How to set bound of frame at the center of screen


 import java.awt.Dimension;  
 import java.awt.Toolkit;  
 import javax.swing.JFrame;  
 public class FrameBound extends JFrame{  
   public FrameBound() {  
     this.setSize(300, 300);  
     int WIDTH = this.getWidth();  
     int HEIGHT = this.getHeight();  
     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();  
     this.setBounds((screenSize.width / 2) - (WIDTH / 2), (screenSize.height / 2) - (HEIGHT / 2), WIDTH, HEIGHT);  
   }  
   public static void main(String[] args){  
     new FrameBound().setVisible(true);  
   }  
 }  

No comments:

Post a Comment