Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
87 views
in Technique[技术] by (71.8m points)

java - 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

question from:https://stackoverflow.com/questions/65924759/how-do-i-make-my-jradiobutton-get-a-question-that-i-made-my-code-get-from-the-da

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...