tags:

views:

228

answers:

5

I'm new to GUI programming, but need to create a multiple window GUI. Does anyone know of any good tutorial online or could you please show a simple code that will launch 2 windows?

+1  A: 

http://java.sun.com/docs/books/tutorial/uiswing/components/internalframe.html

the JDesktopPane is cool if you really want an integrated desktop.. it handles objects very similar to JFrames (they are indeed called JInternalFrame) and it automatically handles minimizing, maximing, top menu bar like a normal document based application.

Jack
+2  A: 

Just create two JFrame objects like this:

    public static void main(String[] args)  throws Exception {
        SwingUtilities.invokeLater(new Runnable() {
  public void run() {
   new JFrame("frame1").setVisible(true);
   new JFrame("frame2").setVisible(true);
  }
 });
}
Ramon
thank you. this answered what i was looking for.
ShaChris23
A: 

Java has a class called "Window" http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Window.html. This may not be what you want. The normal toplevel object in Swing is a JFrame (http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JFrame.html) which is a subclass of Window.

peter.murray.rust
+1  A: 

I suggest you use NetBeans and create a project using the "Swing Desktop Application" pre-existing template.

It will create the basic infrastructure for your app including a main window with a menu and status bar with a progress bar, about box, event handlers, etc, all pre-wired.

What's nice about it for example is that the progress bar is already configured to listen to any action task that you create, so by simply creating a new action task, you get a working progress bar that will run when the task executes, without having to code it.

Furthermore, you get a visual drag-and drop Editor that certainly sometimes can be frustrating when it comes to resizing and layouts, but for simple layouts is very good and easy to use. You'll be able to create an interface in no time.

For more info see here.

JRL
+1  A: 

this website is the best IMO, gives you direct How-to-do-it codes, with super brief descriptions

for GUI tutorials, look for "Swing" lessons.

evilReiko
thanks for the useful link!
ShaChris23