importjava.awt.event.*;importjava.awt.*;publicclassExam5_19extendsFrameimplementsActionListener,ItemListener{TextFieldtext;publicExam5_19(){super("我的菜单窗口");setSize(...
import java.awt.event. *;
import java.awt. *;
public class Exam5_19 extends Frame implements ActionListener,ItemListener
{
TextField text;
public Exam5_19()
{
super("我的菜单窗口");
setSize(300,200);
}
public void init()
{
MenuBar myB=new MenuBar();
setMenuBar(myB);
Menu m1=new Menu("文件");
m1.add(new MenuItem("打开"));
MenuItem m11=new MenuItem("保存");
m11.setEnabled(false);
m1.add(m11);
m1.add("打印");
m1.addSeparator();
m1.add("退出");
m1.addActionListener(this);
myB.add(m1);
Menu m2=new Menu("编辑");
m2.add("复制");
Menu m21=new Menu("颜色");
m21.add("前景色");
m21.add("背景色");
m21.addActionListener(this);
m2.add(m21);
m2.addSeparator();
CheckboxMenuItem mycmi=new CheckboxMenuItem("全部");
mycmi.addItemListener(this);
m2.add(mycmi);
m2.addActionListener(this);
myB.add(m2);
Menu m3=new Menu("帮助");
m3.add("关于");
m3.addActionListener(this);
myB.setHelpMenu(m3);
text=new TextField();
add("South",text);
}
public static void main(String args[])
{
Exam5_19 myMenu=new Exam5_19();
myMenu.init();
myMenu.setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
text.setText("状态改变");
}
public void actionPerformed(ActionEvent e)
{
text.setText(e.getActionCommand());
if(e.getActionCommand()=="退出")
System.exit(0);
}
}
html文件:
怎么运行我都知道
是运行不出来结果
提示:
java.lang.ClassCastException: Exam5_20 cannot be cast to java.applet.Applet
at sun.applet.AppletPanel.createApplet(AppletPanel.java:779)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:708)
at sun.applet.AppletPanel.run(AppletPanel.java:362)
at java.lang.Thread.run(Thread.java:619)
你们不会也不要瞎回答啊!
真晕了!
自己能不能亲身运行一下!
展开