/* * HelloWorldSwing.java is a 1.4 example that * requires no other files. Modified by Sam Rebelsky * to make it conform more to his coding style */ import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.SwingUtilities; public class HelloWorldSwing { String message; private HelloWorldSwing(String _message) { this.message = _message; } // HelloWorldSwing(String) /** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread. */ private void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window. JFrame frame = new JFrame(message); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Add the ubiquitous "Hello World" label. JLabel label = new JLabel("Hello World"); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(label, BorderLayout.CENTER); //Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { final HelloWorldSwing one = new HelloWorldSwing("Hello"); final HelloWorldSwing two = new HelloWorldSwing("Goodbye"); //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. SwingUtilities.invokeLater(new Runnable() { public void run() { one.createAndShowGUI(); two.createAndShowGUI(); } }); } }