注意:不改动程序的结构,不得增行或删行
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
{
E.xample3_4 example;
boolean isHold;
C.ounter (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
[问答题] 怎样设置倒计时,怎样开始、停止、重置倒计时?
[单选题]窗体上有一个名为Commandl的命令按钮和一个名为Timerl的计时器,并有下面的事件过程:Private Sub Commandl_Click()Timerl.Enabled=TrueE.nd SubPrivate Sub Form_Load()Timerl.Interval=10Timerl.Enabled—FalsePrivate Sub Timerl _Timer()C.ommandl.Left=Commandl.Left+10E.nd Sub程序运行时,单击命令按钮,则产生的结果是A
[填空题] 为使计时器控件每隔5秒钟产生一个计时器事件(Timer事件),则应将其Interval属性设置为()。
[单选题]窗体上有一个名为Command 1的命令按钮和一个名为Timer 1的计时器,并有下面的事件过程:Private Sub Command 1_Click()Timerl.Enabled=TrueE.nd SubPrivate Sub Form_ Load()Timerl.Interval=10Timerl.Enabled=FalseE.nd SubPrivate Sub Timerl_Timer()C.ommand l .Left=Commandl .Left+10E.nd Sub程序运行时,单
[单选题]2006年(),北京奥运倒计时两周年A .8月6日B .8月7日C .8月8日D . D.8月8日
[单选题]在窗体上有一个计时器控件Timer1和一个标签控件Labe11,在程序运行的时候,可通过每隔30ms让Labe11左移100缇,从而产生文字移动动画效果。文字从右向左移动,当移动到接近窗体左边界时停止移动,如图20-9所示。空格处应填( )。 Private Sub Form_Load() Labell.Left=Form1.Width Timer1.Interval=30 Timer1.Enabled=True End Sub Private Sub Timer1_Timer() Labell
[填空题] 氧气流量超时是指在投料按钮按下后,延时35秒,氧气流量计时器开始计时,时间20秒。如果20秒后,XV1305()、XV1303()、XV1320()的阀位不正常,气化炉停车联锁动作,气化炉停车。
[单选题]在窗体上有一个计时器控件Timer1和一个标签控件Label1,在程序运行时可通过每隔30毫秒让Lable1左移100缇,从而产生文字移动动画效果。文字从右向左移动,当移动到接近窗体左边界时停止移动。空格处应填 ______。 Private Sub Form1_Load() LabelLeft=FormWidth TimerInterval=30 ______ End Sub Private Sub Timer1_Timer() Lable1.Left=LableLeft -100 If La
[单选题]在窗体上画一个文本框和一个计时器控件,名称分别为Text1和Timer1,在属性窗口中把计时器的Interal属性设置为1000,Enabled属性设