java - How to use a variable in two classes? -
i need able see in of these classes if variable true.
public void performaction() { if (door.intersects(hero)) { system.out.println("actionperformed!"); herox = 0; heroy = 0; inside = true; } } this every time press space , want draw inside of house. in main class draw want like:
public void paintcomponent(graphics g) { if (!inside) { g.drawimage(background, 0, 0, null); achilles.draw(g); }else if (inside) { g.drawimage(houseinside, 0, 0, null); } } i don't know how change "inside" in hero class , use in main class. have tried many things , don't know do.
inside property of hero object, so, if property public, can access heroname.inside
if property private (which should be), have use public access function inside hero class, such hero.isinside, , set setting function hero.setinside , hero.setoutside.
this called "getters , setters"
Comments
Post a Comment