[英]How can I make Frame/Applet application in jar file?
I have a sample code App.java
: 我有一个示例代码
App.java
:
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 it by means of compile.bat
: 我通过
compile.bat
:
@echo off
cls
del *.jar
javac *.java
jar cfe App.jar App *.class
del *.class
When I double click on App.jar
, I see a frame with text. 当我双击
App.jar
,我看到一个带有文本的框架。 That is what I wanted. 那就是我想要的。
How can I also display this on a html page? 如何在html页面上显示呢?
I try code below and it doesn't work: 我尝试下面的代码,它不起作用:
<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>
The page shows Error. Click for details.
该页面显示
Error. Click for details.
Error. Click for details.
When I click, I see: 当我单击时,我看到:
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
When I post App.class
on html, everything works. 当我在HTML上发布
App.class
时,一切正常。 I'm unable to post App.jar
. 我无法发布
App.jar
。 How can I do this so it works both as an applet and frame? 我该怎么做,使其既可以作为小程序又可以作为框架?
我刚刚从html删除了codebase="classes"
,一切正常:)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.