1

I have a game that uses a JFrame that displays the game info. The window updates whenever a player sends a move object to the server. It works perfectly fine for any number of move objects. However once the 3nd turn starts it hits a wall and here is what happens:

  • The Jframe completely stops responding to left and right mouse clicks (it makes a windows ding sound when you try to click)
  • The JFrame still responds to mouse scrolls and keyboard inputs
  • The JFrame vanishes from the alt-tab program list.
  • NO error message or stack trace.
  • Using souts it appears that the code reaches all points of necessary code properly
  • I can't even click the "X" Window button or right-click close on the task bar
  • The 3rd turn object is structurally identical to previous turn objects

what on earth can cause a program to do this??

Robert
  • 97
  • 7
  • 2
    Post an a sscce http://sscce.org – Guillaume Polet Mar 29 '12 at 23:33
  • I don't think I can (I know that's going to make helping me very hard). What I really want to know is if anyone knows HOW something like that can predictably happen without causing a stack trace. Then maybe I can locate the issue. – Robert Mar 29 '12 at 23:42
  • 1
    Some modal dialog that would be in the background and is not owned by your JFrame? Using a debugger might help by pausing the EDT and looking at the stacktrace? You can also do that using JConsole – Guillaume Polet Mar 29 '12 at 23:45
  • I think you might be on to something because occasionally an odd task has been showing on my taskbar yet I can't click it or view it. – Robert Mar 29 '12 at 23:53

2 Answers2

4

The event dispatch thread has thrown an exception. It is automatically restarted, but your program remains in the state you describe. See also How can I catch Event Dispatch Thread (EDT) exceptions and this answer.

Addendum: How uncaught exceptions are handled and Uncaught exceptions in GUI applications may be helpful. Also check for empty exception handlers.

Addendum: Here's an example.

import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;

/** @see https://stackoverflow.com/a/9935287/230513 */
public class Fail extends JPanel {

    private static final JLabel label = new JLabel(
        "12345678901234567890", JLabel.CENTER);

    public Fail() {
        this.setLayout(new GridLayout(0, 1));
        this.add(label);
        this.add(new JButton(new AbstractAction("Kill me, now!") {

            @Override
            public void actionPerformed(ActionEvent e) {
                JButton b = (JButton) e.getSource();
                b.setText(String.valueOf(1 / 0));
            }
        }));
        new Timer(100, new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                label.setText(String.valueOf(System.nanoTime()));
            }
        }).start();
    }

    private void display() {
        JFrame f = new JFrame("Example");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(this);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new Fail().display();
            }
        });
    }
}
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I used the "MyExceptionHandler" example from your link and registered it in main. When the problem happens, nothing shows up. – Robert Mar 30 '12 at 01:03
  • Ouch. I'd look for empty exception handlers, next. – trashgod Mar 30 '12 at 01:06
  • Are you using [`DefaultEditorKit.BeepAction`](http://docs.oracle.com/javase/6/docs/api/javax/swing/text/DefaultEditorKit.html)? – trashgod Mar 30 '12 at 05:39
0

Check if your frame class do not overrides isEnabled() method. I spent couple of hours searching for exception but the responce was pretty trivial: I have implemented interface with such method.

VDanyliuk
  • 1,049
  • 8
  • 23