/** * A Simple stand-alone GUI program based on Swing. * The program just displays a simple message. * * @author Dave Hollinger * @version 1.0 */ import javax.swing.*; class Simple { static private final String label = "Hello World"; static private final String title = "Simple Java GUI"; public static void main(String [] args) { // create a top-level container with a title JFrame frame = new JFrame(title); // set the size frame.setSize(200,200); // establish what happens when the window is closed // (without this the program would keep running!) frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // create a label JLabel lbl = new JLabel(label); // add the label to the frame (to the content pane of the frame) frame.getContentPane().add(lbl); // make the frame visible frame.setVisible(true); } }