Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.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
我想在HTML中运行的Java程序_Java_Html_Jar_Applet - Fatal编程技术网

我想在HTML中运行的Java程序

我想在HTML中运行的Java程序,java,html,jar,applet,Java,Html,Jar,Applet,我有一个简单的Hello.java类,我想把它放在一个网站上 public class Hello { public static void main(String[] args) { System.out.println("Hello, World!"); } } 我试着去做 jar cf Hello.jar Hello.java 然后在网站上试着让它运行我把 Hello测试 本例使用Hello.jar小程序。 不用说它不工作。也许你应该从Applet继

我有一个简单的Hello.java类,我想把它放在一个网站上

 public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
我试着去做

jar cf Hello.jar Hello.java
然后在网站上试着让它运行我把

Hello测试
本例使用Hello.jar小程序。

不用说它不工作。

也许你应该从Applet继承

编辑:位于以下行的内容:

public class FirstApplet extends Applet
{
    public FirstApplet ()
    {
        setBackground (Color.BLUE);
    }
}

也许你应该继承Applet

编辑:位于以下行的内容:

public class FirstApplet extends Applet
{
    public FirstApplet ()
    {
        setBackground (Color.BLUE);
    }
}

如果您编写一个小程序,它应该具有独立应用程序以外的另一种结构,这是因为您的浏览器中有独立应用程序以外的其他环境

当你的应用程序作为小程序运行时,你有一个固定的屏幕,你不能向它发送文本,基本上只能使用浏览器提供的屏幕空间

当独立运行时,您基本上拥有更多的功能,可以访问更多的内容,而不会出现安全异常,但最重要的是,您还需要自己完成图形用户界面的工作

示例:

public class HelloWorld extends JApplet {
        //Called when this applet is loaded into the browser.
        public void init() {
            //Execute a job on the event-dispatching thread; creating this applet's GUI.
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        JLabel lbl = new JLabel("Hello World");
                        add(lbl);
                    }
                });
            } catch (Exception e) {
                System.err.println("createGUI didn't complete successfully");
            }
        }
      }
javac HelloWorld.jar
jar cf Hello.jar Hello.class
<h2> Hello Test </h2>
<APPLET 
   CODE="HelloWorld"
   WIDTH="50%" HEIGHT="50"
   ARCHIVE = "Hello.jar"
 > This example uses a Hello.jar applet.</APPLET>
示例来源:(需要java插件才能查看)

使用:

public class HelloWorld extends JApplet {
        //Called when this applet is loaded into the browser.
        public void init() {
            //Execute a job on the event-dispatching thread; creating this applet's GUI.
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        JLabel lbl = new JLabel("Hello World");
                        add(lbl);
                    }
                });
            } catch (Exception e) {
                System.err.println("createGUI didn't complete successfully");
            }
        }
      }
javac HelloWorld.jar
jar cf Hello.jar Hello.class
<h2> Hello Test </h2>
<APPLET 
   CODE="HelloWorld"
   WIDTH="50%" HEIGHT="50"
   ARCHIVE = "Hello.jar"
 > This example uses a Hello.jar applet.</APPLET>
然后使用以下命令在浏览器中运行它:

public class HelloWorld extends JApplet {
        //Called when this applet is loaded into the browser.
        public void init() {
            //Execute a job on the event-dispatching thread; creating this applet's GUI.
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        JLabel lbl = new JLabel("Hello World");
                        add(lbl);
                    }
                });
            } catch (Exception e) {
                System.err.println("createGUI didn't complete successfully");
            }
        }
      }
javac HelloWorld.jar
jar cf Hello.jar Hello.class
<h2> Hello Test </h2>
<APPLET 
   CODE="HelloWorld"
   WIDTH="50%" HEIGHT="50"
   ARCHIVE = "Hello.jar"
 > This example uses a Hello.jar applet.</APPLET>
Hello测试
本例使用Hello.jar小程序。

如果您编写小程序,它应该具有独立应用程序以外的另一种结构,这是因为您的浏览器中有独立应用程序以外的其他环境

当你的应用程序作为小程序运行时,你有一个固定的屏幕,你不能向它发送文本,基本上只能使用浏览器提供的屏幕空间

当独立运行时,您基本上拥有更多的功能,可以访问更多的内容,而不会出现安全异常,但最重要的是,您还需要自己完成图形用户界面的工作

示例:

public class HelloWorld extends JApplet {
        //Called when this applet is loaded into the browser.
        public void init() {
            //Execute a job on the event-dispatching thread; creating this applet's GUI.
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        JLabel lbl = new JLabel("Hello World");
                        add(lbl);
                    }
                });
            } catch (Exception e) {
                System.err.println("createGUI didn't complete successfully");
            }
        }
      }
javac HelloWorld.jar
jar cf Hello.jar Hello.class
<h2> Hello Test </h2>
<APPLET 
   CODE="HelloWorld"
   WIDTH="50%" HEIGHT="50"
   ARCHIVE = "Hello.jar"
 > This example uses a Hello.jar applet.</APPLET>
示例来源:(需要java插件才能查看)

使用:

public class HelloWorld extends JApplet {
        //Called when this applet is loaded into the browser.
        public void init() {
            //Execute a job on the event-dispatching thread; creating this applet's GUI.
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        JLabel lbl = new JLabel("Hello World");
                        add(lbl);
                    }
                });
            } catch (Exception e) {
                System.err.println("createGUI didn't complete successfully");
            }
        }
      }
javac HelloWorld.jar
jar cf Hello.jar Hello.class
<h2> Hello Test </h2>
<APPLET 
   CODE="HelloWorld"
   WIDTH="50%" HEIGHT="50"
   ARCHIVE = "Hello.jar"
 > This example uses a Hello.jar applet.</APPLET>
然后使用以下命令在浏览器中运行它:

public class HelloWorld extends JApplet {
        //Called when this applet is loaded into the browser.
        public void init() {
            //Execute a job on the event-dispatching thread; creating this applet's GUI.
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        JLabel lbl = new JLabel("Hello World");
                        add(lbl);
                    }
                });
            } catch (Exception e) {
                System.err.println("createGUI didn't complete successfully");
            }
        }
      }
javac HelloWorld.jar
jar cf Hello.jar Hello.class
<h2> Hello Test </h2>
<APPLET 
   CODE="HelloWorld"
   WIDTH="50%" HEIGHT="50"
   ARCHIVE = "Hello.jar"
 > This example uses a Hello.jar applet.</APPLET>
Hello测试
本例使用Hello.jar小程序。

您读过小程序教程吗?你需要学习小程序。你读过小程序教程吗?你需要学习applet。从JApplet扩展会更好。从JApplet扩展会更好。