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!