import java.awt.event.*; import javax.swing.*; import java.awt.*; import java.net.*; import java.io.*; public class showname {//implements ActionListener{ JFrame f = new JFrame(); Container c = f.getContentPane(); JLabel L1 = new JLabel("net:"); JTextField T1 = new JTextField(); public static void main (String agr[]) throws Exception{ showname a = new showname(); a.createFrame(); } public void createFrame() throws Exception{ c.setLayout(null); L1.setBounds(20,0,50,20); T1.setBounds(50,0,50,20); c.add(L1); c.add(T1); f.setUndecorated(true); f.setSize(100,20); f.setVisible(true); //T1.setText(Conn.detect()); start(); } public void start() { String ip = "202.188.0.133"; String pingResult = ""; String pingCmd = "ping " + ip +" -t"; try { Runtime r = Runtime.getRuntime(); Process p = r.exec(pingCmd); BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { if(inputLine.indexOf("Request timed out")!=-1){ T1.setText("down"); } else if(inputLine.indexOf("Reply from")!=-1) T1.setText("up"); } in.close(); }//try catch (IOException e) { System.out.println(e); } /* int a = 0; try{ while(a ==0 ){ ConnectionDetector Conn = new ConnectionDetector(); Conn.detect(); T1.setText(""); T1.setText(Conn.detect()); } }catch(Exception ae){ ae.printStackTrace(); }*/ } }