⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example9_18.java.bak

📁 不错的教程 适合中高级人员的使用
💻 BAK
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.Timer;
public class Example9_18
{
	public static void main(String args[])
   { 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);
	  setVisible(true);
	  setSize(500,500);
	  validate();
	  addWindowListener(new WindowAdapter()
                      {   public void windowClosing(WindowEvent e)
                           { setVisible(false);
                           }
                      }
                   );
   }
   public void actionPerformed(ActionEvent e)
	{
	   if(e.getSource()==time)
		{
		  java.util.Date date=new java.util.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();		      
	   }
   }
  
  

 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -