简体   繁体   中英

How do i make my JRadioButton get a question that i made my code get from the database

im trying to make a game where i get questions from the database and the JRadioButton shows these questions. My problem is, how do i define the JRadioButton?

i can code to get the answers from the database but how do i set up my JRadioButton. Im learning to code any tips would be appreciated

You must know how to fetch data from the database since you say you know how to get the answers from the database, so let's assume you've retrieved a question that you want to apply to your radio button. We'll call it myQuestion .

JRadioButton has a constructor which takes a String and a boolean as arguments, representing the String that the radio button should be displayed, and whether the radio button should be selected.

JRadioButton myRadioButton = new JRadioButton(myQuestion, false);

This gives you an unselected radio button with your question as text.

Now what if you want to change your question at some point? You can use JRadioButton's setText() method to change the radio button's text at any time.

myRadioButton.setText(myNewQuestion);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM