• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ArrayList from Resultset

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic