java AppletViewer - “小程序未初始化”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17140990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AppletViewer - "applet not initialized"
提问by Rick_Sch
My code compiles and works just fine in both my browser and Eclipse, but for some reason the AppletViewer just won't work with my VERY simple code. When I try to run it with appletviewer FirstApplet.html
, the AppletViewer window appears as expected, but the upper-left part of the window just says "Applet" and the bottom-left part of the window says "Start: applet not initialized"
我的代码在我的浏览器和 Eclipse 中都可以编译并正常工作,但是由于某种原因,AppletViewer 无法与我的非常简单的代码一起使用。当我尝试使用 运行它时appletviewer FirstApplet.html
,AppletViewer 窗口按预期显示,但窗口左上角只显示“Applet”,窗口左下角显示“开始:小程序未初始化”
What could be the problem here? (Again, it works in my browser and Eclipse)
这里可能有什么问题?(同样,它适用于我的浏览器和 Eclipse)
Thank you for any help! :)
感谢您的任何帮助!:)
FirstApplet.java
第一个Applet.java
import java.awt.*;
import java.applet.*;
public class FirstApplet extends Applet {
public void paint(Graphics g){
g.drawString("This is my first Java Applet!", 20, 30);
}
}
FirstApplet.html
第一个Applet.html
<html>
<head>
<title>FirstApplet</title>
</head>
<body>
<applet
codebase = "."
code = "FirstApplet.class"
name = "FirstApplet"
width = "640"
height = "480"
hspace = "0"
vspace = "0"
align = "middle"
>
</applet>
</body>
</html>
回答by Rick_Sch
I figured it out! It was an Eclipse problem after all!
我想到了!毕竟这是一个 Eclipse 问题!
I wrote and compiled the code in Eclipse. Eclipse's internal version of the AppletViewer worked just fine, and it worked just fine to open the HTML file that I made in my browsers.
我在 Eclipse 中编写并编译了代码。Eclipse 的内部版本的 AppletViewer 工作得很好,而且在打开我在浏览器中创建的 HTML 文件时也工作得很好。
The applet didn't work in the actual AppletViewer, however, until I compiled the code using something other than Eclipse. It appears that for some reason AppletViewer didn't like the .class
file that Eclipse generated.
然而,小程序在实际的 AppletViewer 中不起作用,直到我使用 Eclipse 以外的东西编译代码。似乎出于某种原因 AppletViewer 不喜欢.class
Eclipse 生成的文件。
Mystery solved!
谜团已揭开!
回答by Reitsu Y
I was experiencing the same problem.
我遇到了同样的问题。
First of all I had removed public from my class.That lead fine compilation but no initialization in applet:(.
首先,我从我的班级中删除了 public。这导致了很好的编译,但在小程序中没有初始化:(。
Next I changed it public and the code threw an error to me.
接下来,我将其更改为 public,代码向我抛出了一个错误。
To solve error I renamed my source code as per my public class name then I simply ran the code through appletviewer which executed all fine.
为了解决错误,我根据我的公共类名重命名了我的源代码,然后我只是通过 appletviewer 运行代码,它执行得很好。
I apologize for Inconvenient explanation though. Here are the Snippets of three Stage of my problem Solving
我为不便的解释道歉。这是我解决问题的三个阶段的片段
I have tried to demonstrate the aspect of code changes as well :) and the RHS pane is the code webpage.
我也试图演示代码更改的方面 :) 并且 RHS 窗格是代码网页。
Simply keep the name of class and main class containing Source same.
只需保持包含 Source 的类和主类的名称相同。