Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
显示Java小程序格式_Java_Networking_Applet - Fatal编程技术网

显示Java小程序格式

显示Java小程序格式,java,networking,applet,Java,Networking,Applet,我通常不在java中使用applet或GUI,我仍在学习基础知识。但我有一个项目要做,它特别使用Applet。它是一个本地主机端口扫描程序 import java.net.Socket; import javax.swing.*; @SuppressWarnings("serial") public class portScan extends JApplet{ String remote = "localhost"; int i = 0; String mess

我通常不在java中使用applet或GUI,我仍在学习基础知识。但我有一个项目要做,它特别使用Applet。它是一个本地主机端口扫描程序

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);
     }

}
然后我将Applets.jar放在Applets/Applets.jar文件夹下,并将html代码更改为:

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


浏览器中仍然没有显示

您是否对java小程序进行了签名???检查上面的编辑不要像现在这样忽略异常,并检查java控制台中打印的堆栈跟踪。
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
<applet id="Applets"
            code = "portScan.class"
            archive="applets/Applets.jar"
            width="80%"
            height="80%">
    </applet>