Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 21st, 2013  |  syntax: None  |  size: 1.30 KB  |  views: 33  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import javax.swing.*;        
  2.  
  3. public class HelloWorldSwing {
  4.  
  5.     private static void createAndShowGUI() {
  6.         //Create and set up the window.
  7.         JFrame frame = new JFrame("HelloWorldSwing");
  8.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  9.  
  10.         //Add the ubiquitous "Hello World" label.
  11.         JLabel label = new JLabel("Hello World");
  12.         frame.getContentPane().add(label);
  13.  
  14.         //Display the window.
  15.         frame.pack();
  16.         frame.setVisible(true);
  17.     }
  18.  
  19.  
  20.     public static void main(String[] args) {
  21.         //Schedule a job for the event-dispatching thread:
  22.         //creating and showing this application's GUI.
  23.         javax.swing.SwingUtilities.invokeLater(new Runnable() {
  24.             public void run() {
  25.                 createAndShowGUI();
  26.             }
  27.         });
  28.     }
  29. }
  30.        
  31. import javax.swing.JFrame;
  32. import javax.swing.JLabel;
  33.  
  34.  
  35. public class HelloWorldFrame extends JFrame {
  36.  
  37.     //Programs entry point
  38.     public static void main(String args[]) {
  39.         new HelloWorldFrame();
  40.     }
  41.  
  42.     //Class Constructor to create components
  43.     HelloWorldFrame() {
  44.         JLabel jlbHelloWorld = new JLabel("Hello World");
  45.         add(jlbHelloWorld); //Add the label to the frame
  46.         this.setSize(100, 100); //set the frame size
  47.         setVisible(true); //Show the frame
  48.     }
  49. }