网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

请完成下列Java程序:实现2个下拉式菜单,一个包含exit菜单项,另一个包含item1和item2共2个菜单项。要求选择exit菜单项时,退出程序;选择item1菜单项之后,item1项变为不可选而item2可选;选择item2菜单项时,item2变为不可选而item1可选。

注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。

程序运行结果如下:

import java.awt.*;

import java.awt.event.*;

public class ex18_2 extends Frame. implements ActionListener {

private choiceHandler ch;

private MenuItem item1;

private MenuItem item2;

public static void main(String[] arg) {

new ex18_2 ( );

}

ex18_2 ( ) {

setTitle("ex18_2");

MenuItem item;

ch = new choiceHandler();

MenuBar mb = new MenuBar();

Menu fm = new Menu("File");

fm.addSeparator();

fm.add(item = new MenuItem("Exit"));

item.addActionListener(this);

fm.add(item);

mb.add(fm);

Menu mm = new Menu("Choice");

mm.add(item1 = new MenuItem("item1"));

item1.addActionListener(ch);

mm.add(item2 = new MenuItem("item2"));

item2.addActionListener(ch);

mb.add(mm);

setMenuBar(mb);

setSize(200,200);

show();

}

public void actionPerformed(ActionEvent ae) {

if(ae.getActionCommand().equals("Exit"))

System.exit(0);

else

System.out.println(ae.getActionCommand());

}

class choiceHandler implements ActionListener {

public void actionPerformed(ActionEvent ae) {

String strCommand = ae.getActionCommand();

if(_________________) {

item2.setEnabled(true);

item1.setEnabled(false);

} else if(______________________) {

item2.setEnabled(false);

item1.setEnabled(true);

}

}

}

}


参考答案

更多 “ 请完成下列Java程序:实现2个下拉式菜单,一个包含exit菜单项,另一个包含item1和item2共2个菜单项。要求选择exit菜单项时,退出程序;选择item1菜单项之后,item1项变为不可选而item2可选;选择item2菜单项时,item2变为不可选而item1可选。注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。程序运行结果如下:import java.awt.*;import java.awt.event.*;public class ex18_2 extends Frame. implements ActionListener {private choiceHandler ch;private MenuItem item1;private MenuItem item2;public static void main(String[] arg) {new ex18_2 ( );}ex18_2 ( ) {setTitle("ex18_2");MenuItem item;ch = new choiceHandler();MenuBar mb = new MenuBar();Menu fm = new Menu("File");fm.addSeparator();fm.add(item = new MenuItem("Exit"));item.addActionListener(this);fm.add(item);mb.add(fm);Menu mm = new Menu("Choice");mm.add(item1 = new MenuItem("item1"));item1.addActionListener(ch);mm.add(item2 = new MenuItem("item2"));item2.addActionListener(ch);mb.add(mm);setMenuBar(mb);setSize(200,200);show();}public void actionPerformed(ActionEvent ae) {if(ae.getActionCommand().equals("Exit"))System.exit(0);elseSystem.out.println(ae.getActionCommand());}class choiceHandler implements ActionListener {public void actionPerformed(ActionEvent ae) {String strCommand = ae.getActionCommand();if(_________________) {item2.setEnabled(true);item1.setEnabled(false);} else if(______________________) {item2.setEnabled(false);item1.setEnabled(true);}}}} ” 相关考题
考题 在下列关于菜单的说法中,正确的是()。A、每个菜单项都是一个控件,与其他控件一样都有自己的属性和事件B、除了Click事件之外,菜单项还能响应其他的如DblClick等事件过程C、菜单项的快捷键不可以任意设置D、在程序执行时,如果菜单项的Enabled属性为False,则该菜单项变成灰色,不能被用户选择

