Source of TryWindow2.java


  1: //TryWindow2.java (From Horton)
  2: //Uses the Toolkit object to get information about the local environment.

  4: import javax.swing.JFrame;
  5: import java.awt.Toolkit;
  6: import java.awt.Dimension;

  8: public class TryWindow2
  9: {
 10:     static JFrame window = new JFrame("This is the Window Title"); 

 12:     public static void main(String[] args)
 13:     {
 14:         window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 16:         //Get the window toolkit and then the screen size
 17:         Toolkit kit = window.getToolkit();
 18:         Dimension windowSize = kit.getScreenSize();

 20:         //Set window position to screen center and size to half screen size
 21:         window.setBounds(windowSize.width/4, windowSize.height/4,
 22:                          windowSize.width/2, windowSize.height/2);
 23:         window.setVisible(true);
 24:   }
 25: }