It has been quite some time since I used this :

Dimension SCREEN_SIZE = Toolkit.getDefaultToolkit().getScreenSize();
MainFrame mainFrame = new MainFrame();
int halfWidth = mainFrame.getWidth() / 2;
int halfHeight = mainFrame.getHeight() / 2;
mainFrame.setLocation(SCREEN_SIZE.width / 2 - halfWidth, SCREEN_SIZE.height / 2 - halfHeight);
mainFrame.setVisible(true);

Example for a Frame.

And apparently, you can use this one line instead:

mainFrame.setLocationRelativeTo(null); // or 'this' to parent

damn :D

Thanks Réal Gagnon :)


import java.io.*;

import java.net.*;

 

public class ReachableTest {

 public static void main(String args[]) {

     try {

       InetAddress address = InetAddress.getByName("web.mit.edu");

       System.out.println("Name: " + address.getHostName());

       System.out.println("Addr: " + address.getHostAddress());

       System.out.println("Reach: " + address.isReachable(3000));

     }

     catch (UnknownHostException e) {

       System.err.println("Unable to lookup web.mit.edu");

     }

     catch (IOException e) {

       System.err.println("Unable to reach web.mit.edu");

     }

   }

}