java - paintComponent is stressing me out; Hangman programming project -


ok, have programming project due in few hours , close finished. can paint parts of hangman @ time, dependent on amount of incorrect tries user. teacher of programming class requires creation of hangman drawing in different class. problem i'm having sending on number of incorrect tries class paintcomponent.

if(updatedchallenge == challenge)     {         incorrecttries += 1;     }     challenge = updatedchallenge; 

the challenge == updated challenge refers hidden word before user's guess , hidden word after user's guess. if still equal means user made incorrect choice. 1 gets added total number of incorrect tries.

here other class:

class hangmanpicture extends jpanel {     public void paintcomponent(graphics g)     {         super.paintcomponent(g);          g.setcolor(color.black);         g.drawline(250, 300, 300, 300); //platform          g.drawline(275, 300, 275, 200); //pole          g.setcolor(color.yellow);         g.drawline(275, 200, 350, 200); //rope          g.drawline(350, 200, 350, 225); //noose          g.setcolor(color.cyan);         g.drawoval(350, 225, 15, 15); //head          g.drawline(350, 230, 350, 260); //torso          g.drawline(350, 240, 340, 230); //left arm          g.drawline(350, 240, 360, 230); // right arm          g.drawline(350, 260, 330, 280); // left leg          g.drawline(350, 260, 390, 280); // right leg     } } 

i want put if statement each body part gets added after each incorrect try, requires me send number of incorrect tries class. whenever try send number, somehow interferes paintcomponent

any appreciated, i'm desperate. in advanced!

since extending jpanel class. can add methods , fields class , use them hangmanpicture being used.

hangmanpicture panel = new hangmanpicture();   ...   if(updatedchallenge == challenge)   {       panel.addincorrectattempt();   }   challenge = updatedchallenge;  

class hangmanpicture extends jpanel { private int incorrectattempts = 0;

// add 1 counter public void addincorrectattempt(){   incorrectattempte++; }  // how many times player entered incorrect number public int getincorrectattempts(){   return incorrectattempts; } public void paintcomponent(graphics g) {     super.paintcomponent(g);      g.setcolor(color.black);     if( incorrectattempts >= 1 ){       g.drawline(250, 300, 300, 300); //platform     }      if( incorrectattempts >= 2 ){       g.drawline(275, 300, 275, 200); //pole     } } 

}


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -