javax.swing.JFrame.setFocusable()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(293)

本文整理了Java中javax.swing.JFrame.setFocusable()方法的一些代码示例,展示了JFrame.setFocusable()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JFrame.setFocusable()方法的具体详情如下:
包路径:javax.swing.JFrame
类名称:JFrame
方法名:setFocusable

JFrame.setFocusable介绍

暂无

代码示例

代码示例来源:origin: kevin-wayne/algs4

/**
 * Adds a {@link DrawListener} to listen to keyboard and mouse events.
 *
 * @param listener the {\tt DrawListener} argument
 */
public void addListener(DrawListener listener) {
  // ensure there is a window for listenting to events
  show();
  listeners.add(listener);
  frame.addKeyListener(this);
  frame.addMouseListener(this);
  frame.addMouseMotionListener(this);
  frame.setFocusable(true); 
}

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame("Testing");
frame.setAlwaysOnTop(true);
frame.setUndecorated(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new BackgroundPane());
frame.setLocation(0, 0);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setSize(dim);
// This will stop the background window from become focused,
// potentially hiding the other windows
frame.setFocusableWindowState(false);
frame.setFocusable(false);
frame.setVisible(true);

JFrame dialog = new JFrame();
// Will need to add this to each frame...
dialog.setAlwaysOnTop(true);
dialog.setContentPane(new InstallPane());
dialog.pack();
dialog.setLocationRelativeTo(frame);
dialog.setVisible(true);

代码示例来源:origin: stackoverflow.com

public class ButtonListener implements ActionListener {
  public void actionPerformed(ActionEvent e) {
    JFrame frame = new JFrame();
    FinishButton finish = new FinishButton((ButtonClass) e.getSource());
    panel.add(finish);
    frame.add(panel);
    frame.setFocusable(false);
    frame.setSize(1600,900);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  }
}

代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

d.getRootPane().putClientProperty("Quaqua.RootPane.isPalette", Boolean.TRUE);
d.setFocusable(false);
d.setResizable(false);
d.getContentPane().setLayout(new BorderLayout());

代码示例来源:origin: stackoverflow.com

public static void main (String[] args)
 {
   JFrame frame = new JFrame ("Mainframe");
   JComponent test = new Mainframe();
   frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
   frame.setSize (800, 600);
   frame.setFocusable (true);
   frame.getContentPane().setBackground (Color.WHITE);
   frame.getContentPane().add (test);
   frame.addKeyListener ((KeyListener) test);
   frame.setVisible (true);
 }

代码示例来源:origin: stackoverflow.com

AutoClicker clicker = new AutoClicker();
 JFrame frame = new JFrame();
 frame.addKeyListener(clicker);
 frame.setLocationRelativeTo(null);
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 frame.setSize(new Dimension(200,300));
 frame.setVisible(true);
 frame.setFocusable(true);
 frame.requestFocus();

代码示例来源:origin: stackoverflow.com

JFrame mainWindow = new JFrame;
mainWindow.setVisible(true);
JFrame modalWindow = new JFrame();
// The next two sentences gives modalWindow modal beahaviour
mainWindow.setEnabled(false);
mainWindow.setFocusable(false);
modalWindow.setVisible(true);

代码示例来源:origin: stackoverflow.com

public class WinTest extends Canvas {

private static final long serialVersionUID = -369751247370351003L;

public WinTest(int h, int w, String title, Wincall game, ME me) {

  JFrame f = new JFrame(title);
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  f.setSize(h, w);
  f.add(game);
  f.setVisible(true);
  f.requestFocus();
  f.setResizable(false);
  f.setFocusable(true);
  // f.addMouseMotionListener(me);
  game.addMouseMotionListener(me);
  game.run();
 }
}

代码示例来源:origin: stackoverflow.com

