Results 1 to 3 of 3

Thread: Duplicate Window

  1. #1
    Join Date
    Oct 2004

    Duplicate Window

    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();

    L1=new JLabel("Red"); p.add(L1);
    n1=new JTextField(10); p.add(n1);
    L2=new JLabel("Green"); p.add(L2);
    n2=new JTextField(10); p.add(n2);
    L3=new JLabel("Blue"); p.add(L3);
    n3=new JTextField(10); p.add(n3);
    b1=new JButton("colorMe"); p.add(b1);
    b2=new JButton("reSize"); p.add(b2);
    b3=new JButton("spawn"); p.add(b3);


    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);

    if (bert.getSource()==b2)
    num1 = Integer.parseInt(n1.getText());
    num2 = Integer.parseInt(n2.getText());

    //p.setSize(100, 200);
    if (bert.getSource()==b3)

    Y m = new Y();



  2. #2
    Join Date
    Dec 2004
    I don't see anywhere in your code that is doing a show() method call. I am assuming you perform that somewhere in the main.

    I would recommend placing a this.show() at the end of your constructor. That way every instance of the JFrame will show itself on the screen.

    Hope this helps.

  3. #3
    Join Date
    Dec 2004
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center