Dificuldade com PING

2 respostas
T

Ola amigos,
Preciso de uma ajuda com este “aplicativo”, preciso que ele execute um PING e de a resposta no textarea, oq estou fazendo de errado

[b]

import java.awt.Component;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import <a href="http://java.io">java.io</a>.*;

import javax.swing.*;

public class Formulario implements ActionListener {

private JLabel label;

private JTextField textField;

private JButton button;

private JPanel panel;

private JFrame frame;

private void montaFormulario() {
label = new JLabel(Digite o endereço:);

textField = new JTextField(20);

button = new JButton(PINGAR);

button.addActionListener(this);

Component textArea = new JTextArea(22,40);

panel = new JPanel();

panel.add(label);

panel.add(textField);

panel.add(button);

panel.add(textArea);

frame = new JFrame(SisPing);

frame.add(panel);

frame.pack();

frame.setSize(488,455);

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

static class Ping {

String host;
  JTextArea exibit;
  Process ping;
  String endereco;

  public Ping(String address){
    host = endereco;
  }

  public void setTextArea(JTextArea x){
    exibit = x;
  }


  public String ping() throws IOException{
    String retorno = new String();
    
    Runtime runtime = Runtime.getRuntime();

    ping = runtime.exec(new String("ping "+host));
    BufferedReader br = new BufferedReader(new 
InputStreamReader(ping.getInputStream()));

    String line;

    while ((line = br.readLine()) != null) {
        retorno+=line;
        
        System.out.println(line);
        
        if(exibit != null)
          exibit.append(line);
    }

    return retorno;
  }


  public void stop(){
    ping.destroy();
  }  


  public static void main(String[] args) throws IOException{
    Ping pinger = new Ping("localhost");
    
    System.out.println(pinger.ping());

  }


}
public static void main(String[] args) {

new Formulario().montaFormulario();

}

public void actionPerformed1(ActionEvent e) {
}

<a class="mention" href="/u/override">@Override</a>

public void actionPerformed(ActionEvent e) {
}

}

[/b]

OBRIGADO!

2 Respostas

edmarr

Ola , Bem vindo ao Fórum , antes de uma olhada neste link

http://www.guj.com.br/posts/list/50115.java

melhora a visualização para todos os usuários .

gomesrod

Você pode começar pelo seguinte:

  1. Existe um erro traiçoeiro neste trecho, tente identifica-lo:

public Ping(String address) { host = endereco; }

  1. Falta implementar a ação do botão (método actionPerformed), está vazio ou seja nada acontece ao clicar.
    A propósito, o método actionPerformed não deve levar a anotação @Override, ela não serve para implementação de métodos da interface.

Boa sorte!
Qualquer coisa posta aí

Criado 22 de setembro de 2009
Ultima resposta 22 de set. de 2009
Respostas 2
Participantes 3