public class Test2 {
  public static void main(String[] args) {
    JFrame ablak = new JFrame("Snake game");
    ablak.setVisible(true);
    ablak.setSize(new Dimension(600,600));
    ablak.setFocusable(true);
    ablak.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ablak.addKeyListener(new KeyListener(){
       @Override
        public void keyPressed(KeyEvent e) {
          if(e.getKeyCode() == KeyEvent.VK_UP){
            System.out.println("Hi");
          }
        }

        @Override
        public void keyTyped(KeyEvent e) {
          throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void keyReleased(KeyEvent e) {
          throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });
    ablak.setVisible(true);
  }
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {
  EventQueue.invokeLater(new Runnable() {
    @Override
    public void run() {
      try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
        ex.printStackTrace();
      }

      JFrame frame = new JFrame("Java Sucks!");
      frame.setResizable(false);
      frame.add(game);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setFocusable(true);
      frame.pack();
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
      frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowOpened(WindowEvent e) {
          game.start();
        }
      });

    }
  });
}

代码示例来源:origin: stackoverflow.com

public void init() {
   addKeyListener(new TAdapter()); // only executed in applet
 }
 public EC() {
   // executed in both applet and application
   thread.start();
   timer.start();
 }
 public static void main(String args[]) {   
   // only executed in application
   EC ec = new EC();
   JFrame window=new JFrame("EC");
   window.setPreferredSize(new Dimension(800,600));
   window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   window.add(ec.test);
   window.addKeyListener(ec.new TAdapter());
   window.setFocusable(true);
   window.pack();
   window.setVisible(true);
 }

代码示例来源:origin: stackoverflow.com

f.setFocusable(true);
f.setSize(300, 300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

代码示例来源:origin: com.googlecode.princeton-java-introduction/stdlib

/*************************************************************************
*  Event-based interactions.
*************************************************************************/
public void addListener(DrawListener listener) {
  // ensure there is a window for listenting to events
  show();
  listeners.add(listener);
  frame.addKeyListener(this);
  frame.addMouseListener(this);
  frame.addMouseMotionListener(this);
  frame.setFocusable(true); 
}

代码示例来源:origin: com.github.fracpete/princeton-java-stdlib

/*************************************************************************
*  Event-based interactions.
*************************************************************************/
public void addListener(DrawListener listener) {
  // ensure there is a window for listenting to events
  show();
  listeners.add(listener);
  frame.addKeyListener(this);
  frame.addMouseListener(this);
  frame.addMouseMotionListener(this);
  frame.setFocusable(true); 
}

代码示例来源:origin: stackoverflow.com

frame.setSize(400, 800);
frame.setVisible(true);
frame.setFocusable(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);

代码示例来源:origin: stackoverflow.com

frame.add(game);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setFocusable(true);
frame.pack();
frame.setLocationRelativeTo(null);

代码示例来源:origin: brianway/algorithms-learning

/**
 * Adds a {@link DrawListener} to listen to keyboard and mouse events.
 *
 * @param listener the {\tt DrawListener} argument
 */
public void addListener(DrawListener listener) {
  // ensure there is a window for listenting to events
  show();
  listeners.add(listener);
  frame.addKeyListener(this);
  frame.addMouseListener(this);
  frame.addMouseMotionListener(this);
  frame.setFocusable(true);
}

代码示例来源:origin: edu.princeton.cs/algs4

/**
 * Adds a {@link DrawListener} to listen to keyboard and mouse events.
 *
 * @param listener the {\tt DrawListener} argument
 */
public void addListener(DrawListener listener) {
  // ensure there is a window for listenting to events
  show();
  listeners.add(listener);
  frame.addKeyListener(this);
  frame.addMouseListener(this);
  frame.addMouseMotionListener(this);
  frame.setFocusable(true); 
}

代码示例来源:origin: Toms42/sweep-ai

frame.getContentPane().setLayout(null);
frame.getContentPane().setBackground(Color.black);
frame.setFocusable(true);

代码示例来源:origin: stackoverflow.com

final JFrame frame = new JFrame("Keyboard input to console using robot");
frame.setAlwaysOnTop(true);
frame.setFocusable(false);
frame.setBounds(100, 100, 800, 200);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

相关文章

JFrame类方法