所以我有一个继承Arc2D.Float的类:
package Simon;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.Arc2D;
import javax.swing.JComponent;
public class SimonLight extends Arc2D.Float implements ActionListener{
public Color defCol, lightUpCol, color; //Colors
public enum Orientation {leftU, leftD, rightU, rightD};
Orientation orient;
public SimonLight(Color defCol, Color lightUpCol, Orientation orient, int x, int y){
super.x = x;
super.y = y;
super.width = 200;
super.height = 200;
super.start = 90;
super.extent = 90;
this.defCol = defCol;
this.color = defCol;
this.lightUpCol = lightUpCol;
this.orient = orient;
}
public void actionPerformed(ActionEvent e){
//Does nothing atm
color = lightUpCol;
}
public Color getColor(){
return color;
}
}
但是在构造函数中,我试图将弧类型设置为Arc2D.PIE,但超类中没有变量允许我更改它。有谁知道如何设置类型??
答案 0 :(得分:1)
您应该考虑使用super
构造函数而不是......
public SimonLight(Color defCol, Color lightUpCol, Orientation orient, int x, int y){
super(x, y, 200, 200, 90, 90, Arc2D.PIE);
this.defCol = defCol;
this.color = defCol;
this.lightUpCol = lightUpCol;
this.orient = orient;
}
这通常是一种更好的做法,如果超类要求这些值在内部设置自己;)