• Post Reply Bookmark Topic Watch Topic
  • New Topic

Make a array from some elements of another large array?  RSS feed

 
Niklas Karlsson
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
my goal is:
When I insert: title, category, year, artist in 4 Strings
And when I press "enter" i put those 4 in a array "large", and then when I can start a new music insert with 4 new string elements and add those in the large array..
So:
I have an array "large" with the length 19 (or so..)(max ~100 or so)

Then I what to:
get,in a new array "title",the elements:
0,4,8,12,16 (from the large array
) and put them in a scrollable list. And when I select one element in the title array I then whant to get 3 remaining elements from this. And put it in a array called selection.

So the "large" and the "title" arrays must be dynamically sizes... or be copied to a larger sized..
1 can it be done with arrays?
2 how do dynamically change the size of for example the array "title"?
3 how do I receive the elements 0,4,8,12,16 and so on, (to (
large.length-3) and add it to the title array?

Best regards to you all!
/ Niklas, Sweden
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frankly speaking I am not sure I understand what you mean by 'large'. Also why are you using an array? The recommended way would be to use a List instead so you need not bother about the size.

Coming back to your problem. Looks like all the fields you mentioned are attributes for a song. If so, I would suggest making a custom Song class which encapsulates these fields and then out the songs in your collection.
What is your visual list which the user selects? Swing list? HTML list? If it is swing, you can provide a custom renderer which will display all required attributes, but work (can be selected) as one integral unit
 
Niklas Karlsson
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
interesting, THANK you!

so I make a Song-object with ( title, category, year, artist)
for each "Song".
(for example 5 music objects),
--- "problem 1":
I have never had (sadly) understand how I make a new object in java "multiply"
of course i understand the easy way:
song song1= new song(); //:-)
but how do I make a object like: "for user type in add new song then make a new song-object.."??


then I have one "large-list" that I populate with: all my 5 objects..
--- "problem 2":
how do I "find" the objects if i dont know the names?? (probably solve this if i have the answer of problem 1 :-) )

then I make a "title-list" and add 0,4,8,12,16... to this list.
--- "problem 3": similar to question 2, but the, is this a good way to do it?:


//or similar.. :-)
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Niklas Karlsson wrote:so I make a Song-object with ( title, category, year, artist)
but how do I make a object like: "for user type in add new song then make a new song-object.."??

You practically wrote it yourself

You'll need another class with a main() method to do the job of getting user input and creating (hint) new songs.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need a Main (or someother named) class with a main() method.
  • Prompt user for title, category, year, and artist.
  • Create a new Song with those attributes.
  • Add the song to a list.


  • For the list, use something like this
     
    Carey Brown
    Saloon Keeper
    Posts: 3329
    46
    Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If you are developing a Swing or Web interface I suggest you temporarily set that aside and concentrate on the business logic and put a simple text user interface in front of it for debugging purposes.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!