Example9_18

 package itat;

import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Date;

import javax.swing.Timer;


public class Example9_18 {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub

  TimeWin Win=new TimeWin();
  
 }

}
class TimeWin extends Frame implements ActionListener{
 TextField text;
 Button bStart,bStop,bContinue;
 Timer time;
 int n=0,start=1;
 TimeWin(){
  time=new Timer(1000,this);
  text=new TextField(10);
  bStart=new Button("开始计时");
  bStop=new Button("暂停计时");
  bContinue=new Button("继续计时");
  
  bStart.addActionListener(this);
  bStop.addActionListener(this);
  bContinue.addActionListener(this);
  setLayout(new FlowLayout());
  add(bStart);
  add(bStop);
  add(bContinue);
  add(text);
  setSize(500,500);
  validate();
  setVisible(true);
  addWindowListener(new WindowAdapter(){
   public void windowClosing(WindowEvent e){
    System.exit(0);
   }
  });
 }

 
 public void actionPerformed(ActionEvent e) {
  // TODO Auto-generated method stub
  if(e.getSource()==time){
   Date date=new Date();
   String str=date.toString().substring(11,19);
   text.setText("时间:"+str);
   int x=text.getBounds().x;
   int y=text.getBounds().y;
   y=y+2;
   text.setLocation(x,y);
   
  }else if(e.getSource()==bStart){
   time.start();
  }else if(e.getSource()==bStop){
   time.stop();
  }else if(e.getSource()==bContinue){
   time.restart();
  }
  
 }
 
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值