📄 mazecell.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package maze;import java.awt.Color;import java.awt.Dimension;import java.awt.Graphics;import javax.swing.JComponent;/** * * @author James Bond 007 */public class MazeCell extends JComponent{ public static final int CELL_W = 15; public static final int CELL_H = 15; private boolean finish; private boolean start; private boolean visited; private boolean used; private boolean wall; private int x; private int y; public MazeCell(int x, int y) { this.x = x; this.y = y; wall = false; start = false; finish = false; used = false; visited = false; setPreferredSize(new Dimension(MazeCell.CELL_W, MazeCell.CELL_H)); } @Override public void paintComponent(Graphics g) { if(start) { g.setColor(Color.GREEN); g.fillArc(1, 1, CELL_W - 1, CELL_H - 1, 0, 360); return; } else if(finish) { g.setColor(Color.RED); g.fillArc(1, 1, CELL_W - 1, CELL_H - 1, 0, 360); return; } if(visited && used){ g.setColor(Color.ORANGE); g.fillRect(1, 1, CELL_W - 2, CELL_H - 2); return; } else if(visited){ g.setColor(Color.BLUE); g.fillRect(1, 1, CELL_W - 2, CELL_H - 2); return; } else{ g.setColor(Color.WHITE); g.fillRect(1, 1, CELL_W - 2, CELL_H - 2); } if(start) { g.setColor(Color.GREEN); g.fillArc(1, 1, CELL_W - 1, CELL_H - 1, 0, 360); } else if(finish) { g.setColor(Color.RED); g.fillArc(1, 1, CELL_W - 1, CELL_H - 1, 0, 360); } if(wall){ g.setColor(Color.BLACK); g.fillRect(1, 1, CELL_W - 2, CELL_H - 2); } } public boolean isFinish() { return finish; } public void setFinish(boolean finish) { this.finish = finish; } public boolean isStart() { return start; } public void setStart(boolean start) { this.start = start; } public boolean isUsed() { return used; } public void setUsed(boolean used) { this.used = used; } public boolean isVisited() { return visited; } public void setVisited(boolean visited) { this.visited = visited; } public boolean isWall() { return wall; } public void setWall(boolean wall) { this.wall = wall; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -