我是 Java 新手,在过去 48 小时内一直试图让它工作,但我即将放弃。
我想将 java applet 放在网站上。仅在 eclipse 中工作正常。我尝试了该网站上已经建议的许多解决方案,但没有一个对我有用,只是搞乱了代码,所以我将其恢复到原始状态。有人能指出问题所在吗?谢谢!
(编辑代码以反射(reflect)建议的答案)
package nameapp;
import java.util.*;
import java.io.*;
import java.applet.Applet
public class NameApp extends Applet{
public static void main(String[] args) throws IOException {
String name;
BufferedReader reader;
reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("What is your name? ");
name = reader.readLine();
if (name.equals("Mike")) {
System.out.print("Hello it's ");
System.out.println(new Date());
System.out.print("My name is ");
System.out.print(name);
System.out.println(" and I am totally awesome!!!");
}
else if (name.equals("Lisa")) {
System.out.print("Hello it's ");
System.out.println(new Date());
System.out.print("My name is ");
System.out.print(name);
System.out.println(" and I'm the prettiest gal in the world!");
}
else {
System.out.print("Hello it's ");
System.out.println(new Date());
System.out.print("My name is ");
System.out.print(name);
System.out.println(" and I'm just ok i guess...");
}
}
}
html 是...
<applet code=nameapp/NameApp.class width=300 height=300>
<param name="bgcolor" value="ffffff">
<param name="fontcolor" value="000000">
Your browser is not Java enabled.
最佳答案
请阅读本教程,其中包含有关 JApplet 的基本内容,
请使用JApplet而不是Applet
仔细阅读signed java applet restrictions
What Applets Can and Cannot Do
https://stackoverflow.com/tags/java-web-start/info
注意 Java 1.6.025 对 JApplet 的另一个限制,Andrew Thompson 在这个论坛上详细描述了这些问题和可能的解决方法,但我丢失了链接...
关于Java小程序在eclipse中工作,而不是在其他地方工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6047919/