本文整理汇总了Java中java.awt.im.InputContext.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java InputContext.getInstance方法的具体用法?Java InputContext.getInstance怎么用?Java InputContext.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.im.InputContext
的用法示例。
在下文中一共展示了InputContext.getInstance方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCurrentKeyboardLayout
import java.awt.im.InputContext; //导入方法依赖的package包/类
@Nullable
public static String getCurrentKeyboardLayout() {
InputContext instance = InputContext.getInstance();
Class<? extends InputContext> instanceClass = instance.getClass();
Class<?> superclass = instanceClass.getSuperclass();
if (superclass.getName().equals("sun.awt.im.InputContext")) {
try {
Object inputMethodLocator = ReflectionUtil.getField(superclass, instance, null, "inputMethodLocator");
Locale locale = ReflectionUtil.getField(inputMethodLocator.getClass(), inputMethodLocator, Locale.class, "locale");
return locale.getLanguage().toUpperCase(Locale.getDefault());
}
catch (Exception ignored) {
}
}
return null;
}
示例2: Game
import java.awt.im.InputContext; //导入方法依赖的package包/类
/**
* @author Redomar
* @version Alpha 1.8.4
*/
public Game() {
context = InputContext.getInstance();
// The game can only be played in one distinct window size
setMinimumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
setMaximumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
setPreferredSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
setFrame(new JFrame(NAME)); // Creates the frame with a defined name
getFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Exits the program when user closes the frame
getFrame().setLayout(new BorderLayout());
getFrame().add(this, BorderLayout.CENTER); // Centers the canvas inside the JFrame
getFrame().pack(); // Sizes the frame so that all its contents are at or above their preferred sizes
getFrame().setResizable(false);
getFrame().setLocationRelativeTo(null); // Centres the window on the screen
getFrame().setVisible(true);
requestFocus();
setDevMode(false);
setClosing(false);
}
示例3: getInputContext
import java.awt.im.InputContext; //导入方法依赖的package包/类
/**
* Gets the input context for this window. A window always has an input context,
* which is shared by subcomponents unless they create and set their own.
* @see Component#getInputContext
* @since 1.2
*/
public InputContext getInputContext() {
synchronized (inputContextLock) {
if (inputContext == null) {
inputContext = InputContext.getInstance();
}
}
return inputContext;
}
示例4: main
import java.awt.im.InputContext; //导入方法依赖的package包/类
public static void main(String args[]) {
InputContext ic = InputContext.getInstance();
for (Locale locale : Locale.getAvailableLocales())
ic.selectInputMethod(locale);
ic.getLocale();
}
示例5: getInputContext
import java.awt.im.InputContext; //导入方法依赖的package包/类
/**
* Gets the input context for this window. A window always has an input context,
* which is shared by subcomponents unless they create and set their own.
* @see Component#getInputContext
* @since 1.2
*/
public InputContext getInputContext() {
if (inputContext == null) {
synchronized (inputContextLock) {
if (inputContext == null) {
inputContext = InputContext.getInstance();
}
}
}
return inputContext;
}
示例6: getInputContext
import java.awt.im.InputContext; //导入方法依赖的package包/类
@Override
public InputContext getInputContext() {
toolkit.lockAWT();
try {
if (inputContext == null) {
inputContext = InputContext.getInstance();
}
return inputContext;
} finally {
toolkit.unlockAWT();
}
}
示例7: InputHandler
import java.awt.im.InputContext; //导入方法依赖的package包/类
public InputHandler(Game game) {
InputContext context = InputContext.getInstance();
// Important to know whether the keyboard is in Azerty or Qwerty.
// Azerty countries used QZSD instead of WASD keys.
isAzertyCountry = context.getLocale().getCountry().equals("BE")
|| context.getLocale().getCountry().equals("FR");
game.addKeyListener(this);
}
示例8: getInputLocale
import java.awt.im.InputContext; //导入方法依赖的package包/类
/**
* Returns the input locale for the keyboard.
*
* @return the input locale for the keyboard.
*/
public Locale getInputLocale() {
InputContext ic = InputContext.getInstance();
Locale l = ic.getLocale();
return l;
}