> I am creating a program where I have differnt JInternalFrame classes
> and I would only like 1 frame per class to be displayed at a time.
Use a Singleton pattern.

Signature
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Not Affiliated With Futurama Brass Knuckle Co.
Vova Reznik - 18 Jul 2005 19:58 GMT
>> I am creating a program where I have differnt JInternalFrame classes
>>and I would only like 1 frame per class to be displayed at a time.
>
> Use a Singleton pattern.
He wants to have one frame to be displayed, not created.
> Hello,
> I am creating a program where I have differnt JInternalFrame classes
[quoted text clipped - 3 lines]
> opened. Below is the code to set up a generic JDesktop and one JInternal
> frame. If someone knows how to do this thanks in advance.
Don't think of them as classes. Think of them as objects. When creating
them keep a reference to the new frame. If it already exists just show
it instead of creating a new one.
> public class InternalFrameDemo extends JFrame {
Avoid inheritance if you don't need it. It makes the code far too
specific. You may also override methods by accident.
> JDesktopPane desktop;
I'd suggest (almost) always using private for fields.
> Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
To be very picky you should pick the toolkit off the frame, not get the
default one. In fact the frame may, in general, not be on the default
screen so you should check the frame's graphic enivronment.
> //Quit this app when the big window closes.
> addWindowListener(new WindowAdapter() {
> public void windowClosing(WindowEvent e) {
> System.exit(0);
> }
> });
You can just set the default close operation.
> } catch (java.beans.PropertyVetoException e) {}
Always explain why you are discarding an exception. The explanation
might take the form of a comment sent to a logger.
> public static void main(String[] args) {
> InternalFrameDemo frame = new InternalFrameDemo();
> frame.setVisible(true);
> }
This nees to become:
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() { public void run() {
InternalFrameDemo frame = new InternalFrameDemo();
frame.setVisible(true);
}});
}
Tom Hawtin

Signature
Unemployed English Java programmer