Hi guys!

I'm working on this project that will be a Java Applet, using Swing, but I guess you can awnser me in the normal windows way of doing this :)

The idea is basically to have a single 'frame' (window..), but the entire content would change upon some action - exactly like the next dialogs! It would start off as two labels and textboxes asking for username and password + login button... Then depending on correctness of login, the contents would change to be, eg the main menu... Upon choosing some option, the contents would change to be blah... But I really have no idea how to create such a thing! I can easily acomplish it in multiple windows, but I want to keep the seamless transition going, like the installation dialogs with the next, next, next... Any help?
Posted on 2004-02-12 03:00:39 by FearHQ
You will have to use different layout managers.

But your frame will probably need to use the CardLayout Manager. I did something similar to this about a year ago.
Posted on 2004-02-12 07:57:32 by gorshing
I was thinking of a borderLayout for the main frame... Also, how do I add blank spaces in a BorderLayout? As in I want a blank on all borders and content only in the center? The basic template for all "pages" is



_______________________________
| |
| _______________________ |
| | | |
| | Content | |
| | | |
| |[ buttons ] [ buttons] | |
| |_______________________| |
|_______________________________|



The applet will be alot larger in size though...

One thing is, I would like some of the frames destroyed when the page changes... or it's contents diminished, as the project will incorporate a miniature message board and polls... So it's not wise to keep the polls always loaded as well as the messages...
Posted on 2004-02-12 12:28:02 by FearHQ
sample only... pic at the bottom
[size=9]import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

public class SwingApplication extends JApplet
{
JTextArea info;
JButton cancel, next, back;
int state;

public void initGlobalVar()
{
state = 0;
}

public Component createComponents()
{
info = new JTextArea();
info.setEnabled(false);
info.setBackground(Color.BLACK);
info.setBounds(5, 5, 385, 180);

cancel = new JButton("Cancel");
cancel.setBounds(310, 190, 80, 30);

next = new JButton("next");
next.setBounds(225, 190, 80, 30);

back = new JButton("back");
back.setBounds(140, 190, 80, 30);

NavHandler nh = new NavHandler();
cancel.addActionListener(nh);
next.addActionListener(nh);
back.addActionListener(nh);

initGlobalVar();
infoTextState(0);

JPanel pane = new JPanel();
pane.setLayout(null);
pane.setPreferredSize(new Dimension(395, 225));
pane.add(info);
pane.add(cancel);
pane.add(next);
pane.add(back);

return pane;
}

public void infoTextState(int st)
{
switch(st)
{
case 0:
back.setVisible(false);
info.setText("step 0");
break;
case 1:
back.setVisible(true);
info.setText("step 1");
break;
case 2:
info.setText("step 2");
break;
case 3:
info.setText("step 3");
break;
case 4:
info.setText("step 4");
next.setText("Next");
break;
default:
info.setText("step 5");
next.setText("Finish");
}
}

class NavHandler implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
Object vo = ae.getSource();
if(vo == cancel)
{
System.exit(0);
}
else if(vo == next)
{
state++;
if(state == 6)
{
info.setText("Finished Installing");
back.setEnabled(false);
cancel.setEnabled(false);
next.setEnabled(false);
}
else infoTextState(state);
}
else if(vo == back)
{
state--;
infoTextState(state);
}
}
}

public static void main(String[] args)
{
JFrame frame = new JFrame("??? Install");
SwingApplication app = new SwingApplication();
Component contents = app.createComponents();
frame.getContentPane().add(contents, BorderLayout.CENTER);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}[/size]
in short, you can achieve your goal by hiding Buttons... based on different "states".

you can also try multiple panels/frames/windows whatever... hiding... showing... resizing... relocating... adding pictures...

a similar idea would be like property pages(frames/panels/??) in win32.

my java is kinda rusty so the code above may not be the best solution. And I may be talking rubbish to you. :grin:

tested on j2sdk1.4.2_03

:wave:
Posted on 2004-02-13 03:39:40 by arkane
That's pretty close to what I originally thought... But I had envisioned that I switch the middle pane to the apropriate one, depending on the one the user should see at that moment. The content can dramatically change from a set of buttons to option boxes to text areas... I'll read up on the card layout :)
Posted on 2004-02-15 15:56:24 by FearHQ