我的班级名为UI
extends RoundButton
,如下所示:
public class RoundButton extends JButton {
public RoundButton(String label) {
super(label);
this.setContentAreaFilled(false);
Dimension size = this.getPreferredSize();
size.height = size.width = Math.max(size.height, size.width);
this.setPreferredSize(size);
}
@Override
protected void paintComponent(Graphics g) {
if(!GameState.getIfComplete()) { // If the game is not complete or has just started
this.setBorder(null);
g.setColor(Color.BLACK);
g.fillRect(0, 0, this.getSize().width, this.getSize().height);
if(this.getModel().isArmed()) {
g.setColor(Color.RED);
}else {
g.setColor(Color.GREEN);
}
g.fillOval(0,0,this.getSize().width-1,this.getSize().height-1);
super.paintComponent(g);
}else {
this.setBorder(null);
g.setColor(Color.BLACK);
g.fillRect(0, 0, this.getSize().width, this.getSize().height);
if(this.getModel().isArmed()) {
g.setColor(Color.BLUE);
}else {
g.setColor(Color.BLUE);
}
g.fillOval(0,0,this.getSize().width-1,this.getSize().height-1);
super.paintComponent(g);
}
}
}
里面UI
有一个名为的方法disableAllButtons
,如下所示:
public void disableAllButtons() {
int count =0 ;
while(count <= buttons.length-1) {
buttons[count].setEnabled(false);
buttons[count].paintComponent(Graphics g); // GENERATES AN ERROR
// where buttons[count] = new RoundButton()
count++;
}
}
从我尝试调用的这种方法中,我在课堂上paintComponent
覆盖了。RoundButton
但我得到一个错误:
')' expected
';' expected
not a statement
cannot find symbol
symbol: variable Graphics
location: class UI
当我导入java.awt.Graphics
课程时。
这是为什么 ?