This is a little confusing, but...
Icon
declares paintIcon
as taking four parameters...
Component
Graphics
int x
int y
The is a reference to some component, presumably the one from which the Graphics
context is associated with, as it's likely the the Component
will be used as an ImageObsever
to monitor changes to the icon when it needs to be updated and may provide other useful information
The Graphics
context is actual place (the graphics output) where the image is to be painted.
Now, having said all that, in order to paint the icon successfully, you will need some kind of reference of some Graphics
context. This can be obtained by extending a component (like JPanel
), overriding it's paintComponent
method. This will give you access to a Graphics
context which can used to paint stuff in this paint cycle. Never maintain a reference to a Graphics
context you did not create yourself.
Then you would call paintIcon
passing a reference to the component and the Graphics
context.
Take a look at Performing Custom Painting, Painting in AWT and Swing and 2D Graphics
Having said all that, I think you will the use of BufferedImage
s (or Image
) simpler then Icon
. Take a look at Reading/Loading an Image for more details
As to your second question. No, you won't have the same issues, you'll have entirly brand new ones