0

I write project in Java in NetBeans. I created a new project and didn't check to create main class, because I create all with drag and drop, make some buttons and events on them. Then, I created two JFrame classes: NewJFrame and NewJFrame1, in NewJFrame I a have a button in both frames.

So, can you tell me how can I make event to open first frame by clicking on button in second frame, and to open second frame by clicking on button in first frame?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Jun 16 '15 at 09:25
  • In NewJFrame.java button event call NewJFrame1 jFrame1 = new NewJFrame1(); and do opposite in NewJFrame1.java button event. – Sai Ye Yan Naing Aye Jun 16 '15 at 09:25
  • *"I created a new project and didn't check to create main class, because I create all with drag and drop"* That makes no sense to me. A D'n'D GUI might have a main method, and it may not. Likewise a 'hand made' GUI might have a main method or may not. – Andrew Thompson Jun 16 '15 at 09:29
  • Thanks to all... This is solution.. NewJFrame1 jFrame1 = new NewJFrame1(); jFrame1.setVisible(true); – silent_rain Jun 16 '15 at 09:34

1 Answers1

0
//Make constructor class for both JFrame then 
//write this code into your JFrame where your button is accesing another JFrame
//Note:- jb=button var name,
//       jf=JFrame vatr name,
//       addnew()=JFrame Class to be open.

 jb.addActionListener(new ActionListener() { 
        @Override
        public void actionPerformed(ActionEvent arg0) {
            // TODO Auto-generated method stub
            new addnew();
            jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        } 
    });
imjhapali
  • 1
  • 2