animTableComes carrying the keys "Cat" ect... as you see where i am creating attrib arrays. Each key value has another hashtable which stores a string key for the animation and the values are image sequences. Here is my error:

This code contains an attempt to convert animTable to an ImageSequence. As I understand it, you want to convert the contents of the hashtable to ImageSequences. Take a look at the first parenthesized expression:

1

(ImageSequence)animTable

This is analogous to:

1

(int)x

That is, it converts animTable to an ImageSequence. If you want to convert the result of "animTable.get(startingCharacter)" to an ImageSequence, you need to form it thusly

Why are you asking me? It's your code. Seriously, if you don't know what is in which table, then you probably need to refactor your solution. In my experience, the use of cascading hashtables like this is usually a sign of poorly designed object interactions. I don't mean to be overly harsh here, but rather I'm trying to steer you towards a better solution.

For example, why use a hashtable to store four animations and key them as "north", "south", etc.? How about introducing an interface instead:

Now, write the rest of your code to refer to CharacterAnimation, and you have reduced the coupling between components. Interfaces allow you to add a layer of abstraction such that you can replace the implementation without changing the interface.

The table maps strings to jbuttons, and so if I want to get at the JButton mapped by "foo", I must cast the result of the expression t.get("foo"). I could use more parentheses:

1

p.add( (JButton) (t.get("foo") );

Maybe that approach makes more sense to you, but it is semantically equivalent to the other block of code.

Quote

There are way too many ( and ) in there.

Nope. Unless I am misunderstanding the nature of your code, my previous example has the minimal number of parentheses.

Quote

What was this method you suggested I use instead of this ? Also whats wrong with the current code... again.

Recommendation #1: Refactor the code. Rethink your object model. Focus on the dynamic model: what objects are responsible for processing what messages? Test each class independently, then bring them together.orRecommendation #2: Use the code I already provided.

What is wrong with your current code is that you were casting the table itself to a new class, not the result of the "get" expression. It would be as if I used my jbutton example above and tried to do this:

1

((JButton)t).get("foo")

The key is the first part: ((JButton)t). This casts the table into a JButton, or attempts to. It cannot be done, since these two types are -- to use the phrase the compiler helpfully gave you -- inconvertible.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org