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

📄 scoreanimate.java

📁 Java Swing 版的连连看
💻 JAVA
字号:
package kyodai;

import javax.swing.*;
import java.awt.*;

/**
 * <p>Title: LianLianKan</p>
 * <p>Description: 连连看</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: www.wuhantech.com</p>
 * @author ZhangJian
 * @version 1.0
 */

public class ScoreAnimate
    extends JPanel
    implements Runnable {
  private volatile Thread thread;
  //private boolean isPainting = false;
  private int lastScore, currentScore;
  Color color = new Color(255, 255, 0);
  Font font48 = new Font("serif", Font.BOLD, 42);
  java.text.DecimalFormat df = new java.text.DecimalFormat("0000");

  public ScoreAnimate() {
    this.setMinimumSize(new Dimension(156, 48));
    this.setPreferredSize(new Dimension(156, 48));
  }

  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Dimension d = getSize();
    g2.setBackground(new Color(111, 146, 212));
    g2.clearRect(0, 0, d.width, d.height);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                        RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(color);
    g2.setFont(font48);

    g2.drawString("$" + df.format(lastScore), 20, 40);
  }

  public void start() {
    thread = new Thread(this);
    thread.start();
  }

  public void run() {
    Thread currentThread = Thread.currentThread();
    while (thread == currentThread && lastScore < currentScore) {
      try {
        lastScore++;
        repaint();
        thread.sleep(50l);
      }
      catch (InterruptedException ex) {
      }
    }
  }

  public void setScore(int l, int c) {
    //stop();
    this.lastScore = l;
    this.currentScore = c;
    start();
  }

  public void stop() {
    if (thread != null) {
      thread = null;
    }
  }

}

⌨️ 快捷键说明

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