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

📄 statuspanel.java

📁 用JAVA实现蜘蛛纸牌
💻 JAVA
字号:
package dujid.araneid;

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

public class StatusPanel extends JPanel implements Runnable {
	Thread runner;
	private Araneid main;

	public StatusPanel(Araneid main) {
		this.main = main;
		if (this.runner==null) {
			this.runner = new Thread(this);
			this.runner.start();
		}
	}

	public void paintComponent(Graphics g) {
		Graphics2D comp = (Graphics2D)g;
		Font font = new Font("宋体",0,12);
		comp.setFont(font);
		comp.drawRect(0,0,this.getSize().width-1,this.getSize().height-1);
		comp.setColor(Color.yellow);
		comp.fillRect(1,1,this.getSize().width-2,this.getSize().height-2);
		comp.setColor(Color.black);
		Player player = (Player)main.player;

		String[] msg = {
			"玩    家:"+player.getNickname(),
			"流逝时间:"+player.getLapseTime()+" 秒",
			"得    分:"+player.getScore()
		};

		int max=0;
		for(int i=0;i<msg.length;i++) {
			if (max<msg[i].length()) max = msg[i].length();
		}
		int x = (this.getSize().width-max*10)/2;
		for(int i=0;i<msg.length;i++) {
			comp.drawString(msg[i],x,30+i*20);
		}
	}

	public void run() {
		try {
			while(true) {
				main.player.addLapseTime();
				this.repaint();
				Thread.sleep(1000);
			}
		} catch (InterruptedException ignore) {}
	}
}

⌨️ 快捷键说明

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