【发布时间】:2021-02-21 14:30:45
【问题描述】:
所以基本上我有一个矩形类,我想实现一个方法,在它被绘制后改变它的颜色。
到目前为止,这是我的代码。以为它可能会像更改对象的位置一样起作用,但事实并非如此。
public class rectangle extends JPanel(){
@Override
protected void paintComponent(Graphics g){
super.paintComponent(g);
g.setColor(Color.red)
g.fillRect(0, 0, 30, 30);
}
public void recolor(){
Color.blue;
repaint();
}
}
【问题讨论】:
标签: java swing colors rectangles repaint