Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- public class HelloWorldSwing {
- private static void createAndShowGUI() {
- //Create and set up the window.
- JFrame frame = new JFrame("HelloWorldSwing");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //Add the ubiquitous "Hello World" label.
- JLabel label = new JLabel("Hello World");
- frame.getContentPane().add(label);
- //Display the window.
- frame.pack();
- frame.setVisible(true);
- }
- public static void main(String[] args) {
- //Schedule a job for the event-dispatching thread:
- //creating and showing this application's GUI.
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- createAndShowGUI();
- }
- });
- }
- }
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- public class HelloWorldFrame extends JFrame {
- //Programs entry point
- public static void main(String args[]) {
- new HelloWorldFrame();
- }
- //Class Constructor to create components
- HelloWorldFrame() {
- JLabel jlbHelloWorld = new JLabel("Hello World");
- add(jlbHelloWorld); //Add the label to the frame
- this.setSize(100, 100); //set the frame size
- setVisible(true); //Show the frame
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement