当前位置: 首页>>代码示例>>Java>>正文


Java Canvas.addMouseListener方法代码示例

本文整理汇总了Java中java.awt.Canvas.addMouseListener方法的典型用法代码示例。如果您正苦于以下问题:Java Canvas.addMouseListener方法的具体用法?Java Canvas.addMouseListener怎么用?Java Canvas.addMouseListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Canvas的用法示例。


在下文中一共展示了Canvas.addMouseListener方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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.");
   }
 
开发者ID:josmas,项目名称:openwonderland,代码行数:28,代码来源:InputManager.java

示例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);

}
 
开发者ID:dstallenberg,项目名称:SimpleRecurrentNetwork,代码行数:33,代码来源:Unit.java

示例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());
}
 
开发者ID:ZetzmannM,项目名称:CGL,代码行数:11,代码来源:Listener.java

示例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);

}
 
开发者ID:dstallenberg,项目名称:NormalFeedForwardNeuralNet,代码行数:33,代码来源:Unit.java

示例5: WebcamCanvas

import java.awt.Canvas; //导入方法依赖的package包/类
public WebcamCanvas(Webcam w) {
	super();
	cam = w;
	canvas = new Canvas();
	setSize(w.getViewSize());
	canvas.setSize(w.getViewSize());
	add(canvas);
	initBox();
	canvas.addMouseListener(this);
}
 
开发者ID:ForOhForError,项目名称:MTG-Card-Recognizer,代码行数:11,代码来源:WebcamCanvas.java

示例6: 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
}
 
开发者ID:DreamBlocks,项目名称:DreamBlocks,代码行数:13,代码来源:AwtEventsHandler.java

示例7: InputHandler

import java.awt.Canvas; //导入方法依赖的package包/类
public InputHandler(Canvas canvas)
{
	this.canvas = canvas;
	canvas.addMouseListener(this);
	canvas.addMouseMotionListener(this);
	canvas.addKeyListener(this);
}
 
开发者ID:devMauris,项目名称:UNI_OOP,代码行数:8,代码来源:InputHandler.java

示例8: 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();
}
 
开发者ID:TheRemote,项目名称:Spark,代码行数:60,代码来源:Java2DFrame.java

示例9: main

import java.awt.Canvas; //导入方法依赖的package包/类
public static void main(final String[] args) throws AWTException {
    robot = new Robot();
    Frame bigOne = new Frame();
    bigOne.setSize(200, 200);
    bigOne.setLocationRelativeTo(null);
    bigOne.setVisible(true);
    Frame f = new Frame();
    f.setLayout(new BorderLayout());
    f.setSize(120, 150);
    f.setLocationRelativeTo(null);
    Canvas c = new MyCanvas();
    f.add(c, BorderLayout.CENTER);
    c.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            switch(state) {
                case 0: // the first event should be (0,0)
                    if (e.getX() != 0 || e.getY() != 0) {
                        System.out.println("state 0: wrong location" + e);
                        break;
                    }
                    state++;
                    break;
                case 1: // the second event should be (1,1)
                    if (e.getX() != 1 || e.getY() != 1) {
                        System.out.println("state 1: wrong location " + e);
                        break;
                    }
                    state++;
                    break;
                case 2: // this should never happen
                    System.out.println("state 2: wrong location " + e);
            }
        }
    });
    f.pack();
    f.setVisible(true);
    bigPause();

    Point p = c.getLocationOnScreen();
    doPress(p);
    p.x += 1;
    p.y += 1;
    doPress(p);
    p.x -= 2;
    p.y -= 2;
    doPress(p);
    bigPause();

    f.dispose();
    bigOne.dispose();

    // ...and at the end the state should be 2
    if (state != 2) {
        throw new RuntimeException("wrong state: " + state);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:57,代码来源:GetScreenLocTest.java

示例10: 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);
}
 
开发者ID:Sogomn,项目名称:spjgl,代码行数:59,代码来源:Screen.java


注:本文中的java.awt.Canvas.addMouseListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。