Breaking News
Home / Java / Java Snippets / How do you create a simple Swing based Window with Frame?

How do you create a simple Swing based Window with Frame?

  1. import java.awt.EventQueue;
  2.  
  3. import javax.swing.JFrame;
  4.  
  5.  
  6. public class MainWindow {
  7.  
  8.      private JFrame frame;
  9.  
  10.      /**
  11.      * Launch the application.
  12.      */
  13.      public static void main(String[] args) {
  14.           EventQueue.invokeLater(new Runnable() {
  15.                public void run() {
  16.                     try {
  17.                          MainWindow window = new MainWindow();
  18.                          window.frame.setVisible(true);
  19.                     } catch (Exception e) {
  20.                          e.printStackTrace();
  21.                     }
  22.                }
  23.           });
  24.      }
  25.  
  26.      /**
  27.      * Create the application.
  28.      */
  29.      public MainWindow() {
  30.           initialize();
  31.      }
  32.  
  33.      /**
  34.      * Initialize the contents of the frame.
  35.      */
  36.      private void initialize() {
  37.           frame = new JFrame();
  38.           frame.setBounds(100, 100, 511, 402);
  39.           frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  40.      }
  41.  
  42. }
[pb_builder]

Check Also

How to parse ShoutCast/IceCast Stream Metadata in Java?

Snippet StreamScraper is a java library that can be used to harvest streaming metadata (current …

Advertisment ad adsense adlogger