Is there any way to easily delete an ImageIcon completely from the screen? I can't find one anywhere.
ImageIcon image = new ImageIcon("candle.gif");
image.paintIcon(this, g, 150, 80)
开发者_C百科
For example, if I wanted to get rid of "image" later on when a button is pressed, what would be the appropriate code? (Not for the button, I know how to do that).
Don't reinvent the wheel. The easiest way to paint an Icon is to use a JLabel. The code would be something like:
ImageIcon icon = new ImageIcon(...);
JLabel label = new JLabel( icon );
panel.add( label );
If you don't want to display the icon anymore then in the ActionListener of your button you simple do:
label.setIcon( null );
精彩评论