[多項(xiàng)選擇題] 簡單應(yīng)用題請完成下列Java程序:制作一個圖形用戶界面,上方包含一個TextField和Button構(gòu)件,實(shí)現(xiàn)輸入字符串,點(diǎn)擊Button獲取文
[多項(xiàng)選擇題] 簡單應(yīng)用題請完成下列Java程序:制作一個圖形用戶界面,上方包含一個TextField和Button構(gòu)件,實(shí)現(xiàn)輸入字符串,點(diǎn)擊Button獲取文本區(qū)的字符;中間顯示Label的內(nèi)容;下方是4個按鈕,分別實(shí)現(xiàn)控制Label在最左邊,在中間,在右邊和退出程序的功能。注意:請勿改動main( )主方法和其他已有語句內(nèi)容,僅在下劃線處填入適當(dāng)?shù)恼Z句。程序運(yùn)行結(jié)果如下:import java.awt.*;import java.awt.event.*;public class ex15_2 extends Frame implements ActionListener { private Label l; private TextField tf; public static void main(String[] arg) { 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.addActionLis
正確答案:add("South",p)l.setAlignment(Label.LEFT)
參考解析:本題主要考查AWT基本構(gòu)件Button, Pane, Label和TextField結(jié)合的簡單應(yīng)用。解題關(guān)鍵是熟悉這幾種基本構(gòu)件一般用法,會設(shè)置Label在窗口中的位置。本題中,第1個空,將面板構(gòu)件放在窗口的最下方;第2個空,根據(jù)Button事件調(diào)用l對象的setAlignment()方法,設(shè)置Label在面板中的位置。
詞條內(nèi)容僅供參考,如果您需要解決具體問題
(尤其在法律、醫(yī)學(xué)等領(lǐng)域),建議您咨詢相關(guān)領(lǐng)域?qū)I(yè)人士。