Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

to draw and remove lines on click of mouse

cindrella ss
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suppose i want to remove a line already made by previous program on a mouse event and also draw a new line at the new position where i click mouse....i added a mouse event listener class in the imagepanel but it is not working....what to do...???
i m posting the part of code where i made of the rogram is same as the previous one
class DrawingPanel extends JPanel
{ public DrawingPanel()
{MouseClickListener listener =new MouseClickListener();


public void paintComponent(Graphics g)
if (img!=null)
// resizing the JPanel to the pic size
int width = img.getWidth(this);
int height = img.getHeight(this);
imagepanel.setPreferredSize(new Dimension(width,height));
// printing the image on the panel
g.drawImage(img, 0, 0, this);


private class MouseClickListener extends MouseAdapter
{ public void MouseClicked(MouseEvent e)
{int mouseX=e.getX();
int mouseY=e.getY();
int width = img.getWidth(imagepanel);
Graphics g=imagepanel.getGraphics();

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic