注册 登录
编程论坛 J2EE论坛

为什么程序出现没有初始化小程序??

李贤昌 发布于 2008-02-26 00:13, 868 次点击
代码:
import java.awt.*;
import java.awt.event.*;
public class E20
{
    public static void main(String args[])
    {
        myMenuFrame myMenu=new myMenuFrame();
        myMenu.setVisible(true);
    }
}
class myMenuFrame extends Frame implements ActionListener,ItemListener
{
    TextField text;
    PopupMenu popM;
    Button but;
    public myMenuFrame()
    {
        super("我的菜单窗口");
        setLayout(new BorderLayout());
        setSize(300,200);
        but=new Button("弹出菜单按键");
        add("North",but);
        this.add(but);
        but.addActionListener(this);
        MenuBar myB=new MenuBar();
        setMenuBar(myB);
        Menu m1=new Menu("文件");
        MenuItem m11=new MenuItem("打开");
        MenuItem m12=new MenuItem("保存");
        MenuShortcut sc1=new MenuShortcut(KeyEvent.VK_O);
        MenuShortcut sc2=new MenuShortcut(KeyEvent.VK_E);
        m11.setShortcut(sc1);
        m12.setShortcut(sc2);
        m1.add(m11);  m1.add(m12);
        m1.addSeparator();
        MenuItem m13=new MenuItem("退出",new MenuShortcut(KeyEvent.VK_X));
        m1.add(m13);
        m1.addActionListener(this);
        myB.add(m1);
        popM=new PopupMenu();
        MenuItem p1=new MenuItem("复制");
        p1.addActionListener(this);
        popM.add(p1);
        MenuItem p2=new MenuItem("剪切");
        p2.addActionListener(this);
        popM.add(p2);
        MenuItem p3=new MenuItem("粘贴");
        p3.addActionListener(this);
        popM.add(p3);
        but.add(popM);
        text=new TextField();
        add("South",text);
    }
    
    public void itemStateChanged(ItemEvent e)
    {
        text.setText("状态改变");
    }
    
    public void actionPerformed(ActionEvent e)
    {
        text.setText(e.getActionCommand());
        if(e.getActionCommand()=="弹出菜单按键")
           popM.show(but,50,70);
           if(e.getActionCommand()=="退出")
             System.exit(0);
    }
}
可以编绎通过!
HTML文件为:
<html>
<body>
<applet code="E20.class" height="300" width="500"></applet>
</body>
</html>
但运行是出现:没有初始化小程序!
3 回复
#2
xiaozhefei2008-02-26 08:52
你继承的不是applet类把class myMenuFrame extends Frame implements ActionListener,ItemListener 改为class myMenuFrame extends applet implements ActionListener,ItemListener
试下
#3
jgio2008-02-26 09:45
www.  慧都控件网,国内最大的专业控件代理商与技术支持商
tel:023-66090381   QQ:903506412
#4
论坛元老2008-04-02 18:41
你继承的不是applet类把class myMenuFrame extends Frame implements ActionListener,ItemListener 改为class myMenuFrame extends applet implements ActionLis ...
1