Quantcast
Channel: Developer Feed - Snippet
Viewing all articles
Browse latest Browse all 178

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

$
0
0

  1. importjava.awt.EventQueue;
  2.  
  3. importjavax.swing.JFrame;
  4.  
  5.  
  6. publicclass MainWindow {
  7.  
  8.      privateJFrame frame;
  9.  
  10.      /**
  11.      * Launch the application.
  12.      */
  13.      publicstaticvoid main(String[] args){
  14.           EventQueue.invokeLater(newRunnable(){
  15.                publicvoid 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.      privatevoid initialize(){
  37.           frame =newJFrame();
  38.           frame.setBounds(100, 100, 511, 402);
  39.           frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  40.      }
  41.  
  42. }

Viewing all articles
Browse latest Browse all 178

Trending Articles