【发布时间】:2021-10-08 23:02:24
【问题描述】:
我只是无法让我的代码工作。它使按钮,但它不起作用。那么你能帮我解决这个问题吗?
它使文本正常,按钮也显示出来。但它不起作用,我也尝试了不同的功能,如background(10) 等。
Button login1;
boolean clicked = false;
void setup() {
fullScreen();
loginPage();
}
void draw() {
if (login1.isClicked()) {
print("AAAA");
}
login1.update();
login1.render();
}
void loginPage() {
background(27, 50, 131);
textSize(70);
fill(255);
text("System Statku Organizacji 587 'Aurora'", 600, 150);
login1 = new Button(100,50,400,200,"Zaloguj sie",64, 136, 253,255,255,255);
}
class Button {
boolean Pressed = false;
boolean Clicked = false;
PVector Pos = new PVector(0,0);
float Width;
float Height;
color Colour;
color textColour;
String Text;
Button(int x, int y, float w, float h, String t, int r, int g, int b, int tr, int tg, int tb) {
Pos.x = x;
Pos.y = y;
Width = w;
Height = h;
Text = t;
Colour = color(r,g,b);
textColour = color(tr,tg,tb);
}
void update() {
if (mousePressed == true && mouseButton == LEFT && Pressed == false) {
Pressed = true;
if (mouseX >= Pos.x && mouseX <= Pos.x+Width && mouseY >= Pos.y && mouseY <= Pos.y+Height) {
}
} else {
Clicked = false;
Pressed = false;
}
}
void render() {
noStroke();
fill(Colour);
rect(Pos.x,Pos.y,Width,Height);
fill(textColour);
textAlign(CENTER,CENTER);
text(Text,Pos.x+(Width/2),Pos.y+(Height/2));
}
boolean isClicked() {
return(Clicked);
}
}
【问题讨论】:
标签: processing