aspose file tools
The moose likes Swing / AWT / SWT and the fly likes GUI'S Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "GUI Watch "GUI New topic
Author

GUI'S

Douglas McAuley
Greenhorn

Joined: Jul 21, 2003
Posts: 14
I have attached some source code with two GUI'S in it, one of them has a button which when clicked I would like it to go to the other GUI, but unfortunately I can' t seem to find a way to achieve this, basically I am looking for a way to go from one page to the next.

Any ideas would be most welcome.

Regards Douglas
import java.awt.*;
import java.awt.event.*;
public class Test1 extends Frame implements ActionListener {
Button b = new Button("Click me");
public void ShowGui() {
this.setLayout(new FlowLayout());
b.addActionListener(this);
this.add(b);
setSize (300,300);
setVisible (true);
}
public void ShowGui2() {
setBackground(Color.red);
setSize (300,300);
setVisible (true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == b)
System.out.println("Hello");
}
public static void main(String args[]) {
Test1 t = new Test1();
t.ShowGui();
}
}
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
I don't claim that it's pretty, but it works. The "SillyPanel1" will show up initially. When you push "Next" it will show "SillyPanel2". Pushing "Next" again will close the application.

Of course the FlowLayout is an ugly layout manager in this case, but you can get the idea of what's happening. When the "Next" button is pressed, the first panel is removed and the next panel is added to the UI.
In a *real* application you might not want to create a panel until it's needed. And you'd need something other than a boolean to keep track of current state since you'd likely need more than two panels. Also, I'd put each class into a separate file for ease of maintenance.
Douglas McAuley
Greenhorn

Joined: Jul 21, 2003
Posts: 14
Thank you, thats an interesting way to go about it, I shall check it out.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: GUI'S
 
Similar Threads
mulitple jframes
windowlistener
JQ+:Question ID :954959231549
layout
applets