所以我有一个继承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 ,但父类(super class)中没有变量允许我更改它。有谁知道如何设置类型吗?
最佳答案
您应该考虑使用 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;
}
这通常是更好的做法,以防父类(super class)需要在内部设置这些值;)
关于java - 通过继承绘制Arc2D.Float,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32108604/