This is the First of some basic articles about creating a GUI in Java. The following code is the basis of the following series of articles. I am using the Java Swing window toolkit.
import java.awt.*; import java.swing.*; class FirstWindow { public static void main(String[] args) { //Create Window object and set title bar text JFrame frame = new frame("First Window"); // Set the Default operation when you close the window // This exits the program on closing the window // The default behavior is to HIDE_ON_CLOSE frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Now we need to Display the window // The null argument will place the element in the center of the screen. frame.setLocationRelativeTo(null); frame.pack(); frame.setVisible(true); } }
This is enough to display a simple window, but it will probably not have any useful size associated with it and it does not do anything.
The next step will be to add some useful widgets and eventually functionality to make the window useful.
Helpful info:
Java: Great link to Swing Examples