Java GUI : Java Frame at center of the screen – II

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
class  main2  extends JFrame implements  ActionListener 
{
    JButton btn;
    public main2()
    {
		  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		  setTitle("codeTpoint.com ");
		  setSize(500,400);
		  setLayout(new FlowLayout());
		  btn= new JButton("Know Your Screen Size!");
		  
		  btn.addActionListener(this);
		  add(btn);
		
 	     // Get the size of the screen
           Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

	        // Determine the new location of the window
	        
	        int w = this.getSize().width;
	        int h = this.getSize().height;
	              
	        int x = (dim.width-w)/2;
	        int y = (dim.height-h)/2;
	                
	        // Move the window
	        this.setLocation(x,y);
	        setVisible(true);
		  
	  }
	@Override
	public void actionPerformed(ActionEvent arg) {
	
		if(arg.getSource()==(JButton) btn)
		{
       JOptionPane.showMessageDialog(null,"Screen Size::"+Toolkit.getDefaultToolkit().getScreenSize().width+ 
    		   "|"+ Toolkit.getDefaultToolkit().getScreenSize().height,"Screen Size",JOptionPane.INFORMATION_MESSAGE);
     
		}
	}			 
}
class  win2
{
	  public  static void main(String popat[])
	  {
     new main2();
	  }
}

Output…

frame2