Topic: 菜单问题 ?

  Print this page

1.菜单问题 ? Copy to clipboard
Posted by: snooopy
Posted on: 2005-10-22 18:35

请问这程序为什么会出现这样的情况?

为什么我按了four后,不会输出four?
如果说菜单在菜单里就不行的话,那为什么preview和setting就可以 ? 难道多层就不可以了 ?

这个程序如何让four可以有像preview和setting他们这样的效果 ?



package tmp;
import java.awt.*;
import java.awt.event.*;

class TestMenuBar extends Frame{

MenuBar mb = new MenuBar();

Menu fileM = new Menu("File");
Menu editM = new Menu("Edit");
Menu toolsM = new Menu("Tools");
Menu helpM = new Menu("help");

MenuItem file1 = new MenuItem("New");
MenuItem file2 = new MenuItem("Open");
MenuItem file3 = new MenuItem("Save");

Menu file4 = new Menu("Print");
MenuItem file41 = new MenuItem("preview");
MenuItem file42 = new MenuItem("setting");

CheckboxMenuItem cm = new CheckboxMenuItem("Quit",true);

Menu one = new Menu("one");
Menu two = new Menu("Two");
Menu three = new Menu("Three");
MenuItem four = new MenuItem("Four");

public TestMenuBar(){
mb.add(fileM);
mb.add(editM);
mb.add(toolsM);
mb.add(helpM);

file4.add(file41);
file4.add(file42);
AL A = new AL();
file41.addActionListener(A);
file42.addActionListener(A);
four.addActionListener(A);

three.add(four);
two.add(three);
one.add(two);

fileM.add(file1);
fileM.add(file2);
fileM.add(file3);
fileM.add(file4);
fileM.addSeparator();
fileM.add(cm);
fileM.add(one);


this.setMenuBar(mb);

addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
}
public static void main(String arga[]){
TestMenuBar tmb = new TestMenuBar();
tmb.setSize(500,350);
tmb.setVisible(true);
}
}

class AL implements ActionListener{
public void actionPerformed(ActionEvent e){
if (e.getActionCommand().equals("preview")){
System.out.println("Preview");
}  else if (e.getActionCommand().equals("setting")){
System.out.println("Setting");
}  else if (e.getActionCommand().equals("four")){ // 这里将four改成Four也不行 ?
System.out.println("Four");
}
}
}


2.Re:菜单问题 ? [Re: snooopy] Copy to clipboard
Posted by: nicholastse0303
Posted on: 2005-11-20 18:24

郁闷,改成大写的就可以啊 .我运行拉的.
你是不是改拉没编译,或者有的时候编译器,不是很"灵活".
本来就应该是大写的,你定义的时候定义的就是大写的.


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923