简答题:本题是一个计时器。窗口中有1个文字标签和3个按钮,名为“复位”、“开始”和“暂停”,初始状态时只有“开始”按钮可用,单击

  • 题目分类:Java
  • 题目类型:简答题
  • 号外号外:注册会员即送体验阅读点!
题目内容:
本题是一个计时器。窗口中有1个文字标签和3个按钮,名为“复位”、“开始”和“暂停”,初始状态时只有“开始”按钮可用,单击该按钮开始计时,并且“开始”按钮的标签变为“继续”且不可用,“暂停”按钮变为可用,单击“暂停”按钮后“暂停”按钮变为不可用,“复位”和“继续”按钮变为可用,此时如果单击“复位”按钮将恢复到初始状态,如果单击“继 续”按钮,则继续进行计数。
import java.awt.*;
import java.awt.event.*;
public class java3 extends Frame extends Runnable
{
Label timeDisp=new Label("0:0",Label.
CENTER);
Thread timerThread;
int time=0:
Button btReset=new Button("复位");
Button btStart=new Button("开始");
Button btStop=new Button("暂停");
java3(){
super("java3");
Panel P=new Panel(new GridLayout(1,O));
btReset.setEnabled(false);
btStop.setEnabled(true)
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
btReset.addActionListener(new ResetListener
());
btStop.addActionListener(new StopListener());
btStart.addActionListener(new StartListener());
P.add(btReset);
P.add(btStart);
P.add(btStop);
add(P,BorderLayout.SOUTH);
timeDisp.setFont(new Font("Courier",Font.
BOLD,60));
add(timeDisp,BorderLayout.CENTER);
pack();
show();
}
void stop(){
Thread t=timerThread;
if(t!=null){
timerThread=null:
try{t.join();}catch(Exception e){}
}
}
public void run(){
while(timerThread= =Thread.currentThread
()){
timeDisp.setText(""+time/10+":"+time%
10+"0");
time++;
try { Thread.sleep(100);}catch(Exception e)
{};
}
}
class ResetListener implements ActionListener{
public void actionPerformed(ActionEvent evt){
this.stop()
timeDisp.setText("0:0");
time=0 ;
btReset.setEnabled(false);
btStart.setEnabled(true);
btStop.setEnabled(false);
btStart.setLabel("开始");
}
}
class StopListener implements ActionListener{
public void actionPerformed(ActionEvent evt){
java3.this.stop();
btReset.setEnabled(true);
btStart.setEnabled(true);
btStop.setEnabled(false);
btStart.setLabel("继续");
}
}
class StartListener implements ActionListener{
public void actionPerformed(ActionEvent evt){
timerThread=new Thread(java3.this);
timerThread.start();
btReset.setEnabled(false);
btStart.setEnabled(false);
btStop.setEnabled(true);
btStart.setLabel("继续");
}
}
static public void main(String[]args){
new java3();
}
}
参考答案:【答案仅供学习,请勿对照自行用药等】
答案解析:

Why did the woman cook setup this restaurant?

Why did the woman cook setup this restaurant?A.To earn money. B.To give children

查看答案

说明:用英语记述下列内容,限100—120词。 假定你的朋友叫杨立,是优秀学生。校报请你写一篇介绍他的短文。他的基本情况

说明:用英语记述下列内容,限100—120词。 假定你的朋友叫杨立,是优秀学生。校报请你写一篇介绍他的短文。他的基本情况是: 1)现在读高二,是班长,是全班

查看答案

本题中,鼠标在窗口中单击一下,就在单击的位置生成一个小矩形,如果在小矩形上双击鼠标左键,则删除小矩形。 import j

本题中,鼠标在窗口中单击一下,就在单击的位置生成一个小矩形,如果在小矩形上双击鼠标左键,则删除小矩形。 import java.awt.*; import

查看答案

________________

________________

查看答案

Why was the man relieved at last?

Why was the man relieved at last?A.Because the telegram was a false one. B.Becau

查看答案