Hi! I am developing a pos for a store. I have created a settings window. On this window there is a button which is used to set a name for store. When user press this button a message dialog appears with a text field and a OK button so that user enter text for his store name. I made this message dialog by using a jpanel. Below I am giving the code. for this message dialog.
JTextField field = new JTextField(20);
JLabel label = new JLabel("Enter name for your store");
JPanel p = new JPanel(new BorderLayout(5,2));
p.add(label,BorderLayout.WEST);
p.add(field); JOptionPane.showMessageDialog(null,p,"Store Name required",JOptionPane.PLAIN_MESSAGE,null);
String storeName = field.getText();
try {
obj.setStoreName(storeName);
} catch (SQLException ex) {
Logger.getLogger(Settings.class.getName()).log(Level.SEVERE, null, ex);
}
My code is running perfectly. When user enters a name for his store and presses Ok button,the store name is saved in database perfectly.
But the problem is that when user want to close this message dialog and click on the 'X' button at top right corner of this message dialog, the dialog closes and it again save the store name in database i-e it again executes the code which runs for OK button.
I want that on closing the message dialog , the dialog should only close