📄 grid.java
字号:
package piy;
import javax.swing.JPanel;
import java.awt.*;
/**
* The grid that is on the UserEditWindow. This appears _underneath_ the components
* on the window, it doesn't actually contain the components.
* @author David Vivash
* @version 1.0, 2/12/00
*/
public class Grid extends JPanel {
private Image grid = null;
private int gridWidth = 5, gridHeight = 5;
public Grid(int width, int height) {
setGrid(width, height);
}
/**
* Sets the size (spacing) used for the grid.
* @param width the horizontal spacing between dots on the grid
* @param height the vertical spacing between dots on the grid
*/
public void setGrid(int width, int height) {
gridWidth = (width > 1) ? width : 5;
gridHeight = (height > 1) ? height : 5;
repaint();
}
public void update(Graphics g) {
paint(g);
}
public void paint(Graphics g) {
Dimension d = getSize();
if (grid == null || grid.getWidth(null) < d.width || grid.getHeight(null) < d.height) {
grid = createImage(d.width, d.height);
Graphics og = grid.getGraphics();
for (int x=0; x <= d.width; x += gridWidth)
for (int y=0; y <= d.height; y += gridHeight)
og.drawRect(x,y,0,0);
og.dispose();
}
g.drawImage(grid, 0, 0, null);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -