-2

I am creating a GUI for my project. I am completely stuck at one point. I was able to create a GUI which will make some simple queries like the release number, command name, and few other boolean questions.

Now I want the user to press CONTINUE button to move to the next page of the GUI form. I have created the continue button, but now I need to register an event to it. This is where I am stuck. I have no idea what event can I register to it which will move the GUI to next page. (By moving to the next page I mean, the different GUI pages we see when we are installing a software for our computer.)

For instance, if I am installing iTunes, I'd first select the radio button for "I accept the terms and conditions" and then I'd press the CONTINUE or the NEXT button to move ahead. If I need to come back, I'd press the BACK button.

One logical answer would be to create another GUI form and then link it to the one I created first.

EDIT:: this is the first time I am working in Java, so I might have ignored some obvious facts.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user4252523
  • 69
  • 2
  • 8
  • *"One logical answer would be to create another GUI form and then link it to the one I created first."* See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) This GUI needs a `CardLayout` – Andrew Thompson Apr 18 '12 at 15:41

4 Answers4

1

Look into using a CardLayout, adding several JPanels to the CardLayout-using container, and then to swap to the next view (the next JPanel), call the layout's next(...) method in the JButton's ActionListener. You could also randomly access components held by the CardLayout using its show(...) method.

To learn more about this including sample code, please have a look at the CardLayout Tutorial, and the API.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
1

Well, register an ActionListener or an Action with the button. To do that wizard style, have a look at the CardLayout layout manager to switch cards or use a tabbed pane, hide the tabs and switch them inside the action or action listener.

Thomas
  • 87,414
  • 12
  • 119
  • 157
1

if i understood, i think you should use the CardLayout

Ahmed Laatabi
  • 907
  • 1
  • 8
  • 21
1

If you are using Swing, you can using several instances of JPanel over a one instance of JFrame.

You can have something like that structure:

JFrame
  +------JPanel:root
           |
           +---JPanel:current // This panel change by other instance
           |
           +---JPanel:controlPanel // This panel contains you button

In you button need add a ActionListener with the method addActionListener

The panel control may need changes your elements, may the text of button or remove the listener and change by other.

I hope that can help

Paul Vargas
  • 41,222
  • 15
  • 102
  • 148