主题:请高手帮忙
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class test0 extends Applet {
MyFrame f=new MyFrame("bingbing");
MenuBar mb1=new MenuBar();
Menu fi=new Menu("File");
Menu e=new Menu("Edit");
Menu s=new Menu("Option");
MenuItem[] file={
new MenuItem("exit")};
MenuItem[] edit={
new MenuItem("copy"),
new MenuItem("cut"),
new MenuItem("paste"),
new MenuItem("deleteall")};
MenuItem[] option={
new MenuItem("font")};
ML ml1=new ML();
//MIL mil1=new MIL();
WL fw1=new WL();
public void init() {
f.setMenuBar(mb1);
mb1.add(fi);
for(int i=0;i<file.length;i++)
fi.add(file[i]);
mb1.add(e);
for(int i=0;i<edit.length;i++)
e.add(edit[i]);
mb1.add(s);
for(int i=0;i<option.length;i++)
s.add(option[i]);
file[0].setActionCommand("exit");
file[0].addActionListener(ml1);
f.addWindowListener(fw1);
f.setSize(200,300);
}
class WL extends WindowAdapter{
public void actionPerformed(ActionEvent e){
f.setVisible(false);
}
}
class MyFrame extends Frame {
MyFrame(String s){
super(s);
setLayout(new FlowLayout());
}}
class ML implements ActionListener{
public void actionPerformed(ActionEvent e){
MenuItem target=(MenuItem)e.getSource();
String ac=target.getActionCommand();
if(ac.equals("exit")){
f.setVisible(false);
}
}
}
class MIL implements ItemListener{
public void itemStateChanged(ItemEvent e){
CheckboxMenuItem target=(CheckboxMenuItem)e.getSource();
String acommand=target.getActionCommand();
if(acommand.equals("copy"))
if(acommand.equals("cut"))
if(acommand.equals("paste"))
if(acommand.equals("deleteall"))
stop();
}
}
}
着是我用来做菜单的,编译没问题,但是运行的时候显示不了菜单?这是怎么回事啊?
import java.applet.*;
import java.awt.event.*;
public class test0 extends Applet {
MyFrame f=new MyFrame("bingbing");
MenuBar mb1=new MenuBar();
Menu fi=new Menu("File");
Menu e=new Menu("Edit");
Menu s=new Menu("Option");
MenuItem[] file={
new MenuItem("exit")};
MenuItem[] edit={
new MenuItem("copy"),
new MenuItem("cut"),
new MenuItem("paste"),
new MenuItem("deleteall")};
MenuItem[] option={
new MenuItem("font")};
ML ml1=new ML();
//MIL mil1=new MIL();
WL fw1=new WL();
public void init() {
f.setMenuBar(mb1);
mb1.add(fi);
for(int i=0;i<file.length;i++)
fi.add(file[i]);
mb1.add(e);
for(int i=0;i<edit.length;i++)
e.add(edit[i]);
mb1.add(s);
for(int i=0;i<option.length;i++)
s.add(option[i]);
file[0].setActionCommand("exit");
file[0].addActionListener(ml1);
f.addWindowListener(fw1);
f.setSize(200,300);
}
class WL extends WindowAdapter{
public void actionPerformed(ActionEvent e){
f.setVisible(false);
}
}
class MyFrame extends Frame {
MyFrame(String s){
super(s);
setLayout(new FlowLayout());
}}
class ML implements ActionListener{
public void actionPerformed(ActionEvent e){
MenuItem target=(MenuItem)e.getSource();
String ac=target.getActionCommand();
if(ac.equals("exit")){
f.setVisible(false);
}
}
}
class MIL implements ItemListener{
public void itemStateChanged(ItemEvent e){
CheckboxMenuItem target=(CheckboxMenuItem)e.getSource();
String acommand=target.getActionCommand();
if(acommand.equals("copy"))
if(acommand.equals("cut"))
if(acommand.equals("paste"))
if(acommand.equals("deleteall"))
stop();
}
}
}
着是我用来做菜单的,编译没问题,但是运行的时候显示不了菜单?这是怎么回事啊?