Hai all,
I am developing an applet which performs the Pinging operation using command prompt.
Here I am giving the Code of my applet.
import java.awt.*;
import javax.swing.*;
import java.applet.*;
import java.io.*;
import java.awt.event.*;
public class applet1 extends Applet implements ActionListener{
String str;
public static TextArea area;
public static TextField ipaddress;
public void init(){
str = "this is my first Applet";
Label label = new Label("Enter IP Address");
add(label);
ipaddress = new TextField(20);
add(ipaddress);
Button submit = new Button("Ping");
add(submit);
area = new TextArea(20,40);
add(area);
submit.addActionListener(this);
setBackground(Color.gray);
}
public void paint(Graphics g){
showStatus("pinging.....");
}
public void actionPerformed(ActionEvent ae){
String ip = ipaddress.getText();
String pingResult = "";
String pingCmd = "ping " + ip;
try {
Runtime r = Runtime.getRuntime();
Process p = r.exec(pingCmd);
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String inputLine = null;
while ((inputLine = in.readLine()) != null) {
area.append(inputLine+"\n");
pingResult += inputLine;
}
in.close();
}
catch (IOException e) {
System.out.println(e);
}
}
}
This code is generating an exception as shown in the image.
Java.security.AccessControlException-exception.png
Can anybody fix this for me?step3b_fail.jpg
Thanks in advance.