• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Please Help

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No not really. I got the part extending JComponent on both of the classes.
 
Destiny's powerful hand has made the bed of my future. And this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic