That is the correct way to do it.Caglar Gul wrote:
Carey Brown wrote:
That is the correct way to do it.Caglar Gul wrote:
Your code snippet indicates you have an object reference named 'changeState', yet your error message says you have a class named 'True'. Something is amiss. We need to see more of the code.
Paul Clapham wrote:Hi Caglar, welcome to the Ranch!
Those problems, actually, they don't have anything to do with what you're trying to do there. What's going on is this: somehow your braces (those { and } characters which delimit code blocks) have got out of order, and you're trying to put lines of code outside of the class. So you have too many closing braces (the } character) before them.
So what you need to do is go through your code and make sure it's properly indented and the opening and closing braces match up. Get rid of the extras. If you're using an IDE (Eclipse, Netbeans, etc) which can do that for you, then definitely ask it to do that. If not, well, you've got nearly 500 lines of code to go through and clean up. That's really too much code for one class but if you're a beginner then you probably aren't being taught good programming practices yet.
Carey Brown wrote:Can you post the first 100 lines of code, including any package and import statements. Be sure to use Code tags so that we get line numbers.
Where's the class declaration? Where's the imports? Where's the line 34 mentioned in your error message?Caglar Gul wrote:
Carey Brown wrote:Can you post the first 100 lines of code, including any package and import statements. Be sure to use Code tags so that we get line numbers.
I'm not sure anyone will benefit from this... my first 100 lines are full of items being added to the JFrame..
Carey Brown wrote:
Where's the class declaration? Where's the imports? Where's the line 34 mentioned in your error message?Caglar Gul wrote:
Carey Brown wrote:Can you post the first 100 lines of code, including any package and import statements. Be sure to use Code tags so that we get line numbers.
I'm not sure anyone will benefit from this... my first 100 lines are full of items being added to the JFrame..
Carey Brown wrote:
Where's the class declaration? Where's the imports? Where's the line 34 mentioned in your error message?Caglar Gul wrote:
Carey Brown wrote:Can you post the first 100 lines of code, including any package and import statements. Be sure to use Code tags so that we get line numbers.
I'm not sure anyone will benefit from this... my first 100 lines are full of items being added to the JFrame..
That appears to be different from what you first posted, and doesn't appear to contain the code producing the compile‑time error you showed yesterday. We can only help if you post the real code that produces the errors.Caglar Gul wrote:. . . here's the code you're requesting: . . .
Campbell Ritchie wrote:
That appears to be different from what you first posted, and doesn't appear to contain the code producing the compile‑time error you showed yesterday. We can only help if you post the real code that produces the errors.Caglar Gul wrote:. . . here's the code you're requesting: . . .
I can, I am afraid, see lots more about your current code.
Don't extend classes like JComponent. You may need to extend JPanel for displaying the game, but it will probably only need its paintComponent() method overriding. Give paintComponent() protected access, and use the following as its first line:- super.paintComponent(g); That will remove the previous image from the panel. Why are those int fields public? I don't like the notion of adding this to a frame. I think you should be adding Panels, as mentioned above. There is something not right about methods to draw a player object. That method belongs in the Player class. The same applies to other sorts of Item. The checkMove method is confusing; there must be a simpler way to do that. Start getting suspicious whenever you see instanceof. I think the individual objects in the game should take care of their own code, which doesn't appear to be happening at the moment.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |