applet & ping

hello,

I have application which check up ping with me to other ping, but i must write apllet which check ping with ip to server but i think when i open applet ain browser and click "ping". ping go to ip server to ip server? or Client ip to server ip?

import java.io.*;

import java.net.*;

import javax.swing.*;

import java.util.*;

import java.io.FileWriter;

publicclass ping{

publicstaticvoid main ( String[] args ){

Runtime rt = Runtime.getRuntime();

String s="google.pl";

String ilosc_s;

String rozmiar_s;

String x;

//System.out.println("rozmiar:" +z+ "/n");

ilosc_s=JOptionPane.showInputDialog(null,"Podaj ilosc");

int ilosc_i;

int rozmiar_i;

rozmiar_s=JOptionPane.showInputDialog(null,"Podaj rozmiar");

ilosc_i=Integer.parseInt(ilosc_s);

rozmiar_i=Integer.parseInt(rozmiar_s);

System.out.println ("pingdas : " );

System.out.println ("pingsa : " );

System.out.println ("ping -n "+ilosc_i+" -l " +rozmiar_i+" "+s);

String d="";

try{

Process p = rt.exec ("ping -n "+ilosc_i+" -l " +rozmiar_i+" "+s);

System.out.println("Process done");

InputStream is = p.getInputStream();

BufferedReader rd =new BufferedReader(new InputStreamReader(is));

String str;

while((str = rd.readLine())!=null){

System.out.println ("ping:" + str);

d+=str;

}

System.out.println(d);

try{

BufferedWriter zapis=new BufferedWriter(FileWriter("plik.txt",true));

zapis.append("Jakis string");

}catch(IOException ex){

System.out.println("Błąd operacji na pliku: "+ex);

}

rd.close();

p.destroy();

System.out.println("done");

}catch ( Exception e ){

System.out.println ( e );

}

}

}

[3447 byte] By [sun66@o2.pla] at [2007-10-3 4:02:05]
# 1

> hello,

> I have application which check up ping with me to

> other ping, but i must write apllet which check ping

> with ip to server but i think when i open applet ain

> browser and click "ping". ping go to ip server to ip

> server? or Client ip to server ip?

Applets always execute on the client.

CeciNEstPasUnProgrammeura at 2007-7-14 22:01:26 > top of Java-index,Java Essentials,New To Java...
# 2

:) my mistakes It my first applet:

I have code but i have problems:" java.security.AccessControlException: access denied <java.io.filePermision ><< ALL FILES>> execute>" what is wrong?

import java.awt.*;

import java.applet.*;

import javax.swing.*;

import java.awt.event.*;

import java.util.*;

import java.io.*;

import java.net.*;

public class Aplet extends JApplet {

Runtime rt = Runtime.getRuntime();

String s;

JTextField rozmiar=new JTextField(2);

JTextField ilosc=new JTextField(4);

JTextField ip=new JTextField(9);

JTextArea wyswietlanie=new JTextArea(8,10);

JLabel rozmiar_l=new JLabel("Rozmiar: ");

JLabel ilosc_l=new JLabel("Ilosc: ");

JLabel ip_l=new JLabel("Adres ip: ");

JButton ping_b=new JButton("ping");

int f=100;

String pob_r;

String pob_i;

String d;

String pob_ip;

public void init()

{

//Container panel=getContentPane();

//JLabel ety=new JLabel("sasA");

//panel.add(ety);

///////////////

//setTitle("Sprawdzanie pingu");

JPanel panel=new JPanel();

panel.setLayout(null);

panel.add(rozmiar_l);

rozmiar_l.setBounds(10,10, 80,20);

panel.add(rozmiar);

rozmiar.setBounds(65,10,40,20);

panel.add(ilosc_l);

ilosc_l.setBounds(120,10, 60,20);

panel.add(ilosc);

ilosc.setBounds(155,10,40,20);

panel.add(ping_b);

ping_b.setBounds(340,10,80,20);

ping_b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent zdarzenie)

{

Object kod=zdarzenie.getSource();

if(kod==ping_b)

{

pob_r=rozmiar.getText();

pob_i=ilosc.getText();

rozmiar.setEditable(false);

ilosc.setEditable(false);

pob_ip=ip.getText();

//wyswietlanie.append("ping -n "+pob_i+ " -l " +pob_r+" "+s+ " \n");

//wyswietlanie.append(pob_i+ " " +pob_r);

try

{

//Process p = rt.exec ("ping -n "+pob_i+ " -l " +pob_r+" "+s);

Process p = rt.exec ("ping -n "+pob_i+ " -l " +pob_r+" "+pob_ip);

wyswietlanie.append("pingujemy \n");

InputStream is = p.getInputStream();

BufferedReader rd = new BufferedReader(new InputStreamReader(is));

String str;

while((str = rd.readLine())!=null)

{

wyswietlanie.append("ping:" + str+ "\n");

d+=str;

}

System.out.println(d);

rd.close();

p.destroy();

wyswietlanie.append("done\n");

}catch ( Exception e )

{

System.out.println ( e );

}

}

//repaint();

}

});

panel.add(ip);

ip.setBounds(230,10,90,20);

wyswietlanie.setLineWrap(true);

JScrollPane przewijanie=new JScrollPane(wyswietlanie);

panel.add(przewijanie);

przewijanie.setBounds(15,40,400,180);

setContentPane(panel);

}

/////////////////////////////

}

sun66@o2.pla at 2007-7-14 22:01:26 > top of Java-index,Java Essentials,New To Java...
# 3
http://java.sun.com/sfaq/
sabre150a at 2007-7-14 22:01:26 > top of Java-index,Java Essentials,New To Java...
# 4
I read this faq but the problem still exist.Can you help me?
sun66@o2.pla at 2007-7-14 22:01:26 > top of Java-index,Java Essentials,New To Java...
# 5

> I read this faq but the problem still exist.

Reading the FAQ will not make the problem go away!

> Can you help me?

Have you undertood that you at least have to sign your applet jar file?

http://java.sun.com/developer/technicalArticles/Security/Signed/

Message was edited by:

sabre150

sabre150a at 2007-7-14 22:01:26 > top of Java-index,Java Essentials,New To Java...
# 6

When I created file jar:

jar cvf aplet.jar aplet.class

and when i open aplet.jar I have message: "Java virtual machine launcher. Invalid or corrupt jarfile C:\sun\appserver\jdk\bin\Aplet.jar

or

"Java virtual machine launcher. Failed to load Main-Class manifest attribute from C:\sun\appserver\jdk\bin\Aplet.jar

What i do wrong?

sun66@o2.pla at 2007-7-14 22:01:26 > top of Java-index,Java Essentials,New To Java...
# 7
You did not provide a Manifest file!
sabre150a at 2007-7-14 22:01:26 > top of Java-index,Java Essentials,New To Java...
# 8
maybe is stupid by I cen't creat this fu**** jar;( What is wrong at the file .mfI test many time forum and article but I do not understand:/My file in Aplet.jar:\META-INF\MANIFEST.MFAplet.classbut i can't exctract Aplet.jar
sun66@o2.pla at 2007-7-14 22:01:26 > top of Java-index,Java Essentials,New To Java...
# 9

> maybe is stupid by I cen't creat this fu**** jar;(

> What is wrong at the file .mf

> I test many time forum and article but I do not

> understand:/

>

> My file in Aplet.jar:

> \META-INF\MANIFEST.MF

> Aplet.class

> but i can't exctract Aplet.jar

Is not your class called 'aplet' not 'Aplet'?

sabre150a at 2007-7-14 22:01:26 > top of Java-index,Java Essentials,New To Java...
# 10
I have the same problem but i write jar cvf Aplet.jar Aplet.class maby I wrong instal jdk? & JCreator?My manifest file looks like this:Manifest-Version: 1.0Created-By: 1.5.0_06 (Sun Microsystems Inc.)Message was edited by: a4a
a4aa at 2007-7-14 22:01:26 > top of Java-index,Java Essentials,New To Java...