当前位置: 答题翼 > 问答 > 计算机类考试 > 正文
目录: 标题| 题干| 答案| 搜索| 相关
问题

下面程序是一个计时器 从1000秒开始倒计时 直到为0结束。在界面上有两个按钮 一个可以暂停计时 另


下面程序是一个计时器,从1000秒开始倒计时,直到为0结束。在界面上有两个按钮,一个可以暂停计时,另一个可以继续已经暂停的计时。请更正题中带下划线的部分。

注意:不改动程序的结构,不得增行或删行

import java.awt.*;

import java.awt.event.*;

import java.applet.Applet;

public class Example3_4 extends Applet

{

public Color color = Color.red;

private int num= 1000;

public Counter theCounter;

private Button stop;

private Button start;

public void init()

{

stop = new Button("暂停");

start = new Button ("继续");

theCounter = new Counter(this);

stop.addActionListener(new Lst() implements ActionListener{

public void actionPerformed(ActionEvent 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 implements ActionListener

{

public void actionPerformed(ActionEvent e)

{

theCounter.conti ();

}

}

}

public class Counter extends Thread

{

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);

synchronized {

while(isHold)

wait ();

}

}

catch (InterruptedException ie)

{}

}

}

}

<HTML>

<HEAD>

<TITLE>Example3_4</TITLE>

</HEAD>

<BO

请帮忙给出正确答案和分析,谢谢!

参考答案
您可能感兴趣的试题
  • 某铁路桥长1000米,一列火车从桥上通过,测得火车从开始上桥到完全下桥共用l20秒,整列火

  • 某铁路桥长1000米,一列火车从桥上通过,测得火车从开始上桥到完全下桥共用120秒,整列火车完全在桥

  • 在窗体上画一个名称为Timer1的计时器控件,要求每隔0.1秒发生一次计时器事件,则以下正确的属性设置语句是()

  • 受电弓升降弓时间为升弓≤8 秒,降弓≤7秒,计时是以充放气时间开始计算。()

  • RIP路由协议有一个定时器 该定时器定义了一条路由从度量值变为16开始 直到它从路由表里被删除所经过的时间 那么()。

  • 某铁路桥长1000米 一列火车从桥上通过 测得火车从开始上桥到完全下桥共用120秒 整列火车完全在桥