📄 drawnextshape.java
字号:
import java.awt.*;
//此类显示下一个游戏块
public class DrawNextShape extends Panel{
static int nextShapeTable[][];//此数组标志下一个游戏块
int width, height;//控件的宽和高
static int x = 5;//
static int y = 5;
int distance ;//单元块间隔
int localWith , localHeight;//单元块的宽和高
Image img;//为防止屏幕闪烁,采用双缓冲技术
Graphics bg;//img和bg均为防止闪烁而定义
public DrawNextShape(){
width = 100;
height = 100;
distance = 20;
localWith = 18;
localHeight = 18;
nextShapeTable = new int[x][y];
img=createImage(width,height);
setLayout(null);//不使用布局管理器,自己定义
setSize(this.width, this.height);
}
//将标识数组清空
public static void init(){
for(int i = 0; i < x; i ++){
for(int j = 0; j < y; j ++){
nextShapeTable[i][j] = 0;
}
}
}
//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 < getX(); i ++){
for(int j = 0; j <getY(); j ++){
if(nextShapeTable [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);
}
}
}
}
public int getX() {
return x;
}
public int getY() {
return y;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -