We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, i don't really know how to ask this on google :
I have multiple page (each page is a class and have one instance) on my application and every time i change the page where i am, i reset my arrayList where is stock all my Button
In each button i want to acces to the variable focus (if one button is focus other are unfocus)
for(int i = 0; i < button.size(); i++) button.get(i).focus = false;
i got the error : "the name "button" cannot be recognized"
i search a code like :
for(int i = 0; i < this.parent.size(); i++) this.parent.get(i).focus = false;
here parent is not a class name but the arrayList.
I don't know if i was clear, i'm newbie and my english is not really good.
Answers
Your question is not clear. Post your entire code, formatted correctly.
You said:
and then:
... Button != button. Is your problem capitalization of the variable name? Can't tell without seeing your code..
buttons with s maybe...?
Sorry, but i can't post the entire code : i have 600 ligne in 4 page This first part is where i have my class
class Input { boolean hover, activ, focus; float posX, posY; float sizeX, sizeY; String label; } class Button extends Input{ Button(String l) { posX = 0; posY = 0; sizeX = 230; sizeY = 75; label = l; } boolean interact() { float screenX = screenX(posX, posY); float screenY = screenY(posX, posY); if(mouseX > screenX-sizeX/2 && mouseX < screenX+sizeX/2 && mouseY > screenY-sizeY/2 && mouseY < screenY+sizeY/2 && !mousePressed) hover = true; if(mouseX < screenX-sizeX/2 || mouseX > screenX+sizeX/2 || mouseY < screenY-sizeY/2 || mouseY > screenY+sizeY/2) hover = false; if(hover && mousePressed) activ = true; if(activ && !mousePressed) { for(int i = 0; i < button.size(); i++) button.get(i).focus = false; //<== The issue is here : if i click on the button i turn for all focus to false and i turn the focus of this to true focus = true; } if(!hover || !mousePressed) activ = false; return focus; } }</pre> This second part is where i use my class class Menu extends Page { ArrayList button; Menu() { button = new ArrayList(); } void setup() { if(user.pseudo == null) button.add(new Button(350, "Se connecter")); else button.add(new Button(350, "Bonjour, "+user.pseudo)); button.add(new Button(350, "Jouer")); button.add(new Button(350, "Option")); button.add(new Button(350, "Créer une carte")); if(user.pseudo == null) button.add(new Button(350, "Quitter")); else button.add(new Button(350, "Se déconnecter")); } void draw() { colors.fillInput(#000000, #303030, #00FFFF, #00C0C0); colors.strokeInput(#FFFFFF, #00FFFF, #000000, #000000); pushMatrix(); int nbrBtn = 5; translate(0, -40*(nbrBtn-1)); button.get(0).draw(); translate(0, 80); button.get(1).draw(); translate(0, 80); button.get(2).draw(); translate(0, 80); button.get(3).draw(); translate(0, 80); button.get(4).draw(); popMatrix(); } void interact() { pushMatrix(); int nbrBtn = 5; translate(0, -40*(nbrBtn-1)); if (user.pseudo == null) { if(button.get(0).interact()) { login = new Login(); login.setup(); nPage = 1; } } translate(0, 80); button.get(1).interact(); translate(0, 80); button.get(2).interact(); translate(0, 80); button.get(3).interact(); translate(0, 80); if(user.pseudo == null) {if(button.get(4).interact()) exit();} else if(button.get(4).interact()) user.disconnect(); popMatrix(); }This third part is where i create and call my Page "menu"
Menu menu = new Menu(); void draw() { menu.interact(); menu.process(); menu.draw(); }I think i give all you need.
The question was how too find the container of an arrayList... The answer is : we can't.
Thx for the time you give me.