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

📄 droptext.java

📁 java applet 非常全的实例。比较利于初学者进行研究。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.applet.*;
import java.awt.*;
import java.awt.Graphics;
import java.awt.Image;
import java.net.*;
import java.util.*;
import java.lang.*;

public class DropText extends Applet implements Runnable{
	private Thread thread;
	private Image no_clock[];
	private Image no_timer[];

	private int w = 600;

	private int n;
	private String message[];
	private int transform[];

	private Date S_time = null;
	private Date C_time = null;

	private Image buffer;
	private Graphics gContext;

	private Color UpLeftMain;
	private Color UpLeftShadow;
	private Color UpLeftBack;

	private Color DownLeftMain;
	private Color DownLeftShadow;
	private Color DownLeftBack;

	private int transforminfo[];

	private Color RightMain;
	private Color RightShadow;
	private Color RightBack;

	private void DrawNumber (Image i, Color m, Color s, Color b, int j){
		Graphics g;
		int k;

		g = i.getGraphics();
		
		g.setColor (b);
		g.fillRect (0, 0, 14, 24);

		for (k=0; k<2; k++){
			if (k == 0) g.setColor (s); else g.setColor (m);
			
			if ((j != 1) && (j != 4)){
				g.drawLine (1+k, 2-k, 10+k, 2-k);
				g.drawLine (2+k, 3-k, 9+k, 3-k);
				g.drawLine (3+k, 4-k, 8+k, 4-k);
			}

			if ((j != 5) && (j != 6)){
				g.drawLine (11+k, 3-k, 11+k, 11-k);
				g.drawLine (10+k, 4-k, 10+k, 10-k);
				g.drawLine (9+k, 5-k, 9+k, 9-k);
			}

			if (j != 2){
				g.drawLine (11+k, 13-k, 11+k, 21-k);
				g.drawLine (10+k, 14-k, 10+k, 20-k);
				g.drawLine (9+k, 15-k, 9+k, 19-k);
			}


			if ((j != 1) && (j != 4) && (j != 7)){
				g.drawLine (1+k, 22-k, 10+k, 22-k);
				g.drawLine (2+k, 21-k, 9+k, 21-k);
				g.drawLine (3+k, 20-k, 8+k, 20-k);
			}

			if ((j == 0) || (j == 2) || (j == 6) || (j == 8)){
				g.drawLine (0+k, 13-k, 0+k, 21-k);
				g.drawLine (1+k, 14-k, 1+k, 20-k);
				g.drawLine (2+k, 15-k, 2+k, 19-k);
			}

			if ((j != 1) && (j != 2) && (j != 3) && (j != 7)){
				g.drawLine (0+k, 3-k, 0+k, 11-k);
				g.drawLine (1+k, 4-k, 1+k, 10-k);
				g.drawLine (2+k, 5-k, 2+k, 9-k);
			}

			if ((j != 0) && (j != 1) && (j != 7))	{
				g.drawLine (1+k, 12-k, 10+k, 12-k);
				g.drawLine (2+k, 11-k, 9+k, 11-k);
				g.drawLine (2+k, 13-k, 9+k, 13-k);
			}
		}
	}
		

	private Color convertColor (String s){
		int r = 0;
		int g = 0;
		int b = 0; 
		int x = 0;
		Color c;

		while (s.charAt(x) != ';'){
			r = r * 10 + Integer.parseInt(s.substring(x,x+1));
			x++;
		}
		x++;
		while (s.charAt(x) != ';'){
			g = g * 10 + Integer.parseInt(s.substring(x,x+1));
			x++;
		}
		x++;
		b = Integer.parseInt(s.substring(x,s.length()));
		c = new Color (r, g, b);
		return c;
	}

