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


Java Canvas.setFocusable方法代码示例

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


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

示例1: AView

import java.awt.Canvas; //导入方法依赖的package包/类
/**
 * Initiates a new View instance.
 * 
 * @param title
 *            The title displayed on the frame.
 * @param width
 *            The width of the frame.
 * @param height
 *            The height of the frame.
 * @param manager
 *            The RenderManager of this View, managing render layers.
 */
public AView(String mTitle, int mWidth, int mHeight, RenderManager mManager) {
	super(0, 0, mWidth, mHeight);

	manager = mManager;
	title = mTitle;
	height = mHeight;
	width = mWidth;

	frame = new JFrame(title);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setResizable(false);
	frame.setSize(width, height);
	frame.setLocationRelativeTo(null);
	frame.setVisible(false);

	canvas = new Canvas();
	canvas.setPreferredSize(new Dimension(width, height));
	canvas.setMaximumSize(new Dimension(width, height));
	canvas.setMinimumSize(new Dimension(width, height));
	canvas.setFocusable(false);
	canvas.setBounds(0, 0, width, height);

	frame.add(canvas);

}
 
开发者ID:Ativelox,项目名称:Rummy,代码行数:38,代码来源:AView.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);
		setVisible(true);
	} catch (Exception e) {
		System.err.println(e);
		throw new RuntimeException("Unable to create display");
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:30,代码来源:GameApplet.java

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

示例4: createDisplay

import java.awt.Canvas; //导入方法依赖的package包/类
private void createDisplay()
{
	//Creates JFrame with constructor data
	frame = new JFrame(title);
	frame.setSize(width, height);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setResizable(false);
	frame.setLocationRelativeTo(null);
	frame.setVisible(true);
	
	//Creates a Canvas to draw the game on
	canvas = new Canvas();
	canvas.setBackground(Color.BLACK);
	canvas.setPreferredSize(new Dimension(width, height));
	canvas.setMaximumSize(new Dimension(width, height));
	canvas.setMinimumSize(new Dimension(width, height));
	canvas.setFocusable(false);
	
	//Adds canvas to JFram
	frame.add(canvas);
	frame.pack();
}
 
开发者ID:DasAvh,项目名称:APCS_3rd_Hour_2015,代码行数:23,代码来源:Display.java

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

示例6: updateKeyFocus

import java.awt.Canvas; //导入方法依赖的package包/类
/**
 * By default, the control arb makes it so the main canvas is not focusable
 * when an app has control. Subclasses may override this method to change
 * this behavior.
 * @param hasControl true if the app has just gained control, or false if
 * not
 */
protected void updateKeyFocus(boolean hasControl) {
    Canvas canvas = JmeClientMain.getFrame().getCanvas();

    if (!hasControl) {
        // Make sure that the main canvas is focusable
        canvas.setFocusable(true);
    } else {
        // Prevent the main canvas for gaining focus while an app has focus
        canvas.setFocusable(false);
    }
}
 
开发者ID:josmas,项目名称:openwonderland,代码行数:19,代码来源:ControlArbAppFocus.java

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

示例8: DisplayParentTest

import java.awt.Canvas; //导入方法依赖的package包/类
public DisplayParentTest() throws LWJGLException {
    setTitle( "LWJGL Display Parent Test" );
    setSize( 640, 320 );
    setLayout( new GridLayout( 1, 2 ) );
    final Canvas display_parent = new Canvas();
    final Canvas display_parent_2 = new Canvas();
    display_parent.setFocusable( true );
    display_parent.setIgnoreRepaint( true );
    add( display_parent );
    display_parent_2.setFocusable( true );
    display_parent_2.setIgnoreRepaint( true );
    add( display_parent_2 );
    addWindowListener( new WindowAdapter() {
        public void windowClosing( WindowEvent e ) {
            killswitch = true;
        }
    } );
    setResizable( true );
    setVisible( true );
    Display.setParent( display_parent );
    Display.setVSyncEnabled( true );
    Display.create();
    float angle = 0f;
    while ( isVisible() && !killswitch ) {
        angle += 1.0f;
        int width;
        int height;
        if ( !Display.isFullscreen() ) {
            width = display_parent.getWidth();
            height = display_parent.getHeight();
        }
        else {
            width = Display.getDisplayMode().getWidth();
            height = Display.getDisplayMode().getHeight();
        }
        if ( width < 1 || height < 1 ) {
            continue;
        }
        glViewport( 0, 0, width, height );
        glClearColor( 0.0f, 1.0f, 0.0f, 1.0f );
        glClear( GL_COLOR_BUFFER_BIT );
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        gluOrtho2D( 0.0f, (float) width, 0.0f, (float) height );
        glMatrixMode( GL_MODELVIEW );
        glPushMatrix();
        glTranslatef( width / 2.0f, height / 2.0f, 0.0f );
        glRotatef( 2 * angle, 0f, 0f, -1.0f );
        glRectf( -50.0f, -50.0f, 50.0f, 50.0f );
        glPopMatrix();
        Display.update();
        while ( Keyboard.next() ) {
            // closing on ESCAPE
            if ( Keyboard.getEventKey() == Keyboard.KEY_ESCAPE && Keyboard.getEventKeyState() ) {
                Display.destroy();
                dispose();
                break;
            }
            if ( Keyboard.getEventKey() == Keyboard.KEY_SPACE && Keyboard.getEventKeyState() ) {
                Mouse.setGrabbed( !Mouse.isGrabbed() );
            }
            if ( Keyboard.getEventKey() == Keyboard.KEY_F && Keyboard.getEventKeyState() ) {
                Display.setFullscreen( !Display.isFullscreen() );
            }
            if ( Keyboard.getEventKey() == Keyboard.KEY_4 && Keyboard.getEventKeyState() ) {
                if ( Display.getParent() == display_parent ) {
                    Display.setParent( display_parent_2 );
                }
                else {
                    Display.setParent( display_parent );
                }
            }
        }
        while ( Mouse.next() ) {
            System.out.println( "Mouse.getEventX() = " + Mouse.getEventX() + " | Mouse.getEventY() = " + Mouse.getEventY() );
        }
    }
    Display.destroy();
    dispose();
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:81,代码来源:DisplayParentTest.java

示例9: DisplayParentTest

import java.awt.Canvas; //导入方法依赖的package包/类
public DisplayParentTest() throws LWJGLException {
		setTitle("LWJGL Display Parent Test");
		setSize(640, 320);
		setLayout(new GridLayout(1, 2));
		final Canvas display_parent = new Canvas();
		display_parent.setFocusable(true);
		display_parent.setIgnoreRepaint(true);
		add(display_parent);
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				killswitch = true;
			}
		});
		setResizable(true);
		setVisible(true);
		Display.setParent(display_parent);
		Display.setVSyncEnabled(true);
		Display.create();
		float angle = 0f;

		while (isVisible() && !killswitch) {
			angle += 1.0f;
			int width;
			int height;
			if (!Display.isFullscreen()) {
				width = display_parent.getWidth();
				height = display_parent.getHeight();
			} else {
				width = Display.getDisplayMode().getWidth();
				height = Display.getDisplayMode().getHeight();
			}

			if(width < 1 || height < 1) {
				continue;
			}

			glViewport(0, 0, width, height);
			glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
			glClear(GL_COLOR_BUFFER_BIT);
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			gluOrtho2D(0.0f, (float) width, 0.0f, (float) height);
			glMatrixMode(GL_MODELVIEW);
			glPushMatrix();
			glTranslatef(width / 2.0f, height / 2.0f, 0.0f);
			glRotatef(2*angle, 0f, 0f, -1.0f);
			glRectf(-50.0f, -50.0f, 50.0f, 50.0f);
			glPopMatrix();
			Display.update();
			while(Keyboard.next()) {
				// closing on ESCAPE
				if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE && Keyboard.getEventKeyState()) {
					Display.destroy();
					dispose();
					break;
				}

				if(Keyboard.getEventKey() == Keyboard.KEY_SPACE && Keyboard.getEventKeyState()) {
					Mouse.setGrabbed(!Mouse.isGrabbed());
				}
				if(Keyboard.getEventKey() == Keyboard.KEY_F && Keyboard.getEventKeyState()) {
					Display.setFullscreen(!Display.isFullscreen());
				}
			}
