joptionpane - how to properly use the radio buttons in java -


i have problem following code. created dice program , created radio buttons. want radio buttons following: when selected, want roll dice number button has; problem once click on it, gives me results. want select , click roll button give me results.

private void jbutton1actionperformed(java.awt.event.actionevent evt) {      random dice = new random ();     int number;      (int counter=1; counter<=5;counter++) {         number= 1+dice.nextint(6);         joptionpane.showmessagedialog(null, number);     } }                                          private void jradiobutton1actionperformed(java.awt.event.actionevent evt) {     random dice = new random ();     int number = 0;      (int counter=1; counter<=5;counter++)          number= 4+dice.nextint(4);     joptionpane.showmessagedialog(null, number); } 

  • create roll button.

  • add actionlistener button.

  • in actionlistener fetch selected value radiobuttons , roll "dice".

you not need listener on radiobuttons this.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -