【分析解答题】
下面程序是一个计时器,从1000秒开始倒计时,直到为0结束。在界面上有两个按钮,一个可以暂停计时,另一个可以继续已经暂停的计时。请更正题中带下划线的部分。 注意:不改动程序的结构,不得增行或删行 import jav
A、awt.*; import jav
A、awt.event.*; import jav
A、applet.Applet; public classExample3_4 extendsApplet { publicColor color =Color.red; private int num= 1000; publicCounter theCounter; privateButton stop; privateButton start; public void init() { stop = newButton("暂停"); start = newButton ("继续"); theCounter = newCounter(this); {{U}}stop.addActionListener(new Lst() implementsActionListener{{{/U}} public void actionPerformedActionEvent e) { theCounter.sus(); } }); start.addActionListener(new SuspenListener()); add(start); add(stop); theCounter.start(); } public void paint(Graphics g) { g.setCotor(color); g.drawString(String.valueOf(num),50,50); } public void setInt(int i) { num=i; } class SuspenListener implementsActionListener { public void actionPerformedActionEvent e) { theCounter.conti (); } } } {{U}}public classCounter extends Thread{{/U}} {Example3_4 example; boolean isHold;Counter Example3_4 ex) { this.example = ex; isHold = false; } public void sus() { isHold = true; } public synchronized void conti() { isHold = false; notify(); } public void run() { for (int i = 1000; i>0; i--) { if (i%2 == 1) example.color =Color.red; else example.color =Color.blue; example.setInt(i); example.repaint(); try { sleep(1000); {{U}}synchronized{{/U}} { while(isHold) wait ( ); } } catch (InterruptedException ie) {} } } } <HTML><HEAD> <TITLE>Example3_4</TITLE></HEAD><BODY> <applet code="Example3_4.class" width=300 height=400> </applet></BODY> </HTML>
查看答案解析
参考答案:
正在加载...
答案解析
正在加载...
根据网考网移动考试中心的统计,该试题:
0%的考友选择了A选项
0%的考友选择了B选项
0%的考友选择了C选项
0%的考友选择了D选项