Java Code Examples for javax.swing.JFrame.setFocusable()

The following are Jave code examples for showing how to use setFocusable() of the javax.swing.JFrame class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Lunar   File: Game.java   View Source Code Vote up 6 votes
/**
 * Initialize the project.
 *
 * @param title    The string on the window's title bar.
 * @param width    Width of the window
 * @param height   Height of the window
 * @param tickRate Determines how fast the game loop is.
 */
public Game(String title, int width, int height, int tickRate) {
    this.width = width;
    this.height = height;

    stack = new ArrayList<>();

    this.maxTPS = tickRate;

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

    frame.addKeyListener(new InputListener());
    frame.addMouseListener(new MouseInput());
}
 
Example 2
Project: Lunar   File: Game.java   View Source Code Vote up 6 votes
/**
 * Initialize the game.
 *
 * @param title    The string on the window's title bar.
 * @param width    Width of the window
 * @param height   Height of the window
 * @param pref     The window preferences.
 * @param tickRate Determines how fast the game loop is.
 */
public Game(String title, int width, int height, FramePreferences pref, int tickRate) {
    this.width = width;
    this.height = height;

    stack = new ArrayList<>();

    maxTPS = tickRate;

    frame = new JFrame(title);
    frame.setSize(width, height);
    frame.setDefaultCloseOperation(pref.getCloseOperation());
    frame.setLocationRelativeTo(pref.getRelativeLocation());
    frame.setResizable(pref.isResizable());
    frame.setFocusable(pref.isFocusable());

    frame.addKeyListener(new InputListener());
    frame.addMouseListener(new MouseInput());
}
 
Example 3
Project: cc-unespar   File: Mouse.java   View Source Code Vote up 5 votes
public void telinha() {	
	janela = new JFrame();
	//janela.addMouseListener(this);
	//janela.setSize(img.getWidth(null), img.getHeight(null));
	JLabel background = new JLabel();
	ImageIcon icone = new ImageIcon(img);
	background.addMouseListener(this);
	background.setSize(img.getWidth(null), img.getHeight(null));
	background.setIcon(icone);
	janela.add(background);
	janela.setVisible(true);
	janela.setFocusable(true);
	janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	
}