[填空題] bar為一JSerollBar組件,閱讀下面程序段,請(qǐng)?jiān)诔绦蛑械漠嬀€處填入正確的語句使程序能夠正確運(yùn)行。 … public WellAdjusted
[填空題] bar為一JSerollBar組件,閱讀下面程序段,請(qǐng)?jiān)诔绦蛑械漠嬀€處填入正確的語句使程序能夠正確運(yùn)行。 … public WellAdjusted() { super("Well Adjusted"); setSize(350,100); bar.addAdjustmentListener(this); value.setHorizontalAlignment(SwingConstants.CENTER); value.setEditable(false); JPanel pane=new JPane(); pane.setLayout(new BorderLayout()); pane.add(value,"Center"): pane.add(bar,"South"); setContentPane(pane); } public void adjustmentValueChanged(AdjustmentEvent evt) { 【12】 if(source==bar) {int newValue bar.getValue();value.setText(""+newValue); } repaint(); } …
正確答案:Object source=evt.getSource()
參考解析:本題考查事件及響應(yīng)中的基本知識(shí)。在 WellAdjusted()中將接收器添加到bar對(duì)象中,將滾動(dòng)條和非編輯文本域添加到幀中。 adjustmentValueChanged(AdjustmentEvent evt)中實(shí)現(xiàn)當(dāng)移動(dòng)滾動(dòng)條的時(shí)候在域中顯示消息。缺少getSource()方法決定事件的來源。
詞條內(nèi)容僅供參考,如果您需要解決具體問題
(尤其在法律、醫(yī)學(xué)等領(lǐng)域),建議您咨詢相關(guān)領(lǐng)域?qū)I(yè)人士。