• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please Help  RSS feed

 
John Penalosa
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I call another application within an application.
For Example I have two classes. A and B
When I open A and press a button that calls B, how can I NOT let it open in a whole new window, I want it to open using ClassA window.
Here is an example:
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);
}
}
I got this code from Angelo Watson.
My question is when ClassA intiates ClassB by pressing a button. How can I NOT let it open in a different window.
I hope this helps
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why you don't make ClassA and ClassB extending from JComponent and you wrap it by one JFrame. Then it is easy to display CalssA in the JFrame and it is also easy to change the contents of the JFrame by destoying it and adding ClassB.
Do you got the idea?
 
John Penalosa
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No not really. I got the part extending JComponent on both of the classes.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!