Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2007

Tip: Looking for answers? Try searching our database.

No Main Window

Thread view: 
Peter Christensen - 13 Feb 2007 17:56 GMT
Should this be a problem:

My program can operate with several windows (maybe up to ten), and they
basically all have the same status and functions. For example, a window can
be closed, and from a window also other windows can be opened or closed.
When the last window is closed, then the program will end. No window will
have a special status, for example the first window, that was opened, can
just be closed again, if just a new window has been opened first.

It's really important for me, that all windows have exactely the same
status, and they will also have basically the same menues in practice. They
will all be objects of the same subclass.

I don't think it will be a problem to implement, even though it might be a
bit unusual. Is this correct?

Pete C

Ps. I will use the Java Swing GUI.
Michael Rauscher - 13 Feb 2007 18:14 GMT
Peter Christensen schrieb:
> It's really important for me, that all windows have exactely the same
> status, and they will also have basically the same menues in practice. They
> will all be objects of the same subclass.

Sure, they're all instances of JFrame.

> I don't think it will be a problem to implement, even though it might be a
> bit unusual. Is this correct?

It's not unusual. Firefox, Open-Office and AFAIK MS-Word are examples of
applications that exit when you close the last open window.

And yes, it shouldn't be a big problem to implement this.

import java.awt.event.*;
import javax.swing.*;

public class Test {
    private ActionListener listener = new ActionListener() {
        public void actionPerformed( ActionEvent e ) {
            createAndShowGUI();
        }
    };

    private JMenuBar createMenuBar() {
        JMenuBar menuBar = new JMenuBar();
        JMenu menu = new JMenu("File");
        JMenu newMenu = new JMenu("New");

        JMenuItem item = new JMenuItem("Window");
        item.addActionListener(listener);
        newMenu.add(item);

        menu.add(newMenu);
        menuBar.add(menu);

        return menuBar;
    }

    public void createAndShowGUI() {
        JFrame frame = new JFrame("Test");
        frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
        frame.setJMenuBar( createMenuBar() );
        frame.setSize(400,400);
        frame.setVisible(true);
    }

    public static final void main( String args[] ) {
        SwingUtilities.invokeLater( new Runnable() {
            public void run() {
                new Test().createAndShowGUI();
            }
        });
    }
}

Bye
Michael
Peter Christensen - 13 Feb 2007 22:58 GMT
Thanks for the reply.

Rgds,
Pete C

> Peter Christensen schrieb:
>> It's really important for me, that all windows have exactely the same
[quoted text clipped - 55 lines]
> Bye
> Michael
Thomas A. Russ - 14 Feb 2007 01:45 GMT
> > I don't think it will be a problem to implement, even though it might
> > be a bit unusual. Is this correct?
>
> It's not unusual. Firefox, Open-Office and AFAIK MS-Word are examples of
> applications that exit when you close the last open window.

This is actually platform-dependent.
On the Mac, applications don't generally exit when the last window is
closed.  Certainly MS-Word doesn't do that.  Safari doesn't, and neither
does Firefox.  I don't have Open-Office handy, so I can't test that.

Signature

Thomas A. Russ,  USC/Information Sciences Institute

Michael Rauscher - 14 Feb 2007 08:53 GMT
Thomas A. Russ schrieb:
>>> I don't think it will be a problem to implement, even though it might
>>> be a bit unusual. Is this correct?
[quoted text clipped - 6 lines]
> closed.  Certainly MS-Word doesn't do that.  Safari doesn't, and neither
> does Firefox.  I don't have Open-Office handy, so I can't test that.

Thanks for clarifying.

Bye
Michael


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.