本文整理汇总了Java中java.awt.Canvas.addKeyListener方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.addKeyListener方法的具体用法?Java Canvas.addKeyListener怎么用?Java Canvas.addKeyListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Canvas
的用法示例。
在下文中一共展示了Canvas.addKeyListener方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import java.awt.Canvas; //导入方法依赖的package包/类
/**
* Initialize the input manager to receive input events from the given AWT canvas
* and start the input manager running. The input manager will perform picks with the
* given camera. This routine can only be called once. To subsequently change the
* camera, use <code>setCameraComponent</code>. To subsequently change the focus manager,
* use <code>setFocusManager</code>.
* @param canvas The AWT canvas which generates AWT user events.
* @param cameraComp The mtgame camera component to use for picking operations.
*/
public void initialize (Canvas canvas, CameraComponent cameraComp) {
if (this.canvas != null) {
throw new IllegalStateException("initialize has already been called for this InputManager");
}
this.canvas = canvas;
inputPicker.setCanvas(canvas);
setCameraComponent(cameraComp);
canvas.addKeyListener(this);
canvas.addMouseListener(this);
canvas.addMouseMotionListener(this);
canvas.addMouseWheelListener(this);
canvas.addFocusListener(this);
canvas.setDropTarget(new DropTarget(canvas, this));
logger.fine("Input System initialization complete.");
}
示例2: Unit
import java.awt.Canvas; //导入方法依赖的package包/类
public Unit(){
getBestSize();
net = new Net(new int[]{4,5,4}, true);
graph = new TimeGraph(net,0,GAME_HEIGHT-200,GAME_WIDTH, 200, "errorRate");
frame = new Frame();
canvas = new Canvas();
canvas.setPreferredSize(new Dimension(canvasWidth, canvasHeight));
canvas.addKeyListener(new InputHandler());
canvas.addMouseListener(new InputHandler());
canvas.addMouseMotionListener(new InputHandler());
frame.add(canvas);
frame.pack();
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e){
Test.quit(net);
}
});
frame.setVisible(true);
gc = canvas.getGraphicsConfiguration();
vImage = gc.createCompatibleVolatileImage(GAME_WIDTH, GAME_HEIGHT);
}
示例3: setup
import java.awt.Canvas; //导入方法依赖的package包/类
/**
* Sets up the Listener
* @param cnv Canvas
*/
public static void setup(Canvas cnv){
cnv.addKeyListener(new Listener());
cnv.addMouseListener(new Listener());
cnv.addMouseWheelListener(new Listener());
cnv.addMouseMotionListener(new Listener());
}
示例4: Unit
import java.awt.Canvas; //导入方法依赖的package包/类
public Unit(){
getBestSize();
net = new Net(new int[]{2,5,2});
graph = new TimeGraph(net,0,GAME_HEIGHT-200,GAME_WIDTH, 200, "errorRate");
frame = new Frame();
canvas = new Canvas();
canvas.setPreferredSize(new Dimension(canvasWidth, canvasHeight));
canvas.addKeyListener(new InputHandler());
canvas.addMouseListener(new InputHandler());
canvas.addMouseMotionListener(new InputHandler());
frame.add(canvas);
frame.pack();
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e){
Test.quit(net);
}
});
frame.setVisible(true);
gc = canvas.getGraphicsConfiguration();
vImage = gc.createCompatibleVolatileImage(GAME_WIDTH, GAME_HEIGHT);
}
示例5: AwtEventsHandler
import java.awt.Canvas; //导入方法依赖的package包/类
public AwtEventsHandler(MainGame game, Canvas canvas) {
this.game = game;
// add a key input system (defined below) to our canvas
// so we can respond to key pressed
canvas.addKeyListener(new KeyInputHandler());
canvas.addMouseListener(new MouseInputHander());
canvas.addMouseWheelListener(new MouseWheelInputHander());
canvas.addMouseMotionListener(new MouseMoveInputHander());
// TODO: A lot of this should be calling a nicer function in Game to handle
// mouse+keyboard/touch input
}
示例6: initializeGUI
import java.awt.Canvas; //导入方法依赖的package包/类
private void initializeGUI() {
frame = new Frame("Test frame");
canvas = new Canvas();
canvas.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent event) { focusGained = true; }
});
canvas.addKeyListener(this);
frame.setLayout(new BorderLayout());
frame.add(canvas);
frame.setSize(200, 200);
frame.setVisible(true);
}
示例7: initializeGUI
import java.awt.Canvas; //导入方法依赖的package包/类
private void initializeGUI() {
frame = new Frame("Test frame");
canvas = new Canvas();
canvas.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent event) { focusGained = true; }
});
canvas.addKeyListener(this);
frame.setLayout(new BorderLayout());
frame.add(canvas);
frame.setBounds(200, 200, 200, 200);
frame.setVisible(true);
}
示例8: setUpKeyboard
import java.awt.Canvas; //导入方法依赖的package包/类
@ObfuscatedName("x")
@ObfuscatedSignature(
signature = "(I)V",
garbageValue = "2042047067"
)
@Export("setUpKeyboard")
protected final void setUpKeyboard() {
if(Signlink.javaVendor.toLowerCase().indexOf("microsoft") != -1) {
KeyFocusListener.KeyHandler_keyCodes[186] = 57;
KeyFocusListener.KeyHandler_keyCodes[187] = 27;
KeyFocusListener.KeyHandler_keyCodes[188] = 71;
KeyFocusListener.KeyHandler_keyCodes[189] = 26;
KeyFocusListener.KeyHandler_keyCodes[190] = 72;
KeyFocusListener.KeyHandler_keyCodes[191] = 73;
KeyFocusListener.KeyHandler_keyCodes[192] = 58;
KeyFocusListener.KeyHandler_keyCodes[219] = 42;
KeyFocusListener.KeyHandler_keyCodes[220] = 74;
KeyFocusListener.KeyHandler_keyCodes[221] = 43;
KeyFocusListener.KeyHandler_keyCodes[222] = 59;
KeyFocusListener.KeyHandler_keyCodes[223] = 28;
} else {
KeyFocusListener.KeyHandler_keyCodes[44] = 71;
KeyFocusListener.KeyHandler_keyCodes[45] = 26;
KeyFocusListener.KeyHandler_keyCodes[46] = 72;
KeyFocusListener.KeyHandler_keyCodes[47] = 73;
KeyFocusListener.KeyHandler_keyCodes[59] = 57;
KeyFocusListener.KeyHandler_keyCodes[61] = 27;
KeyFocusListener.KeyHandler_keyCodes[91] = 42;
KeyFocusListener.KeyHandler_keyCodes[92] = 74;
KeyFocusListener.KeyHandler_keyCodes[93] = 43;
KeyFocusListener.KeyHandler_keyCodes[192] = 28;
KeyFocusListener.KeyHandler_keyCodes[222] = 58;
KeyFocusListener.KeyHandler_keyCodes[520] = 59;
}
Canvas var1 = this.canvas;
var1.setFocusTraversalKeysEnabled(false);
var1.addKeyListener(KeyFocusListener.keyboard);
var1.addFocusListener(KeyFocusListener.keyboard);
}
示例9: method806
import java.awt.Canvas; //导入方法依赖的package包/类
@ObfuscatedName("r")
@ObfuscatedSignature(
signature = "(B)V",
garbageValue = "52"
)
final void method806() {
Canvas var1 = this.canvas;
var1.removeKeyListener(KeyFocusListener.keyboard);
var1.removeFocusListener(KeyFocusListener.keyboard);
KeyFocusListener.field597 = -1;
WorldMapType1.method245(this.canvas);
if(this.mouseWheelHandler != null) {
this.mouseWheelHandler.removeFrom(this.canvas);
}
this.replaceCanvas();
Canvas var2 = this.canvas;
var2.setFocusTraversalKeysEnabled(false);
var2.addKeyListener(KeyFocusListener.keyboard);
var2.addFocusListener(KeyFocusListener.keyboard);
class27.method213(this.canvas);
if(this.mouseWheelHandler != null) {
this.mouseWheelHandler.addTo(this.canvas);
}
this.method825();
}
示例10: InputHandler
import java.awt.Canvas; //导入方法依赖的package包/类
public InputHandler(Canvas canvas)
{
this.canvas = canvas;
canvas.addMouseListener(this);
canvas.addMouseMotionListener(this);
canvas.addKeyListener(this);
}
示例11: GreedSnake
import java.awt.Canvas; //导入方法依赖的package包/类
public GreedSnake() {
mainFrame = new JFrame("GreedSnake");
Container cp = mainFrame.getContentPane();
labelScore = new JLabel("Score:");
cp.add(labelScore, BorderLayout.NORTH);
paintCanvas = new Canvas();
paintCanvas.setSize(canvasWidth+1,canvasHeight+1);
paintCanvas.addKeyListener(this);
cp.add(paintCanvas, BorderLayout.CENTER);
JPanel panelButtom = new JPanel();
panelButtom.setLayout(new BorderLayout());
JLabel labelHelp;
labelHelp = new JLabel("PageUp, PageDown for speed;", JLabel.CENTER);
panelButtom.add(labelHelp, BorderLayout.NORTH);
labelHelp = new JLabel("ENTER or R or S for start;", JLabel.CENTER);
panelButtom.add(labelHelp, BorderLayout.CENTER);
labelHelp = new JLabel("SPACE or P for pause",JLabel.CENTER);
panelButtom.add(labelHelp, BorderLayout.SOUTH);
cp.add(panelButtom,BorderLayout.SOUTH);
mainFrame.addKeyListener(this);
mainFrame.pack();
mainFrame.setResizable(false);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.setVisible(true);
begin();
}
示例12: Java2DFrame
import java.awt.Canvas; //导入方法依赖的package包/类
public Java2DFrame(Spark game)
{
super(GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration());
this.game = game;
ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
gd = ge.getDefaultScreenDevice();
gc = gd.getDefaultConfiguration();
setTitle("Spark");
setFocusable(false);
setBackground(Color.black);
setFocusTraversalKeysEnabled(false);
setResizable(false);
setIgnoreRepaint(true);
if (game.gameOptions.displayWindowed == false)
setUndecorated(true);
setIconImage(new ImageIcon("spark/images/imgIcon.gif").getImage());
// Invisible cursor
int[] pixels = new int[16 * 16];
Image image = Toolkit.getDefaultToolkit().createImage(
new MemoryImageSource(16, 16, pixels, 0, 16));
Cursor transparentCursor = Toolkit.getDefaultToolkit()
.createCustomCursor(image, new Point(0, 0), "invisibleCursor");
setCursor(transparentCursor);
drawCanvas = new Canvas(gc);
drawCanvas.setPreferredSize(new Dimension(game.ResolutionX,
game.ResolutionY));
drawCanvas.setBackground(Color.black);
drawCanvas.setIgnoreRepaint(true);
drawCanvas.setFocusTraversalKeysEnabled(false);
drawCanvas.addKeyListener(this);
drawCanvas.addMouseListener(this);
drawCanvas.addMouseWheelListener(this);
drawCanvas.setCursor(transparentCursor);
add(drawCanvas);
addWindowListener(this);
pack();
setLocationRelativeTo(null);
if (game.gameOptions.displayWindowed == false)
{
setFullScreen();
}
setVisible(true);
drawCanvas.requestFocus();
}
示例13: InputManager
import java.awt.Canvas; //导入方法依赖的package包/类
public InputManager(Canvas canvas){
canvas.addKeyListener(this);
}
示例14: Screen
import java.awt.Canvas; //导入方法依赖的package包/类
/**
* Constructs a new Screen object with the given width, height and title.
* The screen can be resized.
* @param width The screen width
* @param height The screen height
* @param title The screen title
*/
public Screen(final int width, final int height, final String title) {
frame = new JFrame(title);
canvas = new Canvas();
mouse = new Mouse();
keyboard = new Keyboard();
final WindowAdapter closingAdapter = new WindowAdapter() {
@Override
public void windowClosing(final WindowEvent w) {
close();
if (closingCallback != null) {
closingCallback.run();
}
}
};
final ComponentAdapter resizeAdapter = new ComponentAdapter() {
@Override
public void componentResized(final ComponentEvent c) {
calculateViewport();
if (redrawOnResize) {
redraw();
}
}
};
open = true;
initialWidth = canvasWidth = renderWidth = width;
initialHeight = canvasHeight = renderHeight = height;
resizeBehavior = ResizeBehavior.STRETCH;
canvas.setPreferredSize(new Dimension(width, height));
canvas.setIgnoreRepaint(true);
canvas.addMouseListener(mouse);
canvas.addMouseMotionListener(mouse);
canvas.addMouseWheelListener(mouse);
canvas.addKeyListener(keyboard);
frame.addMouseListener(mouse);
frame.addMouseMotionListener(mouse);
frame.addMouseWheelListener(mouse);
frame.addKeyListener(keyboard);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.setIgnoreRepaint(true);
frame.addWindowListener(closingAdapter);
frame.addComponentListener(resizeAdapter);
frame.add(canvas);
frame.pack();
frame.setLocationRelativeTo(null);
}