Advertisement
Guest User

Untitled

a guest
Feb 21st, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement