자신 만의 GUI 라이브러리를 만들려고합니다. 수퍼 클래스에서 약간의 어려움을 겪고 있습니다.이 클래스는 새로운 것이고, 배우기 좋은 소스를 찾을 수 없습니다.). 하지만 모든 구성 요소를 "GGUI"에서 확장 한 다음 쉽게 액세스 할 수 있도록 ArrayList에 저장합니다. 내 문제는 내가 오류가 : "Implicit super constructor GrimGUI.GGUI() 정의되지 않았습니다. 명시 적으로 다른 생성자를 호출해야합니다".목록에서 수퍼 클래스의 원본 클래스에 액세스합니다.
GrimGUI :
이Button testScreen;
Slider firstSlider;
Slider secondSlider;
Text firstSliderText;
Text secondSliderText;
boolean onHome;
boolean onTest;
ArrayList<GGUI> gguiScreen = new ArrayList<GGUI>();
void setup() {
size(500, 500);
onHome = true;
background(255);
gguiScreen.add(new Button(75, 50, 40, 20));
testScreen = new Button(115, 50, 40, 20);
testScreen.cNormal = color(0, 255, 125);
firstSlider = new Slider(250, 250, 100);
secondSlider = new Slider(250, 280, 100);
firstSliderText = new Text(280, 250, "0");
secondSliderText = new Text(280, 280, "0");
}
void draw() {
background(255);
HomeScreen();
TestScreen();
endFix();
}
void HomeScreen() {
if (onHome) {
testScreen.Update();
firstSlider.Update();
firstSliderText.content = str(firstSlider.value);
firstSliderText.Update();
if (testScreen.released) {
onTest = true;
onHome = false;
}
}
}
void TestScreen() {
if (onTest) {
Button trash = (Button)gguiScreen.get(0);//Testing that I can get the only object placed in it to view on screen
trash.Update();
secondSlider.Update();
secondSliderText.content = str(secondSlider.value);
secondSliderText.Update();
if (trash.WasClicked()) {
onTest = false;
onHome = true;
}
}
}
버튼 :
이class Button extends GGUI {
boolean visible, pressed, released, hovering;
color cNormal, cPressed, cReleased, cHovering;
float x, y, w, h;
Button(float X, float Y, float W, float H) {
visible = true;
x = X;
y = Y;
w = W;
h = H;
cNormal = color(75, 75, 75);
cPressed = color(100, 100, 100);
cReleased = color(125, 125, 125);
cHovering = color(175, 175, 175);
}
Button(boolean visibility, float X, float Y, float W, float H) {
visible = visibility;
x = X;
y = Y;
w = W;
h = H;
cNormal = color(75, 75, 75);
cPressed = color(100, 100, 100);
cReleased = color(125, 125, 125);
cHovering = color(175, 175, 175);
}
Button(boolean visibility, float X, float Y, float W, float H, color CNORMAL, color CPRESSED) {
visible = visibility;
x = X;
y = Y;
w = W;
h = H;
cNormal = CNORMAL;
cPressed = CPRESSED;
cReleased = color(125, 125, 125);
cHovering = color(175, 175, 175);
}
Button(boolean visibility, float X, float Y, float W, float H, color CNORMAL, color CPRESSED, color CHOVERING) {
visible = visibility;
x = X;
y = Y;
w = W;
h = H;
cNormal = CNORMAL;
cPressed = CPRESSED;
cHovering = CHOVERING;
cReleased = color(125, 125, 125);
}
Button(boolean visibility, float X, float Y, float W, float H, color CNORMAL, color CPRESSED, color CHOVERING, color CRELEASED) {
visible = visibility;
x = X;
y = Y;
w = W;
h = H;
cNormal = CNORMAL;
cPressed = CPRESSED;
cHovering = CHOVERING;
cReleased = CRELEASED;
}
void Update() {
CheckState();
if (visible) {//WILL NOT RENDER IF NOT VISIBLE
if (pressed && !released) {// IF PRESSED
fill(cPressed);
}
if (released && !pressed) {// IF RELEASED
fill(cReleased);
}
if (hovering && !released && !pressed) {// IF HOVERING
fill(cHovering);
}
if (!hovering && !released && !pressed) {// IF NORMAL/NOT ACTIVE
fill(cNormal);
}
stroke(1);
rect(x, y, w, h);
}
}
void CheckState() {
hovering = false;
released = false;
if (mouseX > x && mouseX < x + w) {
if (mouseY > y && mouseY < y + h) {
hovering = true;
}
}
if (hovering) {
if (mPressed) {
pressed = true;
released = false;
}
if (mClicked) {
released = true;
pressed = false;
}
} else {
pressed = false;
released = false;
hovering = false;
}
}
boolean WasClicked() {
return pressed;
}
}
GGUI :
class GGUI {
int x, y;
boolean visible;
color cBase, cSecondary;
GGUI(int _x, int _y, boolean _visible, color _cBase, color _cSecondary) {
x = _x;
y = _y;
visible = _visible;
cBase = _cBase;
cSecondary = _cSecondary;
}
void Update() {
println("Updated");
}
}
이 아주 간단합니다. 수퍼 클래스에서 생성자를 정의하지 않는 한 Java는 컴파일 타임에 생성자를 만듭니다. 또한 super를 직접 호출하지 않으면 각 확장 클래스에서이 생성자에 대한 호출을 생성합니다. 하지만 수퍼 클래스에 여러 생성자와 기본 생성자가 정의되어 있지 않습니다. 적어도 하나 이상의 슈퍼 생성자를 호출해야하지만 Java가 선택할 수는 없으므로 오류가 발생합니다. 슈퍼 클래스에 빈 생성자를 구현하거나 각 로컬 생성자에서 슈퍼 생성자 중 하나를 호출하십시오. – DiabolicWords