• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Simple Question

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic