6
Starting a Swing program
- import javax.swing.*;
- public class HelloSwing {
- private static void createAndShowGUI() {
- JFrame.setDefaultLookAndFeelDecorated(true);
- JFrame frame = new JFrame("Swing");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JLabel label = new JLabel("Let's swing!");
- frame.getContentPane().add(label);
- frame.pack();
- frame.setVisible(true);
- }
- public static void main(String[] args) {
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- createAndShowGUI();
- }
- });
- }
- }
$ javac HelloSwing.java
$ java HelloSwing
Comments