考题 请完成下列Java程序:创建一个具有2行3列的GridLayout管理器,包括Choice、Label、Button构件,布局为第1行包括一个Choice构件(包括2个选项item1和item2)、一个Label构件(当选择Choice构件中的选项时,Labe1构件显示相应的名称,即如果点击item1则Labe1中显示item1)和一个exit按钮(点击则退出应用程序),第2行包括3个Button构件。程序运行结果如下。注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。源程序文件清单如下:import java.awt.*;import java.awt.event.*;public class ex11_2 extends Frame. implements ActionListener, ItemListener{private Label 1;private String str="label";private Choice choice11_2;public static void main(String[] arg){new ex11_2();}ex11_2 (){setLayout (______);choice11_2 = new Choice();choice11_2.addItem("item1");choice11_2.addItem("item2");choice11_2.______;add(choice11_2);l=new Label(str);add(l);Button exit11_2 = new Button("exit");exit11_2.addActionListener(this);add(exit11_2);for(int i=0; i<3; i++)add(new Button("button" + i));setSize(300,300);pack();show();}public void actionPerformed(ActionEvent event){if (event.getActionCommand ( ). equals ( "exit" ) ){System.exit(0);}}public void itemStateChanged(ItemEvent event{str=choice11_2.getSelectedItem();l.setText(str);}}

考题 在使用Windows的菜单时,能弹出下级接联菜单的操作是( )A、选择了尾部带省略号的菜单项B、选择了尾部带三角形箭头的菜单项C、选择了颜色变灰的菜单项D、选择了前面带圆点记号的菜单项E、选择了带下划线的菜单项

考题 本题的功能是监听对于菜单项和工具条的操作。窗口中有一个菜单“Color”和一个工具体,菜单“Color”中有菜单项“Yellow”、“Blue”、“Red”和“Exit”,每个菜单项都有对应的图形,单击前三个颜色菜单项,主窗口就变成对应的颜色,单击“Exit”则退出程序。工具条上有4个按钮,分别为三个颜色按钮和一个退出程序的按钮,单击任意一个颜色按钮,主窗口将变成按钮对应的颜色,单击退出程序按钮,则退出程序。import java.awt.*;import java.awt.event.*;import java.beans.*;import javax.swin9.*;public class java3{public static void main(String[]args){ToolBarFrame. frame=new ToolBarFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.show();}}class ToolBarFrame. extends JFrame{public ToolBarFrame(){setTitle("java3");setSize(DEFAULT_WIDTH,DEFAUlT_HElGHT);Container contentPane=getContentPane();panel=new JPanel();contentPane.add(panel,BorderLayout.CEN-TER);Action blueAction=new ColorAction("Blue".new ImageIcon("java3-blue-ball.gif"),Color.BLUE);Action yellowAction=new ColorAction("Yellow",new Imagelcon("java3-yellow-ball.gif"),Col-or.YELLOW);Action redAction=new ColorAction("Red".new Imagelcon("java3-red-ball.gif"),Color.RED);Action exitAction=newAbstractAction("Exit".new Imagelcon("java3-exit.gif")){public void actionPerformed(ActionEvent event){System.exit(0);}};exitAction.putValue(Action.SH()RT_DESCRIP-TIoN,"Exit");JToolBar bar=new JToolBar();bar.add(blueAction);bar.add(yellowAction);bar.add(redAction);bar.addSeparator();bar.add(exitAction);contentPane.addToolBar(bar,BorderLayout.NoRTH);JMenu menu=new JMenu("Color"):menu.add(yellowAction);menu.add(blueAction);menu.add(redAction);menu.add(exitAction);JMenuBar menuBar=new JMenuBar():menuBar.add(menu);SetJ Menu(menuBar);}public static final int DEFAULT_WIDTH=300;public static final int DEFAULT_HEIGHT=200;private JPanel panel;class ColorAction extends AbstractAction{public ColorAction(String name,Icon icon,Colorc){putValue(Action.NAME,name);putValue(Action.SMALL_ICON,icon);putValue(Action.SHORT_DESCRIPTION,name+"background");putValue("Color",c);}public void actionPerformed(ActionEvent evt){Color C=(Color)getValue("Color");panel.setBackcolor(c);}}}

考题 在下列关于菜单项的说法中,错误的是________。A.有些菜单项的前面有一个钩,是因为在设计时输入了“√ ”。B.每个菜单项都是一个对象,也有自己的属性、事件和方法C.菜单中的分隔符也是一个对象D.在程序执行时,如果菜单项的Enabled属性为False,则该菜单项变成灰色,不能被用户选择。

考题 下列关于菜单的叙述中,错误的是()。A.菜单项是一个具有属性的控件B.菜单可以分为下拉式菜单和弹出式菜单两种类型C.菜单项只响应单击事件D.在同一窗体的菜单项中,不允许出现标题相同的菜单项

考题 按照下图实现菜单设计。 (1)菜单为二级,第一级四个菜单项,只需对学校概况设计第二级下拉菜单;要求用无序列表实现(4分) (2)鼠标覆盖到一级菜单时,菜单项底色变为黄色,字体颜色变为黑色;覆盖到二级菜单时菜单项底色变为白色,字体颜色变为黑色(8分) (3)所有菜单项水平、垂直居中(4分) (4)所有菜单项初始状态字体为宋体,字体颜色为白色,底色为红色(4分)

考题 编写如图所示应用程序,单击选择菜单项退出后,显示下面的请选择对话框,选择是结束程序,选择否显示下面的消息对话框。

考题 利用“路径选择工具”选中形状,在编辑菜单中原来为自由变换和变换菜单项的位置处将变为自由变换路径和变换路径菜单项,选择其中任何一个菜单项均可进入自由变形状态。