Is it possible to re-paint an applet without losing its previous contents? I was just trying to make a program which allows users to draw lines, Rectangle etc. using mouse.
Two possible solutions:
getGraphics()
, and then draw the BufferedImage in your JPanel's paintComponent(Graphics g)
method. OrArrayList
place your mouse points into the List, and then in the JPanel's paintComponent(Graphics g)
method, iterate through the List with a for loop, drawing all the points, or sometimes better -- lines that connect the contiguous points.Other important suggestions:
paintComponent(Graphics g)
method.paintComponent(Graphics g)
method override.