I think this is more than just beginner forum stuff (I may be wrong).
First question, i have a paint command within a canvas class that doesn't seem to be recognised on PC's, but it is on macs, is there some different way you have to set it up on PC's? The code is exactly the same, i don't understand this problem.
Second question, are the commands for getting keyboard presses different between the two platforms (mac and pc), they've never worked on pc's.
It would be really helpful if someone could post some code showing how to get keyboard presses to move a picture around the screen on a pc (this would solve all my problems most likely).
This really has me confused
Any suggestions or answers would be very much appreciated.
These are probably not beginner questions, but they're also not intermedite questions: they're Swing/AWT questions -- so I'm moving this to the Swing/AWT forum. You should probably head over to the new copy of this thread and post some code, so people can see what you're doing wrong.
I don't think you should override the update(Graphics) method...
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
author and iconoclast
Well, two separate problems deserve two separate answers.
First, the escape key handler. Components won't receive key events unless they've got the keyboard focus. You can put the keyboard focus on a component using the requestFocusInWindow() method. You'll find that if you add anf.requestFocusInWindow() line at the end of main(), your escape key handler will work.
Second, the canvas painter. The BorderLayout will ask the Canvas for its preferred size, and try to make the height onscreen equal to that value. The default getPreferredSize() method returns Dimension(0, 0). Therefore, the canvas will be zero pixels high, and the AWT is smart enough to never try to paint it. If you override getPreferredSize() in the Canvas subclass and return a java.awt.Dimension with non-zero dimensions, you'll find your paint method is then called.
If this works on a Mac, it's due to undefined behavior, not any official difference between platforms.