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

📄 drawtable.java

📁 Java 开发的俄罗斯方块游戏
💻 JAVA
字号:
import java.awt.*;

public class DrawTable extends Panel {
	
	int width, height;//空间的宽和高
	int distance ;//单元块之间的距离
	int localWith , localHeight;//单元块的宽和高
	Image img;//采用双缓冲技术防止屏幕闪烁,img和bg均为此目的而定义
	Graphics bg;

	public DrawTable(){		
		width = 300;
		height = 400;
		distance = 20;
		localWith = 18;
		localHeight = 18;
		img=createImage(width,height); 

		
		setLayout(null);
		setSize(this.width, this.height);
	}
	
	//update()是双缓冲的实例
	public void update(Graphics g){
		
		if(img == null){
			img = createImage(width, height);
			bg = img.getGraphics();
		}
		else{
			bg = img.getGraphics();
		}
		paint(bg);
		g.drawImage (img, 0, 0, this);
	}	

	public void paint(Graphics g){

		g.setColor(Color.white);
		g.fillRect(0,0, width, height);

		for(int i = 0; i < Table.getX(); i ++){
			for(int j = 0; j < Table.getY(); j ++){
				if(Table.mytable [i][j] == 1){
					g.setColor(Color.black);
					g.fillRect(	distance *j ,  distance *i, localWith, localHeight);
				}
				else{
					g.setColor(Color.lightGray);
					g.fillRect( distance *j , distance *i, localWith, localHeight);
				}
			}
		}
	}
}

⌨️ 快捷键说明

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