Forums Register Login

Simple Question

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Why don't you write your code? I don't undestand what you mean...
+Pie Number of slices to send: Send
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.
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 670 times.
Similar Threads
Final method
Launch Main from current class scope.
Interface instance
Implementing Lock/Unlock using Event delegator
Doubts regarding Method Local Inner Class
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:38:06.