/*			while (Mouse.next()) {
System.out.println("				Mouse.getEventX() = " + 				Mouse.getEventX() + " | Mouse.getEventY() = " + Mouse.getEventY());
			}*/
		}
		Display.destroy();
		dispose();
	}
 
开发者ID:mleoking,项目名称:PhET,代码行数:72,代码来源:DisplayParentTest.java

示例10: initialize

import java.awt.Canvas; //导入方法依赖的package包/类
/**
 * Initialize the contents of the frame.
 */	
@SuppressWarnings({ "unchecked", "rawtypes" })
private void initialize() {
	
	frame = new JFrame("Sensor Display");
	
	frame.setBounds(200, 200, 650, 650);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.getContentPane().setLayout(null);
	
	//List Model 
	ListModel model = new DefaultListModel();

	
	//Hashtable in order to store item objects and their name

	//Jlabel to say if an item has been sent

	
	//Selection lister to enable or disable the Jlabel according to the value of item flag
	
	
	JLabel lblNew = new JLabel("Sensors");
	//lblNew.setMaximumSize(new Dimension(10000, 50));
	
	lblNew.setBounds(0, 0, 100, 100);
	frame.getContentPane().add(lblNew);
	
	lblNew.setVisible(true);

		// saving sample_minimal.png
		

	Server serv;
	JLabel lblNew2 = new JLabel("Distribution");
	//lblNew.setMaximumSize(new Dimension(10000, 50));
	
	lblNew2.setBounds(350, 50, 100, 10);
	frame.getContentPane().add(lblNew2);
	
	 canvas = new Canvas();
	  canvas.setBounds(350, 100, 236, 150);

	
	    canvas.setBackground(Color.WHITE);
	    canvas.setVisible(true);
	    canvas.setFocusable(false);

	    frame.getContentPane().add(canvas);
	    
	try {
		
		 serv=new Server(6005,this);
		 new Thread(serv).start();
		 
		 
	} catch (IOException e) {
		e.printStackTrace();
	}
	
	
	//On exit close all connections 


}
 
开发者ID:fmcalcagno,项目名称:Sensors,代码行数:68,代码来源:Interface.java


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