當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。