• Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayList from Resultset

 
kaut raut
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi friends

I have data in Resultset and wants to display it in the radio buttons and jlabel after storing it in Arraylist. My Arraylist will be:

List<Object,Object> list=new ArrayList<Object,Object>();
One Object contains questions like: Who is Indian test cricket team captain?
Second Object contain its answers like: V. Kohli. 

These types of Q/A are about 40 stored in ArrayList from Resultset.

I have a GUI where there is a JLabel and I need to assign Questions to it (Ist object of ArrayList). There is a radiobutton where I have to assign the Answer(from second Object).
Please some body help me in slightly detail how can I populate these components from the ArrayList.

Second and important query is: When user slect radiobutton, he will click a button to move to next question and answer so the ArrayList should be incremented, so how can I do it?

Very thanks to every one.
 
Tim Cooke
Sheriff
Posts: 3291
153
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, and welcome to the Ranch!

I'm guessing you haven't actually compiled any of this? Because if you had the compiler would have informed you that this is the incorrect syntax for declaring and creating a List.

I expect you're thinking of a Map rather than a List?
 
Winston Gutkowski
Bartender
Posts: 10571
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kumaraut rohitaut wrote: I have data in Resultset and wants to display it in the radio buttons and jlabel after storing it in Arraylist. My Arraylist will be:
List<Object,Object> list=new ArrayList<Object,Object>();
One Object contains questions like: Who is Indian test cricket team captain?
Second Object contain its answers like: V. Kohli.

Question 1: Are those things simply "objects"? They look more like Strings to me.
Question 2: How many "answers" does a question have?
Question 3: How do you know that the "answer" is correct? (Hint: what if I answer "Virat Kohli", rather than "V. Kohli"?)

Winston
 
kaut raut
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually these are objects like these data come from Protege OWL file.

Second, every question will have one answer and two choices but for now I am just using Questions and Answers (For choices may be I will have another ArrayList where I will have Question object and Choices object).
So two objects for now, one contains questions and second answers.
How to populate JLabel from Question Object and radio button from Answer object? I can display both objects values in console but problem is how to use it in SWING components.
 
Paul Clapham
Sheriff
Posts: 21869
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm somewhat confused, because you'd use an ArrayList when you were expecting you might have to store more than one object. On the other hand when you use a JLabel there's only one object. So your design isn't all that obvious.

Anyway to "populate" a JLabel, you would simply call its setText() method, passing the String value which you want to see visible in the JLabel. But I don't think that was the source of your question, was it? Perhaps you could clarify, with more detail about what you can and can't do.
 
kaut raut
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

My question is I have two Strings in Arraylist i-e Question and its Answer. I want to assign these values(populate) Jlabel and JRadio Button. Like first question in Arraylist will be assigned to a label and first answer to Radio button. Then when user click next button, second question will be assigned to label and second answer to radiobutton and so on. I have 40 questions and answers in my arraylist
 
Paul Clapham
Sheriff
Posts: 21869
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you have two Strings in an ArrayList, and you want to know how to get them back out? To get the first one out you use the get(0) method and to get the second one out you use the get(1) method.

But why did you put them into a list in the first place? Why not just use two String objects?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!