Java WindowFocusListener

Discussion in 'Mac Programming' started by canada eh, Apr 28, 2011.

  1. macrumors regular

    Hi, I am currently in a introducory programming class in highschool, and we are doing java applets.

    For the assignments we are doing simple arcade games like brick breaker, but when we run them we have to click on the screen to focus the window in order to use the keyboard.

    Is there something I can do to eliminate the need to click. I am not too sure but from googling I think I need to implement a WindowFocusListener but I am not sure how to do it just to focus on the window in these simple applets.

    Thanks in advance :)
  2. macrumors 65816


    You would implement WindowFocusListener if you wanted to know when your window gains and loses focus. But that interface can't be used to control the focus.

    I'm at work and don't have a Java development environment, but does adding this to your applet work?

    public void init()
  3. macrumors regular

    Thanks for the reply

    That line did work, but only when I put it on the timer and not in init.

    public void actionPerformed(ActionEvent e){
    		if(e.getSource() == timer1){

Share This Page