I'm trying to make this window duplicate itself upon clicking the "spawn" button. The window is a simple application that changes it's own bgcolor and size. I tried creating another instance of the class but when I test it out it duplicates the window but it's doesn't have the interface (no buttons, no text fields). It's just basically all gray and it freezes the application. Any ideas?
Here's my code:
public class Y extends JFrame implements ActionListener
{
JPanel p;
JTextField n1, n2, n3;
JButton b1,b2,b3;
JLabel L1,L2,L3;
int num1, num2, num3;
public Y()
{
p = new JPanel();
this.getContentPane().add(p);
public void actionPerformed (ActionEvent bert)
{
if (bert.getSource()==b1)
{
num1 = Integer.parseInt(n1.getText());
num2 = Integer.parseInt(n2.getText());
num3 = Integer.parseInt(n3.getText());
Color c = new Color (num1, num2, num3);
p.setBackground(c);
}
if (bert.getSource()==b2)
{
num1 = Integer.parseInt(n1.getText());
num2 = Integer.parseInt(n2.getText());
this.setSize(num1,num2);
//p.setSize(100, 200);
}
if (bert.getSource()==b3)
{
My apologies. I now see the setVisible call, however I still think a show() call is safer in a JFrame. It is not deprecated in the call to JFrame but is deprecated in the call to parent class Component. The call to show() has duel purposes on a JFrame.
1) Will set visible.
2) Will bring to front if already visible.
I also am not sure how well making a new instance of a class from within an ActionListener event works. If possible I would use the JFrame show() call at the end of the constructor. The constructor seems to be self-contained.
Bookmarks