I am trying to Enable my mainJframe after disabling it to use another jFrame. i disable it after : actionPerformed
with : frame.setEnabled(false);
the 2nd jFrame works and closes just fine, but I cant get my mainJframe enabeled again.
public class Main {
JFrame frame;
public static void main(String[] args) {...}
private void initialize() {
frame = new JFrame();
frame.getContentPane().setFont(new Font("Tahoma", Font.PLAIN, 13));
frame.setBounds(50, 10, 1050, 650);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new CardLayout(0, 0));
JMenuBar menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
JMenu menu1 = new JMenu("Something");
menuBar.add(menu1);
JMenuItem menuItem1 = new JMenuItem("go to frame 2");
mntmAddStudent.setFont(new Font("Segoe UI Semilight", Font.PLAIN, 12));
menu1.add(menuItem1);
menuItem1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
frame.setEnabled(false); /* ???diable it here or in OtherClass??? */
OtherClass otherClass = new OtherClass ();
otherClass .setVisible(true);
}
});
}
}
public class OtherClass extends JFrame {
private JFrame otherClass;
public static void main(String[] args) {...}
public OtherClass() {
otherClass = new JFrame();
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.out.println("closing...");
JFrame frame = (JFrame)e.getSource();
int result = JOptionPane.showConfirmDialog(frame,"Are you sure you to close this frame?","Exit Application",JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.YES_OPTION){
***What do I do here to enable main frame again?***
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
});
}
}
I also have multiple layouts in main and too many jFrames to change them to jDialogs now. I am using eclipse Kepler. What is the problem?