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

📄 digitaldisplay.java

📁 在windows下玩的扫雷用java编写
💻 JAVA
字号:
/*
   该类实现显示数字的功能
*/
import java.awt.*;
import java.util.*;

public class digitaldisplay extends Canvas  {
	int VerLedx[], VerLedy[], HorLedx[], HorLedy[];
	int CifraXP, CifraYP;	        // 所有数字的x,y 位置        
        int CifraVal[];         	// 用来显示	
	boolean BigClock;		// 判断是否到时间	
        String Led[];			// leds的状态
	String Cifre[];			// 所有10个数字的结构		
	Color bgColor;			// 背景色
	Color fgColor;			// 前景色	
	String strValueDisplayed;
	int NumCifre;
        static int MAXNUMCIFRE=10;	
	//构造函数	
	public digitaldisplay(boolean BigClock, int NumCifre, Color bgColor, Color fgColor) {
		this.BigClock=BigClock;
		this.NumCifre=NumCifre;
		this.bgColor=bgColor;
		this.fgColor=fgColor;
		CifraVal=new int[MAXNUMCIFRE];
		if (BigClock == true) {			
			VerLedx = getParameterIntList("2 3 5 5 3 2 0 0 2", ' ');
			VerLedy = getParameterIntList("0 0 2 17 19 19 17 2 0", ' ');
			HorLedx = getParameterIntList("2 17 19 19 17 2 0 0 2", ' ');
			HorLedy = getParameterIntList("0 0 2 3 5 5 3 2 0", ' ');
	            Led = getParameterList("H 4 0,V 0 4,V 22 4,H 4 22,V 0 26,V 22 26,H 4 44", ',');
			CifraYP = 5;
			CifraXP = 37;	
                        resize(new Dimension(CifraXP*NumCifre, 60));
		} else {
			VerLedx = getParameterIntList("0 1 2 3 3 2 1 0 0", ' ');
			VerLedy = getParameterIntList("1 0 0 1 8 9 9 8 1", ' ');
			HorLedx = getParameterIntList("0 1 8 9 9 8 1 0 0", ' ');
			HorLedy = getParameterIntList("1 0 0 1 2 2 3 2 1", ' ');
            	    Led = getParameterList("H 3 0,V 0 3,V 12 3,H 3 12,V 0 15,V 12 15,H 3 24", ',');
			CifraYP = 3;
			CifraXP = 20;	
			resize(new Dimension(CifraXP*NumCifre-CifraYP, 32));
		}
		Cifre = new String[10];
            Cifre[0] = "1 1 1 0 1 1 1";
            Cifre[1] = "0 0 1 0 0 1 0";
            Cifre[2] = "1 0 1 1 1 0 1";
            Cifre[3] = "1 0 1 1 0 1 1";
            Cifre[4] = "0 1 1 1 0 1 0";
            Cifre[5] = "1 1 0 1 0 1 1";
            Cifre[6] = "0 1 0 1 1 1 1";
            Cifre[7] = "1 0 1 0 0 1 0";
            Cifre[8] = "1 1 1 1 1 1 1";
            Cifre[9] = "1 1 1 1 0 1 0";
	} 

        public void SetValue(String str) {
		for (int i=0;i<MAXNUMCIFRE-1;i++){ CifraVal[i]=0; }
                for (int i=0;i<str.length();i++){
		     CifraVal[NumCifre-str.length()+i]=Integer.parseInt(str.substring(i,i+1));
		}
                strValueDisplayed=str;
                repaint();
	}
	// 获取参数列表	
	String[] getParameterList(String param, char sep) {
		String p = param;
		String[] result = null;
		if (param != null) {
			int pos = 0;
			int count = 0;
			while ((pos = p.indexOf(sep)) >= 0) {
				p = p.substring(pos + 1);
				count++;
			}
			if (p.length() > 0) {
			count++;
			}
			result = new String[count];
			p = param;
			for (int i=0; i<result.length; i++) {
				pos = p.indexOf(sep);
				if (pos < 0) {
					result[i] = p.substring(0, p.length());
					p = null;
				} else {
					result[i] = p.substring(0, pos);
					p = p.substring(pos+1);
				}
			}
		}
		return result;
	}
	// 	获取参数初始值列表	
	int[] getParameterIntList(String param, char sep) {
		String p = param;
		int[] result = null;
		if (param != null) {
			int pos = 0;
			int count = 0;
			while ((pos = p.indexOf(sep)) >= 0) {
				p = p.substring(pos + 1);
				count++;
			}
			if (p.length() > 0) {
			count++;
			}
			result = new int[count];
			p = param;
			for (int i=0; i<result.length; i++) {
				pos = p.indexOf(sep);
				if (pos < 0) {
					result[i] = Integer.parseInt(p.substring(0, p.length()));
					p = null;
				} else {
					result[i] = Integer.parseInt(p.substring(0, pos));
					p = p.substring(pos+1);
				}
			}
		}
		return result;
	}
	
	public void PrintLed(Graphics g, int TheLed, int x, int y, Color TheColor) {
		String pTemp[];
		int DrawLedx[],
		    DrawLedy[];
		DrawLedx = new int[9];
		DrawLedy = new int[9];
		pTemp = getParameterList(Led[TheLed],' ');
		if (pTemp[0].compareTo("H") == 0) {
			for (int j=0; j<=8; j++) {
				DrawLedx[j] = 0;
				DrawLedy[j] = 0;
				DrawLedx[j] = HorLedx[j] + x + Integer.parseInt(pTemp[1]);
				DrawLedy[j] = HorLedy[j] + y + Integer.parseInt(pTemp[2]);
			}
		} else {
			for (int j=0; j<=8; j++) {
				DrawLedx[j] = 0;
				DrawLedy[j] = 0;
				DrawLedx[j] = VerLedx[j] + x + Integer.parseInt(pTemp[1]);
				DrawLedy[j] = VerLedy[j] + y + Integer.parseInt(pTemp[2]);
			}
		}
		g.setColor(TheColor);
		g.fillPolygon(DrawLedx, DrawLedy, 9);
	}
	//	显示数字
	public void PrintCifra(Graphics g, int LaCifra, int xpos, int ypos) {
		String CT[];
		CT = getParameterList(Cifre[LaCifra], ' ');
		for (int i=0; i<=6; i++) {
			if (CT[i].compareTo("1") == 0) {
				PrintLed(g, i, xpos, ypos, fgColor);
			} else {
				PrintLed(g, i, xpos, ypos, bgColor);
			}
		}
	}
	// Paint()方法
	public void paint(Graphics g) {
		g.setColor(bgColor);
		g.fillRect(0,0,size().width, size().height);
		g.setColor(fgColor);  
                for (int i=0; i<NumCifre; i++) {
		     PrintCifra(g, CifraVal[i], CifraXP*i, CifraYP);
                }           
	}
	// 更新数据
	public void update(Graphics g) { paint(g);  }
} 

⌨️ 快捷键说明

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