下面是一个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>

下面是一个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>


相关考题:

PublicclassHoltextendsThread{PrivateStringsThreadName;Publicstaticvoidmain(Stringargv[]){Holth=newHolt();h.go();Holt(){};Holt(Strings){sThreadName=s;PublicStringgetThreadName(){returnsThreadName;}}Publicvoidgo(){Hotfirst=newHot(first);first.start();Hotsecond=newHot(second);second.start();}Publicvoidstart(){For(inti=0;i2;i++){System.out.print(getThreadName()+i);Try{Thread.sleep(100);}catch(Exceptione){System.out.print(e.getMessage());}}}}当编译运行上面代码时,将会出现()A.编译时错误B.输出first0,second0,first0,second1C.输出first0,first1,second10,second1D.运行时错误

阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。【说明】下面的Java程序演示了程序竞争资源(Mutex的实例对象)而引起程序死锁的一种例子。【Java程序】import java.applet.*;import java.awt.*;//此处声明一个互斥类class Mutex { }class A extends (1){private Mutex first,second;public A(Mutex f,Mutex s){first = f;second = s;}public void run(){//锁定first变量(2) (first){try{ //本线程挂起,等待重新调度Thread.sleep(1); //注意此处(1)不是小题序号}catch(InterruptedException e){}System. out. println("threadA got first mutex");(2) (second) //锁定second变量{ //do somethingSystem. out. println("threadA got second mutex");} //释放second变量} //释放first变量}}class B extends (1){private Mutex first,second;public B(Mutex f,Mutex s){(3) ;second = s;}public void run(){(2) (second) //锁定second变量{//do somethingtry{Thread.sleep(((int)(3*Math.random()))*1000);//本线程挂起,等待重新调度}catch(InterruptedException e){}System.out.println("threadB got second mutex");(2) (first) //锁定first变量{//do somethingSystem.out.println("threadB got first mutex");} //释放first变量} //释放second变量}}public class DeadlockExample{public static void main(String arg[]){Mutex mutexX = new Mutex();Mutex mutexY = new Mutex();AthreadA = new A(mutexX,mutexY);B threadB = new B (4);threadA.(5);threadB.start();}}

The Declaration of Independence was adopted by the ___ Continental Congress on July 4, ___. A.First / 1774B.First / 1776C.Second / 1774D.Second / 1776

执行下列程序,显示的结果是______。first="china"second=""a=LEN(first)i=aDO WHILE i>=1second=second+SUBSTR(first,i,1)i=i-1ENDDO?second

下面是一个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程序,其功能是有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>

下面程序的输出结果是【】。 include using namespace std; int x; void funA(int,i 下面程序的输出结果是【 】。include<iostream>using namespace std;int x;void funA(int,int);void funB(int,int);int main(){int first;int second=5;x=6;funA(first,seconD) ;fimB(first,seconD) ;cout<<first<<" "<<second<<" "<<x<<end1;return 0;}void funA(int a,int B){int first;first=a+b;a=2*b;b=first+4;}void funB(int u,int v){int second;second=x;v=second+4;x=u+v;}

下面程序的输出结果是______。 include using namespace std; int x; void funA(int,int);void funB(int,int);int main(){int first;int second=5;x=6;funA(first,second);funB(first,second);cout<<first<<””<<second<<””<<x<<endl;return 0;}void funA(int a,int b){int first;first=a+b;a=2*b;b=first+4;}void funB(int u, int v){int second;second=x;v=second+4;x=u+v;}

有以下程序: include using namespace std; char *x[]={"First", "Second", "Third" 有以下程序: #include <iostream> using namespace std; char *x[]={"First", "Second", "Third" }; void f(char *z[ ]) { cout<<*z++<<end1; } int main ( ) { char **y; y=x; f(y); return 0; }A.产生语法错误B.FirstC.SecpndD.Third