开发者

Java Frame... not focusing on JTextField

Whenever my Applet starts up.. I start it as Java application and here's what I do:

   public static void main(String[] args)
  {
    JFrame frame=new JFrame("Gam开发者_开发百科e - v2.2");
    applet=new tileOffline();
    frame.setFocusable(true);
    frame.requestFocusInWindow();
    frame.getContentPane().add(applet,BorderLayout.CENTER);
    frame.setSize(646,558);
    frame.addWindowListener(new WindowAdapter()
       {public void windowClosing(WindowEvent evt)
         { applet.stop(); applet.destroy(); System.exit(0); 
       } } );

    applet.init();
    applet.start();    
    frame.setVisible(true);
    say.setFocusable(true);
    say.setText("Test");
  }

So when I start the game... when you first press any key... it should go in the JTextField of say because it's focused on that. But nope. It's not.

In fact, it sees say because it successfully adds Test to say... so... I dunno.


Try calling

say.requestFocusInWindow();


Try this in your WindowAdapter

public void windowOpened(WindowEvent e) {
   say.requestFocus();
}

Cheers,

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