• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple Question  RSS feed

 
Angelo Watson
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two User Interface classes - Class A and Class B
I have Class A calling Class B by a button. When I close Class B it closes Class A, what I wanted is to go back to Class A and not close it.
Please Help, Thank You
 
Andrea Gazzarini
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you write your code? I don't undestand what you mean...
 
Angelo Watson
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.awt.event.*;
import javax.swing.*;
public class ClassA extends JFrame {
public ClassA() {

super("Hello World");
Container container = getContentPane();
JButton button1 = new JButton("Button 1");
button1.addActionListener(
new ActionListener() {
pubic void actionPerformed(ActionEvent e) {

ClassB app = new ClassB();
app.setVisible(true);
}
}
);
container.add(button1);
setSize(400,400);
setVisible(true);
}
}
Another Class:
import java.awt.event.*;
import javax.swing.*;
public class ClassB extends JFrame {
public ClassB() {

super("Hello World");
Container container = getContentPane();
JButton button2 = new JButton("Button 2");
container.add(button1);
setSize(400,400);
setVisible(true);
}
}
When I hit "Button 1" in Class A it will show ClassB, but when I close ClassB it closes Class A also.
My question is is there a way I can ONLY close ClassB.
Hopefully this helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!