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.
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.
I am so proud of you and your efforts and work make me realize that anything can be done with patience and sincerity. Well I am here to say that your work has inspired me without a doubt.
ReplyDeleteJava training in Chennai
Java training in Bangalore
Superb Post. Thanks for posting.
ReplyDeletealso, check Java training in Pune