Java - clear graphics

13lade619

is now a game developer :)
Reaction score
400
i'm using transparent images (.png) to paint my JPanel.

problem is with the artifacts.. how do i clear the Graphics to that it will be empty agaiN?

Code:
    protected void paintComponent(Graphics g)
    {
        g.drawImage(currentimage,0,0,this);
    }

    this.addMouseListener(new MouseAdapter()
            {
            public void mouseEntered(MouseEvent e) {
                currentimage = roll;
                repaint();
            }
            public void mouseExited(MouseEvent e) {
                currentimage = base;
                repaint();
            }
            public void mousePressed(MouseEvent e) {
                //currentimage = roll;
                //repaint();
            }
            public void mouseReleased(MouseEvent e) {
                //currentimage = base;
                //repaint();
            }
        });
 

The Helper

Necromancy Power over 9000
Staff member
Reaction score
1,688
Solved by himself! Thanks for posting your solution it is still being used 12 years later as I am seeing this post in the stats. Pretty popular these days for some reason.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top