首先让我说这是我第一次在Stackoverflow上发帖,因为我的大部分问题已经得到了这个伟大社区的回答。
我正在尝试创建一个非常简单的程序,在该程序中选择按钮并根据按钮保存字符串。
我可以选择GUI1上的按钮,然后显示我的GUI2,但我在GUI1中创建的按钮仍在后台仍然启用。
我想删除它们或完全禁用它们,以便我没有按钮重叠。
Button want;
Button dwant;
Button eat;
Button sleep;
Button play;
Button read;
Button swim;
boolean showGUI1 = true;
boolean showGUI2 = false;
color bgCol = color(255);
void setup()
{
size(550, 900);
want = new Button("Want",140,300,250,150);
dwant = new Button("Dont Want",140,590,250,150);
eat = new Button("Eat",140,300,200,100);
sleep = new Button("Sleep",140,400,200,100);
play = new Button("Play",140,500,200,100);
read = new Button("Read",140,600,200,100);
swim = new Button("Swim",140,700,200,100);
}
void draw()
{
background(bgCol);
if (showGUI1)
{
want.display();
dwant.display();
}
if (showGUI2)
{
eat.display();
sleep.display();
play.display();
read.display();
swim.display();
}
}
void mouseReleased()
{
if(want.mouseReleased())
{
bgCol = color(255,0,0);
choice= "Want";
showGUI1 = false;
showGUI2 = true;
}
if(dwant.mouseReleased())
{
bgCol = color(0,255,0);
choice= "Dont Want";
showGUI1 = false;
showGUI2 = true;
}
//action GUI2 showing
if(eat.mouseReleased())
{
action= "Eat";
showGUI2 = false;
}
if(sleep.mouseReleased())
{
action= "Sleep";
showGUI2 = false;
}
if(play.mouseReleased())
{
action= "Play";
showGUI2 = false;
}
if(read.mouseReleased())
{
action= "Read";
showGUI2 = false;
}
if(swim.mouseReleased())
{
action= "Swim";
showGUI2 = false;
}
我的按钮我使用以下代码
Button(String nm, int x, int y, int w, int h)
{
super(nm, x, y, w, h);
}
void display()
{
if(currentImage != null)
{
float imgWidth = (extents.y*currentImage.width)/currentImage.height;
pushStyle();
imageMode(CORNER);
tint(imageTint);
image(currentImage, pos.x, pos.y, imgWidth, extents.y);
stroke(bgColor);
noFill();
rect(pos.x, pos.y, imgWidth, extents.y);
noTint();
popStyle();
}
else
{
pushStyle();
stroke(lineColor);
fill(bgColor);
rect(pos.x, pos.y, extents.x, extents.y);
fill(lineColor);
textAlign(CENTER, CENTER);
text(name, pos.x + 0.5*extents.x, pos.y + 0.5* extents.y);
popStyle();
}
}
我也可以将ControlP5库用于按钮,但即便如此,我也不知道如何激活“controlP5.Controller:Button hide()”(隐藏功能)
如果有人可以发光,那将非常感激
答案 0 :(得分:0)
好吧,为了删除它们,您可以使用button.setVisibility(View.GONE),它将删除它们并且它们不会占用任何布局空间。但是,如果要隐藏它们但保留它们占用的空间,请使用button.setVisibility(View.INVISIBLE)。
如果你想在另一边看到它们,但只是禁用它们,请使用button.setEnabled(false)。
希望有所帮助