windowlistener

Adding a new WindowListener to a JFrame

为君一笑 提交于 2019-12-05 01:52:16
问题 mainFrame.addWindowListener(new WindowListener() { @Override public void windowClosing(WindowEvent e) { if (JOptionPane.showConfirmDialog(mainFrame, "Are you sure you want to quit?", "Confirm exit.", JOptionPane.OK_OPTION, 0, new ImageIcon("")) != 0) { return; } System.exit(-1); } @Override public void windowOpened(WindowEvent e) {} @Override public void windowClosed(WindowEvent e) {} @Override public void windowIconified(WindowEvent e) {} @Override public void windowDeiconified(WindowEvent e

Popup for JFrame close button

ⅰ亾dé卋堺 提交于 2019-12-04 13:29:58
问题 i am doing some basic Java Swing application (beginner level) . what i have to do is when i press close button on JFrame to colse the window i want a JOptionPane Confirm Dialog instead of straightforward close here is the code JFrame JFrame frame= new JFrame("frame"); frame.setSize(300,300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.pack(); and JOptionPane code goes like this final JOptionPane optionPane = new JOptionPane("Are You sure?",JOptionPane

how to set new text in JTextField after creation?

和自甴很熟 提交于 2019-12-02 09:42:41
问题 I have a jTextField , and I set it's value to a certain sum when I create the frame. Here is the initiation code: totalTextField.setText( itemsPriceTextField.getText() + Float.toString(orderDetails.delivery) ); This textfield should show a sum of items selected by the user. The selection is done on a different frame, and both frames are visible / invisible at a time. The user can go back and forth and add / remove items. Now, every time i set this frame visible again, I need to reload the

Infinite disappear-reappear loop in JFrame java

[亡魂溺海] 提交于 2019-12-02 08:54:24
As a succession to this post I'm running into an infinite loop that causes my computer to crash. Or, well, not quite: it seems to cause the Java window (JFrame) to keep getting focus/getting iconified and normalized infinitely. As such do not try to run the code as is . The program won't allow you to shut it down, nor can you do so via task manager. I have given a complete code example, that you can run - as is often advised. As it's a stripped-down version of an actual program, some code may seem redundant (especially the methods in the middle). The methods that are of importance are: the

WindowListener for closing JFrames and use global variable

我的梦境 提交于 2019-12-02 07:42:26
I'm struggling with using WindowListener for closing JFrames. I have a situation where a client is logged on to a server and when the client closes his application the server needs to be informed. So in order to inform the server, another instance of a class (that handles the rmi implementation) should be addressed. that instance is a global variable in my GUI class. I searched the web a bit but all i can fined to the problem is the following structure addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent e) { System.out.println("jdialog window closed event received"); }

How can save some Objects, directly after the User has closed the Applications JFrame, but before the Program exits?

倾然丶 夕夏残阳落幕 提交于 2019-12-02 03:27:38
问题 Good day! I'm developping a small Java Application with NetBeans IDE that extends JFrame. I implemented several ways to close the App, for example pressing Ctrl-Q and pressing the X of the JFrame. But before the actual closing I'd like the program to execute some additional code for me, to save some objects the application needs to reuse the next time it starts up. What is the best way to change the entire programs closing behavior? I'm thinking about overriding/replacing the

Closing a java program properly when JDialog is the main window

笑着哭i 提交于 2019-12-01 17:39:55
I have a JDialog as the main window in my application (originally it was a JFrame but it showed in the taskbar which I didn't want). Currently I am doing: setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); and when I click an exit button: frame.dispose(); But the process still seems to hang around in the background JFrame had JFrame.EXIT_ON_CLOSE which seemed to do what I wanted. How can I close my application properly? You can add System.exit(0); where you want the program to end, maybe immediately after the dispose() line. You need to add a WindowListener that will do System.exit(0) when

Java: How to cancel application exit

强颜欢笑 提交于 2019-12-01 17:36:59
On one of my programs, I want a Dialog to appear when the user attempts to exit the application. The user must then choose to save some state of the program, not to save or to cancel the exit operation. I wrote this in an attempt to find a solution first and ony then implement it: import javax.swing.*; import java.awt.Dimension; import java.awt.event.*; class WL implements WindowListener { private boolean statussaved; private JFrame tframe; WL (JFrame frame) { statussaved = false; tframe = frame; } @Override public void windowActivated (WindowEvent w) { } @Override public void windowClosed

Closing a java program properly when JDialog is the main window

血红的双手。 提交于 2019-12-01 17:36:56
问题 I have a JDialog as the main window in my application (originally it was a JFrame but it showed in the taskbar which I didn't want). Currently I am doing: setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); and when I click an exit button: frame.dispose(); But the process still seems to hang around in the background JFrame had JFrame.EXIT_ON_CLOSE which seemed to do what I wanted. How can I close my application properly? 回答1: You can add System.exit(0); where you want the program to end,

Java: How to cancel application exit

亡梦爱人 提交于 2019-12-01 16:15:14
问题 On one of my programs, I want a Dialog to appear when the user attempts to exit the application. The user must then choose to save some state of the program, not to save or to cancel the exit operation. I wrote this in an attempt to find a solution first and ony then implement it: import javax.swing.*; import java.awt.Dimension; import java.awt.event.*; class WL implements WindowListener { private boolean statussaved; private JFrame tframe; WL (JFrame frame) { statussaved = false; tframe =