Results 1 to 3 of 3
  1. #1
    Cokeman5 is offline Member
    Join Date
    Apr 2014
    Posts
    3
    Rep Power
    0

    Default JFrame listener issues

    Hello, and thank you for looking into my problem. I've been having an odd issue where all listeners in my JFrame(which uses its own thread) will stop working, including the "x" button, meaning I can't even close the program without task manager. Here is basically what I got going on:

    I create my JFrame and add a mouselistener
    Java Code:
    screen = new Painter(fps);
    screen.addMouseListener(this);
    Once something is clicked the mouseListener is removed and loadGame() is called
    Java Code:
    public void mousePressed(MouseEvent e) {
            if (!Game.loaded && e.getX() > 200 && e.getX() < 400 && e.getY() > 237 && e.getY() < 312) {
                    screen.removeMouseListener(this);
                    loadGame();
                }
        }
    loadGame then adds some key and mouse listeners
    Java Code:
    private void loadGame() {
            ...
            screen.addKeyListener(yourplayer);
            screen.addMouseListener(yourplayer);
            loaded=true;
            ...
        }
    Although, if I forgo the first mouse listener and just call loadGame() immediately, everything works fine:

    Java Code:
    screen = new Painter(fps);
    loadGame();
    Everything else works fine, it's just all listeners stop. So what could be causing this issue? All help would be greatly appreciated.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,343
    Rep Power
    25

    Default Re: JFrame listener issues

    I can't even close the program
    Is the code executing long running tasks on the EDT? That will keep the jvm from responding to user events because the code is using its thread.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Cokeman5 is offline Member
    Join Date
    Apr 2014
    Posts
    3
    Rep Power
    0

    Default Re: JFrame listener issues

    Do you mean infinite loops inside the listener methods? If so, no. Although I do have an infinite render loop inside the JFrame. Also the maximize and minimize buttons still work btw.

    Edit:Hold on, I may have the infinite loop inside a method called from loadGame(), called from the listener, that may be it! I'll look into it.
    Edit2:Fixed, thanks for the help!
    Last edited by Cokeman5; 05-26-2014 at 04:00 PM.

Similar Threads

  1. Replies: 12
    Last Post: 05-04-2011, 09:31 PM
  2. Replies: 2
    Last Post: 04-20-2011, 11:42 PM
  3. JPanel Listener doesn't work in a JFrame...
    By jiapei100 in forum AWT / Swing
    Replies: 2
    Last Post: 11-18-2010, 02:03 PM
  4. JFrame issues
    By ishdevil in forum New To Java
    Replies: 1
    Last Post: 12-17-2009, 08:26 AM
  5. Listener for JFrame size change
    By Thez in forum AWT / Swing
    Replies: 10
    Last Post: 02-14-2008, 03:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •