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

📄 timer.java

📁 a very good example of how to use java for a minesweeper game that is much like the windows one. Th
💻 JAVA
字号:
import java.lang.*;
import java.util.*;
import javax.swing.*;

/**
 **designed & build by Grahame batte email: g.batte@lancaster.ac.uk
 *last modified on 22-05-03 
 *used in my minesweeper aplication
 */
 
public class timer extends Thread
{
/**
 *timegone is the amount of time elapsed.
 */
 public int timegone =0;
/**
 *Time100 is the hundereds of secounds passed
 */
 public static int Time100;
/**
 *Time10 is the tens of secounds passed
 */
 public static int Time10;
/**
 *Time1 is the units of secounds passed
 */
 public static int Time1;
 
/**
 *timer constructs a new thread to update the time elapsed. timer is called by a square when the mouse is frist clicked
 */	
	public timer()
		{
	
		}//end timer
/**
 *run runs the timer theard when GameOver is false and whent Square.numclicks is greater then 0.
 *this means the thread stops when the game is over and only starts once when the the frist click happens.
 */		
 	public void run()
 		{
 		 while ((Square.GameOver==false)&&(Square.GameWon==false)&&(Square.numclicks>0))

 		 	{
 		 	 timegone++;
 //		 	 System.out.println(timegone);
		 	 Time100= timegone/100;				// finds the hundreds sec
		 	 Time10=(timegone-Time100*100)/10;		//find the tens sec
			 Time1=timegone%10;						//find the units
			 MineSweeper.time1.setIcon(new ImageIcon("digits/"+Time1+".gif"));	//sets button to display wright image
			 MineSweeper.time10.setIcon(new ImageIcon("digits/"+Time10+".gif"));	//
			 MineSweeper.time100.setIcon(new ImageIcon("digits/"+Time100+".gif"));//
 		 		try
 		 			{
 		  	 		 sleep(900);
		 			}
 		 		catch (Exception E){}

 			}//end while
 		}// end run()
	
}//end class
	

⌨️ 快捷键说明

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