Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mouamle.ping.ui;
- import java.awt.EventQueue;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JScrollPane;
- import javax.swing.JTextArea;
- import javax.swing.JTextField;
- import javax.swing.ScrollPaneConstants;
- public class MainUI implements Runnable{
- private JFrame frame;
- private JTextField IP;
- private JTextArea Res;
- private String commnandx = "";
- Thread t = new Thread(this);
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- MainUI window = new MainUI();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- public MainUI() {
- initialize();
- }
- public void runSystemCommand(String command) {
- try {
- Process p = Runtime.getRuntime().exec(command);
- BufferedReader inputStream = new BufferedReader(
- new InputStreamReader(p.getInputStream()));
- String s = "";
- // reading output stream of the command
- while ((s = inputStream.readLine()) != null) {
- Res.append(s + "\n");
- }
- } catch (Exception e) {
- }
- }
- private void initialize() {
- frame = new JFrame();
- frame.setBounds(100, 100, 450, 300);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(null);
- JButton Ping = new JButton("ping");
- Ping.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- commnandx = "ping " + IP.getText() + " -t";
- t.start();
- }
- });
- Ping.setBounds(335, 11, 89, 23);
- frame.getContentPane().add(Ping);
- IP = new JTextField();
- IP.setBounds(10, 12, 315, 22);
- frame.getContentPane().add(IP);
- IP.setColumns(10);
- JScrollPane scrollPane = new JScrollPane();
- scrollPane
- .setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
- scrollPane.setBounds(10, 45, 414, 205);
- frame.getContentPane().add(scrollPane);
- Res = new JTextArea();
- scrollPane.setViewportView(Res);
- }
- @Override
- public void run() {
- runSystemCommand(commnandx);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement