0

I do not usually use applet or GUI in java, am still learning the basics. But i got a project to do which exceptionally uses Applet. It is a localhost portscanner.

import java.net.Socket;

import javax.swing.*;
@SuppressWarnings("serial")
public class portScan extends JApplet{

    String remote = "localhost";
     int i = 0;
     String message;

     public portScan(){
         do {
           try {
           Socket s = new Socket(remote,i);
           s.close();
           message = "Server is listening on port " + i + " of " + remote;
           JOptionPane.showMessageDialog(rootPane, message);

           } catch (Exception e) {
           //System.out.println("Server is not listening on port " + i+ " of " + remote);
                }
           i++;
          } while(i <= 100);
     }

}

This generates dialog messages for each port and works correctly inside of eclipse!

once i put in inside an html file, it loads, but does not show the dialog output.

I want to know how to better display the result in a list instead of each time a dialog popping up for each port and to work in the browser too (instead of just appearing in the eclipse IDE).

This how i load the class in html

<applet code="applets/portScan.class" width="80%" height="80%> </applet>

UPDATE!!

I just signed it, but still no display. I created a new Java project with only the portscanner applet, i exported it to a file Applets.jar. Then i signed as such :

keytool -genkey -alias myAlias -keystore myCert -keypass myKeyPass -dname "CN=Applets" -storepass myStorePass -validity 1825

jarsigner -keystore myCert -keypass myKeyPass -storepass myStorePass Applets.jar myAlias

Then i place the Applets.jar under folder applets/Applets.jar, and change the html code to :

<applet id="Applets"
            code = "portScan.class"
            archive="applets/Applets.jar"
            width="80%"
            height="80%">
    </applet>

Still i get no display in the browser

4

0 に答える 0