package datos;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.net.ssl.HttpsURLConnection;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.URL;
import java.net.UnknownHostException;
import java.awt.event.ActionEvent;
import java.awt.Color;
import javax.swing.ImageIcon;
public class Ping {
private JFrame frame;
private JTextField txt_url;
private JLabel lblNewLabel;
private JLabel lb1;
private JLabel lb2;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Ping window = new Ping();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Ping() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.getContentPane().setBackground(Color.BLACK);
frame.setBounds(100, 100, 456, 282);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setLocationRelativeTo(null);
JLabel blping = new JLabel("");
blping.setForeground(Color.GRAY);
blping.setHorizontalAlignment(SwingConstants.CENTER);
JButton bt_ping = new JButton("---PING---");
bt_ping.setIcon(new ImageIcon("C:\\Users\\ACER\\Pictures\\click32.png"));
bt_ping.setSelectedIcon(null);
bt_ping.setBackground(Color.BLACK);
bt_ping.setForeground(Color.BLUE);
bt_ping.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String url=null;
try {
url=txt_url.getText();
URL host=new URL("http://"+url);
HttpURLConnection http=(HttpURLConnection) host.openConnection();
http.connect();
blping.setForeground(Color.green);
blping.setText("Tienes conexión exitosa");
lb1.setVisible(true);
lb2.setVisible(false);
} catch (IOException e) {
blping.setForeground(Color.red);
blping.setText("Verifica tu configuración y vuelve a intentar");
lb1.setVisible(false);
lb2.setVisible(true);
}
}
});
bt_ping.setFont(new Font("Tahoma", Font.BOLD, 18));
bt_ping.setBounds(10, 142, 82, 91);
frame.getContentPane().add(bt_ping);
txt_url = new JTextField();
txt_url.setHorizontalAlignment(SwingConstants.CENTER);
txt_url.setFont(new Font("Tahoma", Font.BOLD, 25));
txt_url.setText("www.google.com");
txt_url.setBounds(10, 43, 420, 44);
frame.getContentPane().add(txt_url);
txt_url.setColumns(10);
blping.setFont(new Font("Tahoma", Font.BOLD, 18));
blping.setBounds(10, 98, 420, 31);
frame.getContentPane().add(blping);
lblNewLabel = new JLabel("By Andrax1990 ");
lblNewLabel.setFont(new Font("Agency FB", Font.BOLD, 26));
lblNewLabel.setForeground(Color.WHITE);
lblNewLabel.setBounds(10, 0, 220, 38);
frame.getContentPane().add(lblNewLabel);
lb1 = new JLabel("");
lb1.setIcon(new ImageIcon("C:\\Users\\ACER\\Pictures\\cloud306.png"));
lb1.setForeground(Color.WHITE);
lb1.setBounds(355, 174, 75, 59);
frame.getContentPane().add(lb1);
lb2 = new JLabel("");
lb2.setIcon(new ImageIcon("C:\\Users\\ACER\\Pictures\\cloud307.png"));
lb2.setForeground(Color.WHITE);
lb2.setBounds(355, 155, 75, 78);
frame.getContentPane().add(lb2);
lb1.setVisible(false);
lb2.setVisible(false);
}
}