下面是一个Applet程序,其功能是有两个按钮,分别为First和Second,以及一个Label构件。要求单击 First时能在Label中显示出"Command:First",而单击Second时能显示出"Command:Second",要求只能重载一次 actionPerformed()方法,请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。源程序文件代码清单如下:import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code=ex04_3.class width=800 height=400></applet>*/Public class ex04_3 extends Applet implements ActionListener{private String str="ok";private Label l;private Button btn;public void init(){setLayout(null);l=new Label(str);l.reshape(10,10,100,30);add(l);btn=new Button("First");btn.reshape(10,50,60,20);l.addActionListene(this);add(btn);btn=new Button("Second");btn.reshape(10,100,60,20);btn.setActionCommand("First");btn.addActionListener(this);add(btn);}public void actionPerformed(ActionEvent ae){str="Command:"+ae.getActionCommand();btn.setText(str);}}ex04_3.html<HTML><HEAD><TITLE>ex04_3</TITLE></HEAD><BODY><applet code="ex2_3.class" width=800 height=400></applet></BODY></HTML>

下面是一个Applet程序,其功能是有两个按钮,分别为First和Second,以及一个Label构件。要求单击 First时能在Label中显示出"Command:First",而单击Second时能显示出"Command:Second",要求只能重载一次 actionPerformed()方法,请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。

注意:不改动程序的结构,不得增行或删行。

源程序文件代码清单如下:

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

/*

<applet code=ex04_3.class width=800 height=400>

</applet>

*/

Public class ex04_3 extends Applet implements ActionListener

{

private String str="ok";

private Label l;

private Button btn;

public void init()

{

setLayout(null);

l=new Label(str);

l.reshape(10,10,100,30);

add(l);

btn=new Button("First");

btn.reshape(10,50,60,20);

l.addActionListene(this);

add(btn);

btn=new Button("Second");

btn.reshape(10,100,60,20);

btn.setActionCommand("First");

btn.addActionListener(this);

add(btn);

}

public void actionPerformed(ActionEvent ae)

{

str="Command:"+ae.getActionCommand();

btn.setText(str);

}

}

ex04_3.html

<HTML>

<HEAD>

<TITLE>ex04_3</TITLE>

</HEAD>

<BODY>

<applet code="ex2_3.class" width=800 height=400>

</applet>

</BODY>

</HTML>


相关考题:

在窗体上画两个标签和一个命令按钮,其名称分别为Labell、Label2和Command1,然后编写如下程序: Private Sub func(L As Label,ByVal a As Integer) L.Caption="1234" a=a*a End Sub Private Sub Form_Load() Label1.Caption="ABCD" Label2.Caption=10 End Sub Private Sub Command1_Click() a=Val(Label2.Caption) Call func(Labell,A)Label2.Caption=a End Sub 程序运行后,单击命令按钮,在两个标签Label1和Label2中显示的内容分别是 ______。A.ABCD和10B.1234和100C.ABCD和100D.1234和10

( 27 )在窗体上画两个标签和一个命令按钮,其名称分别为 Label1 、 Label2 和 Command1 ,然后编写如下程序:Private Sub func(L As Label)L.Caption= ” 1234 ”End subPrivate Sub Form_Load()Label2.Caption=10End subPrivate Sub Command1_Click()A=Val(Label2.Caption)Call func(Label1)Label2.Caption=aEnd sub程序运行后,单击命令按钮,则在两个标签中显示的内容分别为A ) ABCD 和 10B ) 1234 和 100C ) ABCD 和 100D ) 1234 和 10

下面是一个Applet程序,其功能是有2个按钮,分别为First和Second,以及一个Label构件。要求单击First时则能在Label中显示出Command: First,而单击Second时则能显示出Command: Second,要求只能使用重载一次actionPerformed()方法。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。程序运行结果如下:import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code=ex3_3.class width=800 height=400></applet>*/public class ex3_3 extends Applet implements ActionListener{private String str="ok";private Label 1;private Button btn;public void init( ){setLayout(null);1=new Label(str);1.reshape(10,10,150,30);add(1);btn=new Button("First");btn.reshape(10,50,60,20);1.addActionListener(this);add(btn);btn=new Button("Second");btn.reshape(10,100,60,20);btn.setActionCommand("First");btn.addActionListener(this);add(btn);}public void actionPerformed(ActionEvent ae){str="Command:"+ae.getActionCommand( );btn.setText(str);}}ex3_3.html<HTML><HEAD><TITLE>ex3_3</TITLE></HEAD><BODY><applet code="ex3_3.class"width=800 height=400></applet></BODY></HTML>

在窗体上画两个标签和一个命令按钮,其名称分别为Label1、Label2和Command1,然后编写下列程序: Private Sub rune(L AS Labe1) Caption="1234" End Sub Private Sub Form. Load( ) Labe11.Caption="ABCDE" Labe12.Caption=10 End Sub Private Sub Command1Click( ) a=Va1(Label2.Caption) Call func(Label1) Label2.Caption a End Sub 程序运行后,单击命令按钮,则在两个标签中显示的内容分别为( )。A.ABCD和10B.1234和100C.ABCD和100D.1234和10

在窗体上画两个标签和一个命令按钮,其名称分别为Label1、Label2和Command1,然后编写如下程序: Private Sub func(L As Label,ByVal a As Integer) L.Caption="1234" a=a*a End Sub Private Sub Form_Load() Label1.Caption="ABCD" Label2.Caption=10 End Sub Private Sub Command1_Click() a=Val(Label2.Caption) Call func(Label1,A)Label2.Caption=a End Sub 程序运行后,单击命令按钮,在两个标签Label1和Label2中显示的内容分别是: ______。A.ABCD和10B.1234和100C.ABCD和100D.1234和10

在窗体上画两个名称分别为Label1和Label2的标签,再画一个名称为Command1的命令按钮,然后编写如下事件过程:运行上面的程序,单击命令按钮.其输出结果是A.8 9B.8 18C.64 9D.64 18

下面是一个Applet程序,其功能是有2个按钮,分别为First和Second,以及一个Labe1构件。要求点击First时则能在 Labe1中显示出Command:First,而点击Second时则能显示出Command:Second,要求只能使用重载一次actionPerformed()方法。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。程序运行结果如下:import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code=ex2_3.class width=800 height=400></applet>*/public class ex2_3 extends Applet implements ActionListener {private String str="ok";private Labe1 1;private Button btn;public void init() {setLayout(null);1=new Label(str);1.reshape(10, 10, 150, 30);add(1);btn = new Button("First");btn.reshape(10, 50, 60, 20);1.addActionListener(this);add(btn);btn = new Button("Second");btn.reshape(10, 100, 60, 20);btn.setActionCommand("First");btn.addActionListener(this);add(btn);}public void actionPerformed(ActionEvent ae) {str="Command: " +ae.getActionCommand();btn.setText(str);}}ex2_3.htm1<HTML><HEAD><TITLE>ex2_3</TITLE></HEAD><BODY><applet code="ex2_3.class" width=800 height=400 ></applet></BODY></HTML>

在窗体上画两个标签和一个命令按钮,其名称分别为Label1、Label2和Command1,然后编写下列程序:Private Sub rune(L AS Labe1)Caption=1234End SubPrivate Sub Form. Load( )Labe11.Caption=ABCDELabe12.Caption=10End SubPrivate Sub Command1Click( )a=Va1(Label2.Caption)Call func(Label1)Label2.Caption aEnd Sub程序运行后,单击命令按钮,则在两个标签中显示的内容分别为( )。A.ABCD和10B.1234和100C.ABCD和100D.1234和10

在考生文件夹中有一个工程文件execise96.vbp及窗体文件execis96.frm。在名为Form1的窗体上有一个命令按钮Cmd1(标题为NEXT)。要求在窗体上建立一个单选按钮数组 Opt1,含4个单选按钮,标题分别为First、Second、Third和Forth,初始状态下,First为选中状态。程序运行情况如下图所示。窗体文件中已经给出了命令按钮的Click事件过程,但不完整,请去掉程序中的注释符“'”,把程序中的问号“?”改为正确的内容,使得每单击命令按钮‘次,就选中下一个单选按钮,如果已经选中最后一个单选按钮,再单击命令按钮,则选中第1个单选按钮。注意:不能修改程序的其他部分。最后,按原文件名并在原文件夹中保存修改后的文件。