dcsimg
Showing JFrames one at a time
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Alex_Lo
Posted On:   Thursday, July 12, 2001 07:30 AM

I am trying to use Swing (my first time) and i want to have a "wizard" type program that will change from one window to the next everytime the ok button is pressed (not a 2-way wizard, only one way). I already have all my frames built with panels, i just need a way to close or hide the JFrames and open them on a commmand inside a panel in a frame...bit too tricky for me to figure out.
the frames i want to display are slightly more complicated than dialog boxes, is there any way to make a dialog box with a supplied frame? that would make things easier...


Thanks, Alex

Re: Showing JFrames one at a time

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);
About | Sitemap | Contact