Java Swing: multiple windows [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this questionI'm new to GUI programming, but need to create a multiple wi开发者_开发知识库ndow GUI. Does anyone know of any good tutorial online or could you please show a simple code that will launch 2 windows?
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);
}
});
}
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.
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.
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.
Java has a class called Window. This may not be what you want. The normal toplevel object in Swing is a JFrame which is a subclass of Window.
精彩评论