posted 22 years ago
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