Applet无法实例化

时间:2014-04-11 02:34:37

标签: java applet

我正在使用applet创建GUI,但每当我运行代码时,它都显示“Applet未初始化”。 错误: load:home_1.class无法实例化。

错误是

 java.lang.InstantiationException
        at sun.reflect.InstantiationExceptionConstructorAccessorImpl.
newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at sun.applet.AppletPanel.createApplet(Unknown Source)
        at sun.applet.AppletPanel.runLoader(Unknown Source)
        at sun.applet.AppletPanel.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)

代码是......

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public abstract class home_1 extends Applet implements ItemListener 
{
    Checkbox EPL,LALIGA,BUNDESH;
    CheckboxGroup menu;
    String msg="";
    public void init()
    {
        menu = new CheckboxGroup();
        EPL = new Checkbox("English Premier League",menu,true);
        LALIGA = new Checkbox("La Liga",menu,false);
        add(EPL);
        add(LALIGA);
        EPL.addItemListener(this);
        LALIGA.addItemListener(this);
    }
    public void itemStateChanged(ItemEvent ie)
    {
        repaint();
    }
    public void paint(Graphics g)
    {
        msg = "Current Selection: ";
        msg+=menu.getSelectedCheckbox().getLabel();
        g.drawString(msg,6,6);
    }

}

1 个答案:

答案 0 :(得分:2)

public abstract class home_1你感到惊讶它不起作用吗?

abstract个课程无法实例化......

此外,您必须将super.paint(g)作为paint方法的第一行。