【发布时间】:2016-07-25 23:58:59
【问题描述】:
所以在我扩展 JPanel 的课程中,我有:
`class Pane extends JPanel {
public static final int MAX_X = 10; //Width
public static final int MAX_Y = MAX_X; //Height
private static final int CELL_WIDTH = 50;
private static final int PREF_W = CELL_WIDTH * MAX_X;
private static final int PREF_H = CELL_WIDTH * MAX_Y;
private static final Color FILL_COLOR = Color.red;
static final Color GEM_COLOR = Color.blue;
}`
@Override
protected void paintComponent(Graphics g) {
g.setColor(FILL_COLOR);
g.fillRect(x * CELL_WIDTH, y * CELL_WIDTH, CELL_WIDTH, CELL_WIDTH);
}
我想要做的是在位置 x 和 y 的此类之外,在遍历面板时检索颜色。 非常感谢您的帮助,谢谢!
【问题讨论】:
-
设为非私有,然后使用
Pane.FILL_COLOR? -
我知道如何从 FiILL_COLOR 中检索颜色。我想要做的是检索已在网格上填充的颜色。例如在位置 (2,1)
-
哦,我实际上正在寻找 GEM_COLOR,这就是为什么它不是私有的
-
如果您正在寻找 GEM_COLOR,请使用
Pane.GEM_COLOR? -
对不起,我不是故意要混淆任何人,我知道如何找到 Gem_COLOR,我想将该 GEM_COLOR 与网格中的任何位置进行比较,直到它与颜色匹配