• Post Reply Bookmark Topic Watch Topic
  • New Topic

GUI'S  RSS feed

 
Douglas McAuley
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, thats an interesting way to go about it, I shall check it out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!