Tuesday, October 9, 2012

First Java Swing GUI

This post is to create a Java Swing GUI. Here, I will create a typical window having title of “First Swing GUI” and size of 300 by 200. The window can be resized into larger or smaller one. It also allows dragging anywhere in your desktop window.  The close operation is EXIT_ON_CLOSE which includes ‘minimize’, ‘maximize’ and ‘close’ buttons.import  


java.awt.EventQueue;
import javax.swing.JFrame;
public class FirstSwingGUI extends JFrame{
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    FirstSwingGUI gui = new FirstSwingGUI();
                   gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    gui.setSize(300, 200);
                    gui.setVisible(true);
                    gui.setTitle("First Swing GUI");
                } catch(Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}

That’s it!
Any comments and/or suggestions are encouraged. Thank you.

1 comment:

  1. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training Core Java 8 Training in Chennai Core java 8 online training JavaEE Training in Chennai Java EE Training in Chennai

    ReplyDelete