Hi
I have been using the code block below as my standard GUI start. However, for some reason after I updated eclipse and JDK to their newest versions, it just doesn't work anymore and I have no idea why.
exit() gets called and frame properly dispersers but it seems there is a daemon thread and a AWT thread active, according to eclipse debug. This should not be happening.
I don't want to use System.exit(0) or EXIT_ON_CLOSE. I'm not looking for another way to solve this, I want to know why this is not working. have covered all my steps, and the program is written properly.
I am running this program as is right now there are no other thread sunning with it.
Any help or advise will be appreciated, thanks.
I have been using the code block below as my standard GUI start. However, for some reason after I updated eclipse and JDK to their newest versions, it just doesn't work anymore and I have no idea why.
exit() gets called and frame properly dispersers but it seems there is a daemon thread and a AWT thread active, according to eclipse debug. This should not be happening.
I don't want to use System.exit(0) or EXIT_ON_CLOSE. I'm not looking for another way to solve this, I want to know why this is not working. have covered all my steps, and the program is written properly.
I am running this program as is right now there are no other thread sunning with it.
Any help or advise will be appreciated, thanks.
import java.awt.Toolkit;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.UIManager;
import javax.swing.SwingUtilities;
@SuppressWarnings("serial")
public class JFrameTest extends JFrame implements Runnable{
private final Listener manager;
private JButton jbExit;
public JFrameTest(){
super("JFrame Test");
try {
UIManager.setLookAndFeel( UIManager. getSystemLookAndFeelClassName());
} catch ( Exception e) {
e.printStackTrace();
}
setResizable(false);
manager = new Listener();
addWindowListener( manager);
setContentPane( createGUI());
setDefaultCloseOperation( DISPOSE_ON_CLOSE);
pack();
setMinimumSize( new Dimension( 250,150));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setLocation( (screenSize.width/2)-(getWidth()), (screenSize.height/2)-(getHeight()));
}
private Container createGUI() {
JPanel jpMain = new JPanel();
jpMain.setLayout( new FlowLayout( FlowLayout.CENTER));
jbExit = new JButton( "Exit");
jbExit.addActionListener( manager);
jpMain.add( jbExit);
return jpMain;
}
@Override
public void run() {
setVisible( true);
}
protected class Listener extends WindowAdapter implements ActionListener{
@Override
public void windowClosing(WindowEvent e) {
exit();
}
@Override
public void actionPerformed(ActionEvent e) {
exit();
}
private boolean exit(){
dispose();
//anyother cleaning
return true;
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater( new JFrameTest());
}
}