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

📄 lotsofcircles.java

📁 java编程开发技巧与实例的编译测试通过的所有例程
💻 JAVA
字号:
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Image;
import java.util.*;
import java.awt.event.*;

import javax.swing.*;

public class LotsOfCircles extends JPanel implements Runnable
{
	private Image		offImage	=	null;
	private Graphics	offGraphics	=	null;
	private	Thread 		thread		=	null;
	private	int 		counter		=	0;
	private int 		width 		= 0,	height = 0;
	
	public LotsOfCircles()
	{
		super();
		setDoubleBuffered(false);
		
		//offImage	=	createImage(getSize().width, getSize().height);
		//offGraphics	=	offImage.getGraphics();
		//offPaint(offGraphics);
	}
	public void run()
	{
		Thread currentThread	=	Thread.currentThread();
		while ((thread == currentThread) && (counter < 1000000))
		{
			offPaint(offGraphics);
			counter ++;
			if ((counter % 100) == 0)
				repaint();
			thread.yield();
		}
	}
	public void offPaint(Graphics g)
	{
		Color color	=	new Color((int)(255*Math.random()), (int)(255*Math.random()), (int)(255*Math.random()));
		//Color color	=	new Color(22, 22, 55);
		int x = (int)(getSize().width * Math.random());
		int y = (int)(getSize().height * Math.random());
		int r = 1;
		g.setColor(color);
		g.fillOval(x-r, y-r, 2*r+66, 2*r);
	}
	public void initOffGraphics()
	{
		thread		=	null;
		width		=	getSize().width;
		height		=	getSize().height;
		offImage	=	createImage(width, height);
		offGraphics	=	offImage.getGraphics();
		counter		= 0;
		thread		=	new Thread(this);
		thread.start();
	}
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		if ((width != getSize().width) || (height != getSize().height))
			initOffGraphics();
		if (offImage != null)
			g.drawImage(offImage, 0, 0, null);
	}
}

⌨️ 快捷键说明

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