Hello I am trying to write a program where im using an MVC pattern but im having problems with my action listener, i want to when i press the button the action listener picks up that is what a dice object pressed and then call a method in the model which takes a dice object as a parameter. in my viewClass i have this code
the dice creates a single dice object from a class which is called dice.
in my Controller i have the code
in my model i have this method
the reason in the controller i have .getActionCommand().equals("") is because when i press the dice button i dont seem to get anything. i was wondering if there was a way of representing the dice.so i could then pass it to the rollDice method
What is viewClass? Is it a class? This would explain why you are getting this error. (As a side note, you should name it ViewClass instead. The Sun coding conventions suggest that class names start with upper-case; variable and function names should start with lower-case.) If viewClass is a class, then it looks like you need to either change rollDice() to a static method or you need to have a instance of the class in order to call the method on. Without more code, I'm not sure which would be appropriate. Perhaps you can post the portions of code from viewClass that are pertinent here. In particular, the "class viewClass" line (with possible "extends"), the rollDice() method, and declarations for all variables used in rollDice() will help us understand what is going on.
It may have "worked", but you should also consider if that is a good design decision. Typically, making design decisions just to make the code work is a poor choice. Sorry if I seem a little skeptical. I just don't know enough about the code to determine if using a static method is necessarily the best choice to fix your code.
I Understand what you mean, and you've helped me to understand how to deal with that error thank you, I have just one more small question which is probably something stupid. To make my code better in my view class i went from this
this second piece of code compiles but when i try to run it i get
java.lang.IllegalArgumentException: illegal component position at java.awt.Container.addImpl(Unknown Source) at java.awt.Container.add(Unknown Source) at viewClass.initializeComponent(viewClass.java:117) at viewClass.<init>(viewClass.java:72) at runDice.main(runDice.java:19)
does anyone know why?
[ February 24, 2005: Message edited by: Andy Rayner ] [ February 24, 2005: Message edited by: Andy Rayner ]
What's a year in metric? Do you know this metric stuff tiny ad?