[問答題] 下面是一個Applet程序,其功能是有2個按鈕,分別為First和Second,以及一個Labe1構件。要求點擊First時則能在Labe1中顯示出
[問答題] 下面是一個Applet程序,其功能是有2個按鈕,分別為First和Second,以及一個Labe1構件。要求點擊First時則能在Labe1中顯示出Command:First,而點擊Second時則能顯示出Command: Second,要求只能使用重載一次actionPerformed( )方法。請改正程序中的錯誤(有下畫線的語句),使程序能輸出正確的結果。
注意:不改動程序的結構,不得增行或刪行。
import java.a(chǎn)wt.*;
import java.a(chǎn)wt.event.*;
import java.a(chǎn)pplet.*;
/*
<applet code=ex20_3.class width=800 height=400>
</applet>
*/
public class ex20_3extends 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,100,30);
add(1);
btn=new Button("First");
btn.reshape(10,50,60,20);
1.a(chǎn)ddAcUonljstener(this);add(btn);
btn=new Button("Second");
btn.reshape(10,100,60,20);
btn.setActionCommand("First&
正確答案:btn.addActionListener(this)btn.btn.setActionCommand("second")1.sctTcxt(str)
詞條內(nèi)容僅供參考,如果您需要解決具體問題
(尤其在法律、醫(yī)學等領域),建議您咨詢相關領域?qū)I(yè)人士。