timethread.java

来自「java写的模仿windows上的挖雷的游戏」· Java 代码 · 共 62 行

JAVA
62 行
字号
//package mine;

import javax.swing.*;

public class TimeThread extends Thread 
{
  int numOfSecond = 0;
  JLabel timeLabel;
  MainFrame theFrame;

  public TimeThread(MainFrame theFrame)
  {
    this.timeLabel = theFrame.jLabelTime;
    this.theFrame = theFrame;
    
  }
  public void run()
  {
    numOfSecond = 0;
    outer:
    while(true)
    {
      if(theFrame.isRestart)
      {
        try
        {
          Thread.sleep(1000);
          numOfSecond++;
          if(numOfSecond < 10)
            timeLabel.setText("000"+numOfSecond);
          else
            if(numOfSecond < 100)
              timeLabel.setText("00"+numOfSecond);
            else
              if(numOfSecond < 1000)
                timeLabel.setText("0"+numOfSecond);
                  if(numOfSecond == 9999)
                    break;
              
        }
        catch(InterruptedException e)
        {
          JOptionPane.showMessageDialog(null,"InterruptedException occured here: " + e);
        }
      }
      else 
      {/*
        if(theFrame.sumOfNotMine==0)
        {
          JOptionPane.showMessageDialog(null,"You Win!!!");
          break outer;
        }
        else
        {
          JOptionPane.showMessageDialog(null,"You Lose!!!");
          break outer;
        }*/
        break;
      }
    }
  }
}

⌨️ 快捷键说明

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