0

I am a new Java Programmer and I am tying to link two JFrames Windows together nut I don't know how , can I get some help please.

What I mean is that I made a button and I need the button to go to the next window,
but I don't know how to do so...

TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130
Favouronu
  • 55
  • 1
  • 12

1 Answers1

4

If you are trying to do a wizard then you may want to take a look to Creating Wizard Dialogs with Java Swing document. You would need only one JFrame (or JDialog) and several JPanel which will pass as you press "Next" button.

If you want open a new window then you can create and show a new JDialog within button action listener implementation. Something like this:

JButton nextButton = new JButton("Next");
nextButton.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        JDialog dialog = new JDialog();
        dialog.setTitle("Title");
        dialog.setModal(true);
        dialog.getContentPane().add(...); // add components here
        dialog.pack();
        dialog.setVisible(true);
}

Suggested readings:

Community
  • 1
  • 1
dic19
  • 17,821
  • 6
  • 40
  • 69