1
我有一個示例代碼App.java
:如何在jar文件中創建Frame/Applet應用程序?
import javax.swing.*;
import java.awt.*;
public class App extends JApplet
{
public void init()
{
getContentPane().add(new JLabel("App"));
}
public static void main(String[] args)
{
JApplet aplet = new App();
JFrame frame = new JFrame("App");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(aplet);
frame.setSize(300,300);
aplet.init();
aplet.start();
frame.setResizable(false);
frame.setVisible(true);
}
}
I,通過compile.bat
手段編譯:
@echo off
cls
del *.jar
javac *.java
jar cfe App.jar App *.class
del *.class
當我雙擊App.jar
,我看到文本框。這就是我想要的。
我怎樣才能在html頁面上顯示呢?
我嘗試下面的代碼,它不工作:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>App</title>
</head>
<body>
<center>
<h1>App</h1>
<applet codebase="classes" code="App.class" archive="App.jar
width="300" height="300" " />
</center>
</body>
</html>
頁面顯示Error. Click for details.
當我點擊,我看到:
load: class App.class not found.
java.lang.ClassNotFoundException: App.class
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.ClassNotFoundException: App.class
當我發佈App.class
上的HTML,一切正常。我無法發佈App.jar
。 我該如何做到這一點,因此它可以作爲一個小程序和框架?