Internal Frames in Java Swing

hi

I was learning Swing and I tried the following example from a book.

// File 1
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Test2 extends Frame implements ActionListener {
   JButton openButton;
   JLayeredPane desktop;
   JInternalFrame internalFrame;
   public Test2() {
      super("Internal Frame Test");
      setSize(500,400);
      openButton = new JButton("Open");
      Panel p = new Panel();
      p.add(openButton);
      add(p, BorderLayout.SOUTH);
      addWindowListener(new BasicWindowMonitor());
      openButton.addActionListener(this);
      desktop = new JDesktopPane();
      desktop.setOpaque(true);
      add(desktop, BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e) {
   System.out.println("TEST1");
   if ((internalFrame == null) || (internalFrame.isClosed())) {
      try {
         internalFrame = new JInternalFrame("Internal Frame",false,false,false, true);
         internalFrame.setBounds(50, 50, 200, 100);
         desktop.add(internalFrame, new Integer(1));
      }
   catch(Exception xxx)
   {
      System.out.println("Exception"+xxx);
   }
   System.out.println("TEST");
   }
}
public static void main(String args[]) {
   Test2 sif = new Test2();
   sif.setVisible(true);
}
}


// File 2
import java.awt.event.*;
import java.awt.Window;

public class BasicWindowMonitor extends WindowAdapter {
     public void windowClosing(WindowEvent e) {
          Window w = e.getWindow();
          w.setVisible(false);
          w.dispose();
          System.exit(0);
     }  
}

The files are compiled and executed successfully.
As written in the program when I clicke the "Open" button it should open an internal frame but it is not opening any internal frames.

I have j2sdk1.4.2 and JRE 1.4.2 installed
Processor AMD Athelon XP
OS Windows XP

Any idea about this??
no1nincompoopAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mayank SAssociate Director - Product EngineeringCommented:
>> desktop.add(internalFrame, new Integer(1));

Try calling desktop.revalidate () after that.
0
no1nincompoopAuthor Commented:
hi mayankeagle,

Thanks atleast I got a comment from you in this big group...
I tried what you said  ? it didn't work :-)

Regards
Muke
0
Mayank SAssociate Director - Product EngineeringCommented:
How about just a call to this.repaint () or this.revalidate () after that?
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

no1nincompoopAuthor Commented:
hi

got the solution.. Please close this question....
Answer is  to add  internalFrame.setVisible(true); in the actionPerformed event after setting the boundary for the internal frame..

This site was a bit useful...
http://java.sun.com/developer/JDCTechTips/2001/tt1220.html

Regards
Muke
0
Mayank SAssociate Director - Product EngineeringCommented:
Oh yes, didn't notice that you weren't calling setVisible () sorry :) it has to be called for every top-level container that you wanna display.
0
no1nincompoopAuthor Commented:
hi cud anyone pls close this question.
0
GranModCommented:
PAQed with points refunded (150)

GranMod
Community Support Moderator
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.