i am trying to build a PaintBrush with Swings. I wanted to do free hand drawing on one of the JPanels, so i overridded it's PaintComponent, and drew some thing, it is fine. But i don't get any background, i needed white background, so i called the super.paintComponent(g) inside paintComponent(), now i am able to get the background but everytime my repaint() is called on mouseDragged event, i lose my previous drawing on the JPanel. Is there any way by which i can get a background color, and also my previous drawing is not lost?
Any help would be appreciated.Thanks
JPanel paintComponent()
public void paintComponent(Graphics g) {
// super.paintComponent(g);
g.setColor(Color.red);
g.fillOval(xpos, ypos, 5, 5);
}
mouseDragged()
public void mouseDragged(MouseEvent arg0) {
xpos= arg0.getX();
ypos= arg0.getY();
repaint();
}