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

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

请完成下列Java程序:制作一个图形用户界面,上方包含一个TextField和Button构件,实现输入字符串,点击Button获取文本区的字符:中间显示Label的内容:下方是4个按钮,分别实现控制Label在最左边,在中间,在右边和退出程序的功能。

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

程序运行结果如下:

import java.awt.*;

import java.awt.event.*;

public class ex15_2 extends Frame. implements ActionListener {

private Label 1;

private TextField tf;

public static void main(String[] args) {

ex15_2 obj15_2 = new ex15_2();

}

public ex15_2() {

setBackground(Color.gray);

l = new Label("Welcom to the NCR Examination!");

Font font = new Font("TimesRoman",Font.BOLD,20);

l.setFont(font);

add("Center",l);

Panel p = new Panel();

Button b = new Button("Left");

b.addActionListener(this);

p.add(b);

b = new Button("Center");

b.addActionListener(this);

p.add(b);

b = new Button("Right");

b.addActionListener(this);

p.add(b);

________________;

b = new Button("Exit");

b.addActionListener(this);

p.add(b);

p = new Panel();

tf = new TextField(40);

p.add(tf);

b = new Button("Set");

b.addActionListener(this);

p.add(b);

add("North",p);

setSize(500,300);

show();

}

public void actionPerformed(ActionEvent ae) {

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

System.exit(0);

else if(ae.getActionCommand().equals("Left"))

____________________;

else if(ae.getActionCommand().equals("Center")

l.setAlignment(Label.CENTER);

else if(ae.getActionCommand().equals("Right"))

l.setAlignment(Label.RIGHT);

else if(ae.getActionCommand().equals("Set"))

l.setText(tf.getText());

}

}


参考答案

更多 “ 请完成下列Java程序:制作一个图形用户界面,上方包含一个TextField和Button构件,实现输入字符串,点击Button获取文本区的字符:中间显示Label的内容:下方是4个按钮,分别实现控制Label在最左边,在中间,在右边和退出程序的功能。注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。程序运行结果如下:import java.awt.*;import java.awt.event.*;public class ex15_2 extends Frame. implements ActionListener {private Label 1;private TextField tf;public static void main(String[] args) {ex15_2 obj15_2 = new ex15_2();}public ex15_2() {setBackground(Color.gray);l = new Label("Welcom to the NCR Examination!");Font font = new Font("TimesRoman",Font.BOLD,20);l.setFont(font);add("Center",l);Panel p = new Panel();Button b = new Button("Left");b.addActionListener(this);p.add(b);b = new Button("Center");b.addActionListener(this);p.add(b);b = new Button("Right");b.addActionListener(this);p.add(b);________________;b = new Button("Exit");b.addActionListener(this);p.add(b);p = new Panel();tf = new TextField(40);p.add(tf);b = new Button("Set");b.addActionListener(this);p.add(b);add("North",p);setSize(500,300);show();}public void actionPerformed(ActionEvent ae) {if(ae.getActionCommand().equals("Exit"))System.exit(0);else if(ae.getActionCommand().equals("Left"))____________________;else if(ae.getActionCommand().equals("Center")l.setAlignment(Label.CENTER);else if(ae.getActionCommand().equals("Right"))l.setAlignment(Label.RIGHT);else if(ae.getActionCommand().equals("Set"))l.setText(tf.getText());}} ” 相关考题
考题 (6)在窗体上画一个文本框、一个标签和一个命令按钮,其名称分别为 Text1、Label1 和 Command1,然后编写如下两个事件过程:Private Sub Command1_Click( )S$=InputBox("请输入一个字符串")Text1.Text=S$End SubPrivate Sub Text1_Change( )Label1.Caption=UCase(Mid(Text1.Text, 7))End Sub程序运行后,单击命令按钮,将显示一个输入对话框,如果在该对话框中输入字符串“VisualBasic”,则在标签中显示的内容是 【6】 。

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

考题 在窗体上画一个文本框、一个标签和一个命令按钮,其名称分别为Textl、Labell和Command1,然后编写如下两个事件过程:Private Sub Commandl_Click()S$=InputBox(”请输入一个字符串”)Textl.Text=S$End SubPrivate Sub Textl Change()Label1.Caption=UCase(Mid(Text1.Text,7))End Sub程序运行后,单击命令按钮,将显示一个输入对话框,如果在该对话框中输入字符串“VisualBasic”,则在标签中显示的内容是【 】。

考题 在程序中,使用适当的布局管理器,在Frame框的North位置添加一句提示信息,在South位置添加一个单行文本框,在这个文本框中输入的内容将会显示在Center位置。运行结果如下图所示。注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。import java.awt.*;import java.awt.event.*;public class simple extends Frame{public static void main(String[] args){simple frame=new simple("simple");frame.init();frame.setSize(300,300);frame.show();}public simple(String name){super(name);addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){______;}} );}public void init(){setLayout(new______);Label labelTitle=new Label("在本文框中输入字符串, 可以早Frame中间显示");Label showTextLabel=new Label();TextField textField=new TextField("请在这里输入字符串");textField.addActionListener(new AddStringListener(showTextLabel,textField));add("North", labelTitle);add("Center", showTextLabel);add("South", textField);}}class AddStringListener implements ActionListener{Label label;TextField textField;public AddStringListener(Label label, TextField textField){this.label=label;this.textField=textField;}public void actionperformed(ActionEvent e){label.setText(textField.getText());}}

考题 阅读以下说明和Java代码,将解答写入对应栏内。【说明】请完成下列Java程序。程序的执行结果是生成一个具有一个TextField类型的对象in、 Button类型的对象btn和Label类型的对象out图形用户界面,程序的功能是计算用户输入数的平方,如图3所示。注意:请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。【程序】import java. awt.*;import java, awt. event.*;public class square {public static void main(String args[ ]){(1)}}class AppFrame. extends Frame{TheAdapterTest listener = new TheAdapterTest( );Text Field in = new TextField (5);Button btn = new Button("计算");Label ut = new Label("用于显示计算结果");public AppFrame( ){setLayout( new FlowLayout( ));add(in);add(btn)add(out);btn. addActionListener( new BtnActionAdapter( ));addWindowListener (listener);setSize(400,100);show( );}class BtnActionAdapter implements (2) {public void actionPerformed((3)) {String s = in. getText( );double d =(4)double sq = d * d;out. setText(d+"的平方是:" +sq);}}class TheAdapterTest extends WindowAdapter{public void windowCIosing((5)){System. exit(1)}}}

考题 在窗体上画一个文本框Text1、一个标签Label1和一个命令按钮Command1,然后编写如下两个事件过程: Private Sub Command1_Click() a=InputBox("请输入一个字符串") Text1.Text=a End Sub Private Sub Textl_Change() Label1.Caption=UCase(Mid(Text1.Text,8)) End Sub 程序运行后,单击命令按钮,将显示一个输入对话框,如果在该对话框中输入字符串“Visual Basic”,则在标签中显示的内容是A.visual basicB.VISUAL BASICC.basicD.BASIC

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

考题 根据本讲学习内容,综合运用TableLayout、Button、TextView进行界面布局,以及掌握按钮的点击事件监听。 (1)创建一个计算器,界面如附件所示,可以完成带小数的加、减、乘、除四则运算。 (2)del按钮可以删除一个字符,C按钮可以清除输入的整个表达式。 (3)提交的作业包中包含应用程序的运行效果截图和源代码。 (4 ) 界面效果如附件所示。

考题 设计一个简单留言程序,当输入留言信息并单击“提交”按钮时,在提交按钮下方的label标签处,显示留言人昵称、留言内容和提交时间。