gamepanle.java
来自「自己写的一个Java版本的俄罗斯方块」· Java 代码 · 共 44 行
JAVA
44 行
package lx.view;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import lx.entity.Ground;
import lx.entity.Shape;
import lx.util.Global;
public class GamePanle extends JPanel {
private static final long serialVersionUID = -1758362163721181062L;
private Ground ground;
private Shape shape;
public GamePanle() {
//设置Panle宽为300,高为300
this.setSize(Global.WIDTH * Global.CELL_SIZE,
Global.HIGHT * Global.CELL_SIZE);
}
public void dispaly(Ground ground,Shape shape){
System.out.println("Ground's display");
this.ground = ground;
this.shape = shape;
this.repaint();
}
@Override
protected void paintComponent(Graphics g) {
//重新显示
g.setColor(new Color(0xcfcfcf));
g.fillRect(0, 0, Global.WIDTH * Global.CELL_SIZE,
Global.HIGHT * Global.CELL_SIZE);
if(shape != null && ground != null){
shape.drawMe(g);
ground.drawMe(g);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?