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


Java Canvas.requestFocus方法代码示例

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


在下文中一共展示了Canvas.requestFocus方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import java.awt.Canvas; //导入方法依赖的package包/类
/**
 * initialise applet by adding a canvas to it, this canvas will start the LWJGL Display and game loop
 * in another thread. It will also stop the game loop and destroy the display on canvas removal when
 * applet is destroyed.
 */
public void init() {
	setLayout(new BorderLayout());
	try {
		display_parent = new Canvas() {
			public void addNotify() {
				super.addNotify();
				startLWJGL();
			}
			public void removeNotify() {
				stopLWJGL();
				super.removeNotify();
			}
		};
		display_parent.setSize(getWidth(),getHeight());
		add(display_parent);
		display_parent.setFocusable(true);
		display_parent.requestFocus();
		display_parent.setIgnoreRepaint(true);
		setVisible(true);
	} catch (Exception e) {
		System.err.println(e);
		throw new RuntimeException("Unable to create display");
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:30,代码来源:GameApplet.java

示例2: init

import java.awt.Canvas; //导入方法依赖的package包/类
/**
 * initialise applet by adding a canvas to it, this canvas will start the LWJGL Display and game loop
 * in another thread. It will also stop the game loop and destroy the display on canvas removal when
 * applet is destroyed.
 */
public void init() {
	setLayout(new BorderLayout());
	try {
		display_parent = new Canvas() {
			public void addNotify() {
				super.addNotify();
				startLWJGL();
			}
			public void removeNotify() {
				stopLWJGL();
				super.removeNotify();
			}
		};
		display_parent.setSize(getWidth(),getHeight());
		add(display_parent);
		display_parent.setFocusable(true);
		display_parent.requestFocus();
		display_parent.setIgnoreRepaint(true);
		//setResizable(true);
		setVisible(true);
	} catch (Exception e) {
		System.err.println(e);
		throw new RuntimeException("Unable to create display");
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:31,代码来源:GearsApplet.java

示例3: init

import java.awt.Canvas; //导入方法依赖的package包/类
/**
 * @see java.applet.Applet#init()
 */
public void init() {
   removeAll();
   setLayout(new BorderLayout());
   setIgnoreRepaint(true);

   try {
      Game game = (Game) Class.forName(getParameter("game")).newInstance();
      
      container = new Container(game);
      canvas = new ContainerPanel(container);
      displayParent = new Canvas() {
         public final void addNotify() {
            super.addNotify();
            startLWJGL();
         }
         public final void removeNotify() {
            destroyLWJGL();
            super.removeNotify();
         }

      };

      displayParent.setSize(getWidth(), getHeight());
      add(displayParent);
      displayParent.setFocusable(true);
      displayParent.requestFocus();
      displayParent.setIgnoreRepaint(true);
      setVisible(true);
   } catch (Exception e) {
      Log.error(e);
      throw new RuntimeException("Unable to create game container");
   }
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:37,代码来源:AppletGameContainer.java

示例4: mousePressed

import java.awt.Canvas; //导入方法依赖的package包/类
public void mousePressed(MouseEvent e) {
	if (inputEnabled && client != null) {
		e.setSource(client);
		Canvas canvas = (Canvas) client.getComponent(0);
		if (canvas != null) {
			if (!hasFocus)
				canvas.requestFocus();

			canvas.dispatchEvent(e);
		}
	}
}
 
开发者ID:LoveLeAnon,项目名称:OSLoader,代码行数:13,代码来源:InputListeners.java

示例5: createUI

import java.awt.Canvas; //导入方法依赖的package包/类
private void createUI(final Composite parent) {

		_swtContainer = new Composite(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
		final Frame awtContainer = SWT_AWT.new_Frame(_swtContainer);

		final Canvas awtCanvas = new Canvas();
		awtContainer.setLayout(new BorderLayout());
		awtCanvas.setIgnoreRepaint(true);

		awtContainer.add(awtCanvas);
		awtCanvas.setFocusable(true);
		awtCanvas.requestFocus();

		awtContainer.addComponentListener(new ComponentAdapter() {

			@Override
			public void componentResized(final ComponentEvent e) {

				/*
				 * Render map otherwise a black screen is displayed until the map is moved
				 */
				final Map map = _mapApp.getMap();

				// check if initialized
				if (map == null) {
					return;
				}

				map.render();
			}
		});

		_mapApp = Map25App.createMap(this, _state, awtCanvas);
	}
 
开发者ID:wolfgang-ch,项目名称:mytourbook,代码行数:35,代码来源:Map25View.java

示例6: 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


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