Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

Storing data using ActionListener method

Hi

I'm playing a certain structure of clips and calling them from an array.The user has the option to click a button on a clip being played, at which point he/she is taken to another set of clips (All in the same array)

How would I store information about the clips chosen by a user in another array... hmmm and i guess I'd need to assign information to them as well.

Any offers?

0
pigmentarts
Asked:
pigmentarts
  • 11
  • 9
1 Solution
 
aozarovCommented:
add a List (ArrayList or LinkedList) as memeber variable.
each time the user click a button that plays a clip add to the list the clip or the clip information.

>> hmmm and i guess I'd need to assign information to them as well.
Right in addition to the array of clips add an array of the names of the clips.
0
 
pigmentartsAuthor Commented:
where do I write the info about the clips...in here?

array_of_names_of_clips = new ArrayList[] {};

if so, I wanted to set two variables for each clip. As I was hoping to use that data to present back to the user. Is it possible?
0
 
pigmentartsAuthor Commented:
Or I can just name my clips with the information I want, and then just print out to the user those clips he/she selected.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
aozarovCommented:
You add two member variables (in addition to index, and the array of clipse):
private String[] clipNames;
private List pickedClips = new LinkedList();

then at the same place you assigne the clips into the clips array you do:
clipsNames = new String[]{"clip", "clip2"}; // put here the name of any string info for each clip

when the user click (and you change the index) do:
pickedClips.add(clipNames[index])); // add to the picked clips list the name of the selected clip.
0
 
pigmentartsAuthor Commented:
Ok I set that up as you said. But I'm having a problem inputting string info into here.

>>clipsNames = new String[]{"clip", "clip2"};// put here the name of any string info for each clip

0
 
aozarovCommented:
What is the problem?
If you have a memeber vairable:
private String[] clipNames;
then you should be able to do:
clipNames = new String[]{"clip", "clip2"};
0
 
pigmentartsAuthor Commented:
hmmm, not sure why I had that problem before.

ok so say i enter data into here, can I write. ... new String[]{"Well done!! Good choice you picked No5", You also chose No. 14"}

and then I have pickedClips.add(clipNames[index])); in the ActionListener method


Q. When the user gets to the end of the clips and has made the final selection how do I link straight to the pickedClips list.

Can i do it this way:-

else if (index < 8) {
           index = 8;
} else if (index < 22) {
               index=22;
} else if (index < 29) {   <<last selection
               index = println (pickedClips);




0
 
aozarovCommented:
ok so say i enter data into here, can I write. ... new String[]{"Well done!! Good choice you picked No5", You also chose No. 14"}
and then I have pickedClips.add(clipNames[index])); in the ActionListener method
Sure, as long as clipNames have strings as much as clips (so index will not get out of bound).
and change: You also chose No. 14" to "You also chose No. 14"

>> Can i do it this way:-
Yes, though println(System.out.println) will not return a value (just a printout to the string)
0
 
pigmentartsAuthor Commented:
what do you mean will not return a value, what value could it be outputting...data to make a chart or graph??

This is what I have under the ActionEvent method:

pickedClips.add(clipNames[index]);

 if (index < 8) {
           index = 8;
} else if (index < 22) {
               index=22;
} else if (index < 29) {
                 index = println(System.out.println) (pickedClips);  <<how do i add this?
                                                                   
                                                                   
                                                               
0
 
aozarovCommented:
>> index = println(System.out.println) (pickedClips);  <<how do i add this?
What do you want to do?
If you want to display the picks
then do it this way:
System.out.println(pickedClips);
0
 
pigmentartsAuthor Commented:
After the last clip has been selected, from the range 22 to 29 I want to print out the picked clips on the screen.

Using this I get an error  void, required: int

pickedClips.add(clipNames[index]);

 if (index < 8) {
           index = 8;
} else if (index < 22) {
               index=22;
} else if (index < 29) {
                 index = System.out.println(pickedClips);  
0
 
aozarovCommented:
>> I want to print out the picked clips on the screen. (Using this I get an error  void, required: int)
I told you, System.out.println(pickedClips) does not return a value (so you can't assign it to index).
replacing
index = System.out.println(pickedClips);  
with just
System.out.println(pickedClips);  

will add a printout to the console, but I think in your case (GUI application and not console application) you want to add it to your JFrame.
So, add a JLabel to your JFrame (the same style you add your JButton, but without having an ActionListener for it) and then call
jLabel.setText(pickedClips.toString());
Assuming you added a JLabel named jLabel.
0
 
pigmentartsAuthor Commented:
i'm a bit confused with what u mean by jLabel and JFrame

what i have done is to:

Label label = new Label ("testResults") {
};

then under that:

add(label, BorderLayout.CENTER);
Label.setText(pickedCLips.toString());

But there an error with   .setText         non-static method
0
 
pigmentartsAuthor Commented:
I also set the size of the label
0
 
aozarovCommented:
Change (there is no need for the {} in this case):
Label label = new Label ("testResults") {
};
to
Label label = new Label ("testResults");

JLabel is like Label but in the swing world (stick with Label, as you already did, for awt only)

>>add(label, BorderLayout.CENTER);
This should be added when you add the buttons

>> Label.setText(pickedCLips.toString());
label.setText(pickedCLips.toString()); // change L to l and do it in the section "else if (index < 29)..."



0
 
pigmentartsAuthor Commented:
do it in the section "else if (index < 29)..."

Do you mean put it in the final "else if"??  This gives me an inner class error for 'label'

0
 
aozarovCommented:
if (index < 8) {
           index = 8;
} else if (index < 22) {
               index=22;
} else if (index < 29) {
                 label.setText(pickedCLips.toString());
0
 
pigmentartsAuthor Commented:
I still get the inner class error

I created the label under where I created the button and added the label afetr i added the button:

add(button, BL.CENTRE); add(label,.....);

The whole error is local variable label accessed from within inner class; needs to be declared final
0
 
aozarovCommented:
>> The whole error is local variable label accessed from within inner class
Where did you declare label? It should be declared outside of any method (put it after pickedCLips delcaration).
e.g:
pickedCLips declaration
Label label;

and then in your jbInit do:
label = new Label(....); // initialize the label you declared outside
add(label, ...);
0
 
pigmentartsAuthor Commented:
ok...theres no errors..now i have to go through test it    80
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 11
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now