为什么运行不了java的applet小程序

来源:百度知道 编辑:UC知道 时间:2024/05/16 04:43:34
我是用jcreator编译java生成class文件的,而且代码是光盘拷过去的(代码肯定没有错误),可是打开html是浏览器老是提示java载入小应用程序失败。
ps:
这是applet小程序,源文件名:threeButtons.java:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

class threeButtons extends Applet implements ActionListener
{
Button btn1=new Button("隐藏/显示");
Button btn2=new Button("变色");
Button btn3=new Button("变大/变小");
Font fnt=new Font("宋体",Font.BOLD,36);
Color C1=Color.red, C2= Color.blue, C3=Color.green;
int flag=1;
public void init()
{
add(btn1);
add(btn2);
add(btn3);
btn1.setBackground(C1);
btn1.setForeground(C2);
btn1.setFont(fnt);
btn2.setFont(fnt);
btn3.setFont(fnt);
btn1.addActionListener(this);
btn2.addAction

刚才我也和你一样,现在我的解决了;
分析如下:
threeButtons.class 不是 public 对象或没有公共构造函数。
java.lang.IllegalAccessException: Class sun.applet.AppletPanel can not access a member of class threeButtons with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java控制台里的.
一:你把threeButton类改为公共类吧!再加上一个构造函数就行了.

楼上兄弟,楼主都会写程序,难道不知道安装JDK?
在class前加public
我给你试过了,命令下”appletviewer threeButtons.html“能行,用Firefox也能行,IE6、IE7也能行,运行效果是3个按钮,第2个按钮是控可以让第1个按钮变红色或蓝色,第3个按钮是控可以让第1个按钮变大和变小。
我的环境是jdk1.6.5,XP SP2,,安装JDK后默认是启用对IE支持的,应该不会在这儿出问题,不过你检查下,IE设置的高级里看看