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

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

请完成下列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);

}

}


参考答案

更多 “ 请完成下列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);}} ” 相关考题
考题 AWT中的布局管理器包括BorderLayout、______、CardLayout、GridBagLayout和GridLayout。

考题 采用GridLayout布局管理器的容器,其中的各构件呈______布局。

考题 AWT中的布局管理器包括BorderLayout、【 】、CardLayout、OridBagLayout和GridLayout。

考题 下列程序用GridLayout布局管理器将Frame分为1行3列,并放入Button构件,横线处应填入的语句是( )。 import java.awt.*; public class Test { public static void main (String[] args) { Frame. frm=new Frame. ("GridLayout"); ____________ frm.add (new Button("Button1")); frm.add (new Button("Button2")); frm.add (new Button("Button3")); frm.setSize (300,300); frm.setVisible (true); } }A.frm.setLayout (GridLayout (1,3));B.setLayout (new GridLayout(1,3));C.frm.setLayout (new GridLayout(3,1));D.frm.setLayout (new GridLayout(1,3));

考题 请完成下列Java程序:用awt实现一个图形用户界面,包含一个List构件和一个TextField构件,List中包含5个项目。要求选择不用的项目时,能在TextField构件中显示出相关的信息,包括事件的名称,选择的项目编号和项目的状态。注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。程序运行结果如下:import java.awt.*;import java.awt.event.*;public class ex14_2 extends Frame. implements ItemListener {private TextField tf;private List 1;public static void main(String[] arg) {ex14_2 obj14_2 = new ex14_2();}public ex14_2() {setBackground(Color. GRAY);setTitle("ex14_2");l = new List(5);l.addItemListener(this);l.addItem("Item1");l.addItem("Item2");l.addItem("Item3");l.addItem("Item4");l.addItem("Item5");add("Center",l);tf = new TextField(50);add("South",tf);______________;show ( );}public void itemStateChanged(ItemEvent event)tf.setText( );}}

考题 请完成下列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.布局管理器体现了Java平台无关性B.LayoutManager是一个接口,编程时通常使用的是实现该接口的类C.每个容器都对应一个布局管理器D.在Java中,必须直接设置构件在容器中的位置和直接设置构件的大小

考题 窗体中有一个名称为Button1的命令按钮,和一个Label1控件对象,编写如下事件过程: 程序运行后,单击命令按钮,如果输入3,则在Label1显示的内容是()A3B4C5D6

考题 【单选题】下列叙述中,错误的一项是A.采用GridLayout布局,容器中的每个构件平均分配容器空间B.采用GridLayout布局,容器中的每个构件形成一个网络状的布局C.采用GridLayout布局,容器中的构件按照从左到右、从上到下的顺序排列D.采用GridLayout布局,容器大小改变时,每个构件不再平均分配容器空间