	public void init (){
		Graphics g;
		int i;
		String s;

		w = size().width;

		transforminfo = new int[5];

		no_clock = new Image[13];
		no_timer = new Image[11];

		if (getParameter("tlm") != null)
			UpLeftMain = convertColor (new String(getParameter("tlm")));			
		else UpLeftMain = Color.white;
		if (getParameter("tls") != null)
			UpLeftShadow = convertColor (new String(getParameter("tls")));
		else UpLeftShadow = Color.black;
		if (getParameter("tlb") != null)
			UpLeftBack = convertColor (new String(getParameter("tlb")));
		else UpLeftBack = new Color (0, 0, 102);
		if (getParameter("blm") != null)
			DownLeftMain = convertColor (new String(getParameter("blm")));			
		else DownLeftMain = Color.white;
		if (getParameter("bls") != null)
			DownLeftShadow = convertColor (new String(getParameter("bls")));
		else DownLeftShadow = Color.black;
		if (getParameter("blb") != null)
			DownLeftBack = convertColor (new String(getParameter("blb")));
		else DownLeftBack = new Color (102, 0, 0);
		if (getParameter("rm") != null)
			RightMain = convertColor (new String(getParameter("rm")));			
		else RightMain = Color.white;
		if (getParameter("rs") != null)
			RightShadow = convertColor (new String(getParameter("rs")));
		else RightShadow = new Color(102, 102, 102);
		if (getParameter("rb") != null)
			RightBack = convertColor (new String(getParameter("rb")));
		else RightBack = Color.black;

		for (i=0; i<=9; i++){
			no_clock[i] = createImage (14, 24);
			DrawNumber (no_clock[i], UpLeftMain, UpLeftShadow, UpLeftBack, i);
			no_timer[i] = createImage (14, 24);
			DrawNumber (no_timer[i], DownLeftMain, DownLeftShadow, DownLeftBack, i);
		}

		no_clock[10] = createImage (5, 24);
		g = no_clock[10].getGraphics();
		g.setColor (UpLeftBack);
		g.fillRect (0, 0, 5, 24);
		g.setColor (UpLeftMain);
		g.drawLine (2, 4, 2, 6);
		g.drawLine (1, 5, 3, 5);
		g.drawLine (2, 14, 2, 16);
		g.drawLine (1, 15, 3, 15);
		g.setColor (UpLeftShadow);
		g.drawLine (0, 6, 1, 7);
		g.drawLine (1, 6, 1, 6);
		g.drawLine (0, 16, 1, 17);
		g.drawLine (1, 16, 1, 16);

		no_timer[10] = createImage (5, 24);
		g = no_timer[10].getGraphics();
		g.setColor (DownLeftBack);
		g.fillRect (0, 0, 5, 24);
		g.setColor (DownLeftMain);
		g.drawLine (2, 4, 2, 6);
		g.drawLine (1, 5, 3, 5);
		g.drawLine (2, 14, 2, 16);
		g.drawLine (1, 15, 3, 15);
		g.setColor (DownLeftShadow);
		g.drawLine (0, 6, 1, 7);
		g.drawLine (1, 6, 1, 6);
		g.drawLine (0, 16, 1, 17);
		g.drawLine (1, 16, 1, 16);

		no_clock[11] = createImage (20, 24);
		g = no_clock[11].getGraphics();
		g.setColor (UpLeftBack);
		g.fillRect (0, 0, 20, 24);
		g.setColor (UpLeftShadow);
		g.drawLine (0, 3, 0, 10);
		g.drawLine (5, 3, 5, 10);
		g.drawLine (1, 2, 4, 2);
		g.drawLine (1, 6, 4, 6);
		g.drawLine (7, 13, 7, 21);
		g.drawLine (17, 13, 17, 21);
		g.drawLine (8, 14, 12, 18);
		g.drawLine (13, 17, 16, 14);
		g.setColor (UpLeftMain);
		g.drawLine (1, 2, 1, 9);
		g.drawLine (6, 2, 6, 9);
		g.drawLine (2, 1, 5, 1);
		g.drawLine (2, 5, 5, 5);
		g.drawLine (8, 12, 8, 20);
		g.drawLine (18, 12, 18, 20);
		g.drawLine (9, 13, 13, 17);
		g.drawLine (14, 16, 17, 13);

		no_clock[12] = createImage (20, 24);
		g = no_clock[12].getGraphics();
		g.setColor (UpLeftBack);
		g.fillRect (0, 0, 20, 24);
		g.setColor (UpLeftShadow);
		g.drawLine (0, 2, 0, 10);
		g.drawLine (5, 3, 5, 5);
		g.drawLine (1, 2, 4, 2);
		g.drawLine (1, 6, 4, 6);
		g.drawLine (7, 13, 7, 21);
		g.drawLine (17, 13, 17, 21);
		g.drawLine (8, 14, 12, 18);
		g.drawLine (13, 17, 16, 14);
		g.setColor (UpLeftMain);
		g.drawLine (1, 1, 1, 9);
		g.drawLine (6, 2, 6, 4);
		g.drawLine (2, 1, 5, 1);
		g.drawLine (2, 5, 5, 5);
		g.drawLine (8, 12, 8, 20);
		g.drawLine (18, 12, 18, 20);
		g.drawLine (9, 13, 13, 17);
		g.drawLine (14, 16, 17, 13);

		S_time = new Date();

		if (getParameter("n") != null)	{
			s = new String (getParameter("n"));
			n = Integer.parseInt(s);
		} else	{
			n = 0;
		}

		if (n != 0){
			transform = new int[n];
			message = new String[n];

			for (i=0; i<n; i++){
				s = new String("message");
				s = s.concat (String.valueOf(i));
				if (getParameter(s) != null)
					message[i] = new String(getParameter(s));
				else
					message[i] = new String("Missing parameter.");
			}

			for (i=0; i<n; i++){
				transform[i] = 8;
			}

			transforminfo[0] = 0; 
			transforminfo[1] = n-1; 
			transforminfo[2] = 78;

		} else stop();

		buffer = createImage (w, 48);
		gContext = buffer.getGraphics();
	}

	private void showClock (Graphics g){
		int x;

		g.setColor (UpLeftBack);
		g.fillRect (0, 0, 82, 24);

		x = (C_time.getHours() % 12);
		if (x == 0) x = 12;
		if (x / 10 == 1) g.drawImage (no_clock[1], 1, 0, this);
		g.drawImage (no_clock[x % 10], 15, 0, this);
		g.drawImage (no_clock[10], 29, 0, this);
		g.drawImage (no_clock[C_time.getMinutes() / 10], 34, 0, this);
		g.drawImage (no_clock[C_time.getMinutes() % 10], 48, 0, this);
		if (C_time.getHours() > 11)
			g.drawImage (no_clock[12], 62, 0, this);
		else
			g.drawImage (no_clock[11], 62, 0, this);
	}

	private void showTimer (Graphics g){
		int h = 0;
		int m = 0;
		int s = 0;

		h = C_time.getHours() - S_time.getHours();
		if (h < 0) h += 24;
		m = C_time.getMinutes() - S_time.getMinutes();
		if (m < 0){
			m += 60;
			h--;
		}
		s = C_time.getSeconds() - S_time.getSeconds();
		if (s < 0){
			s += 60;
			m--;
		}

		g.setColor (DownLeftBack);
		g.fillRect (0, 24, 82, 24);
		
		g.drawImage (no_timer[s % 10], 67, 24, this);
		g.drawImage (no_timer[s / 10], 53, 24, this);

⌨️ 快捷键说明

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