Posted By:
Christopher_Brind
Posted On:
Friday, July 13, 2001 01:01 AM
To move from one frame to the next you'll need to have an ActionListener on your "next" button.
When the actionPerformed() method is called you simply hide the current frame and display the next. You could subclass JFrame and add a nextFrame() method to make this easier.
Also your action listener could just be a class of it's own constucted with the first frame in the sequence. You only need to create one instance to add to all your "next" buttons:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class WizardActionListener implements ActionListener {
private JFrame currentFrame;
public WizardActionListener(JFrame currentFrame) {
this.currentFrame = currentFrame;
}
public void actionPerformed(ActionEvent ae) {
currentFrame.setVisible(false);
currentFrame = currentFrame.nextFrame();
currentFrame.setVisible(true);
}
}
To make a dialog with a frame:
JFrame parent = new JFrame("my frame");
JDialog dlg = new JDialog(parent);