Computer Science Canada Adding a selected Index from a JList box using the JButton. I'm so confused. :S |
Author: | antitru5t [ Wed Mar 25, 2009 1:30 am ] | ||||
Post subject: | Adding a selected Index from a JList box using the JButton. I'm so confused. :S | ||||
Hi everyone, I'm brutally stuck on JAVA. My teacher has mentioned about retrieving from vectors. But, I seriously do not get it at all. His assignment is painstakingly hard. I need to get my Movie Titles, number of copies. I want to implement (Combo Box), type of movie, DVD or Blu ray and Pricing when I press the JButton "Buy". The main idea is that I want to get things to show up. I have been using the getSelectedIndex() feature and I've been getting values like -1. Eek?!? :S How am I supposed to use vectors to get getSelectedIndex()? Here is my coding so far, if you want to look at it and try to fix it. For a visual image of the assignment, here it is. URL: [url] http://www.scribd.com/doc/13082448/CSIS1275Assign3w2009 [/url] MOVIEBUY.JAVA
MOVIEINFO.JAVA
If you can take a look at the code and try to help me ASAP, that would be great. Thanks! ![]() - Nathe |
Author: | DemonWasp [ Wed Mar 25, 2009 7:31 am ] |
Post subject: | RE:Adding a selected Index from a JList box using the JButton. I\'m so confused. :S |
You could try using the JList.getSelectedIndicies() method, which will return ALL the selections made: http://java.sun.com/javase/6/docs/api/javax/swing/JList.html#getSelectedIndices() . |
Author: | antitru5t [ Wed Mar 25, 2009 3:01 pm ] | ||
Post subject: | Re: Adding a selected Index from a JList box using the JButton. I'm so confused. :S | ||
Hello DemonWasp. I am still stuck at the moment. I need the getSelectedValue and not the getSelectedIndex or getSelectedIndices.. .. hmm Here is what I have attempted so far and this is what I have. I think that the answer is close, but I'm not there yet because I can't get it to display on the JList listarea box.
Please help me ASAP. - Nathe |
Author: | antitru5t [ Wed Mar 25, 2009 3:08 pm ] |
Post subject: | Re: Adding a selected Index from a JList box using the JButton. I'm so confused. :S |
I used getSelectedIndices and got a value of [I@19ee1ac, which means that I have something at least. . . .. How do I convert this to a String? |
Author: | DemonWasp [ Wed Mar 25, 2009 5:32 pm ] |
Post subject: | RE:Adding a selected Index from a JList box using the JButton. I\'m so confused. :S |
getSelectedIndices() returns an array of integers - int[] . You should be able to determine which movies are selected from there. |
Author: | antitru5t [ Wed Mar 25, 2009 9:21 pm ] | ||
Post subject: | This is what I have attempted. Can you help me fix it? | ||
I stil have zero results. So far, this is my coding. If you could help me, that would be great.
|
Author: | antitru5t [ Wed Mar 25, 2009 9:24 pm ] |
Post subject: | Re: Adding a selected Index from a JList box using the JButton. I'm so confused. :S |
In other words, my coding does not work. |
Author: | DemonWasp [ Thu Mar 26, 2009 1:28 am ] | ||
Post subject: | RE:Adding a selected Index from a JList box using the JButton. I\'m so confused. :S | ||
Trying to add an int[] to an array isn't going to work. Replace that line with something like this:
|
Author: | antitru5t [ Thu Mar 26, 2009 1:34 am ] |
Post subject: | Re: Adding a selected Index from a JList box using the JButton. I'm so confused. :S |
I get an error of : MovieBuy.java:211: incompatible types found : java.lang.Object[] required: int[] int[] selected = listbox01.getSelectedValues(); How should I fix this? |
Author: | DemonWasp [ Thu Mar 26, 2009 7:55 am ] | ||||
Post subject: | RE:Adding a selected Index from a JList box using the JButton. I\'m so confused. :S | ||||
Ugh. Okay, actually looked at your code; turns out you've set your list box so it can't even select more than one thing at a time. You should be able to use getSelectedValue() to get an object representing what you put into the JList. I'm not quite sure what you put in to that list, but if it was a String, then you can change it to a string by casting it to a String:
Side note: Don't use Vector unless your program is multithreaded (it isn't). Use List instead:
|