i'm trying make ranking using variables in java.
i've created gui (using netbeans) 8 buttons, each 1 adds 1 different variable. goal create ranking clicked buttons.
for example:
if button1 clicked 10 times, variable button1 gets first place.
if button2 clicked 8 times, variable button2 gets second place, , on.
then when click on button "calculate" name of clicked buttons appear in text field.
what done:
i have declared 8 variables classes atributes, each 1 int called buttonx (x being number of button).
each button adds 1 own variable. (button1 = button1 + 1;
)
now need calculate the biggest values , rank them, put it's names on text fields using command:jtextfield3.settext(variable_name_here);
i have no idea do, except check if every value bigger other 1 each place.
extra detail
i want first letter of each variable in capital letter.
can guys give help/insight/ideas? thanks!
you need not have individual variables... can achieve them using map below
your actionperformed() of 8 buttons can below
private void actionperformed(actionevent ae) { jbutton b = (jbutton) ae.getsource(); int clickcount = map.get(b.gettext()); map.put(b.gettext(), clickcount + 1); //iterate map , key maximum value , show in jtextfield3 }
Comments
Post a Comment