• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

to draw and remove lines on click of mouse

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 changes...rest of the rogram is same as the previous one
class DrawingPanel extends JPanel
{ public DrawingPanel()
{MouseClickListener listener =new MouseClickListener();
addMouseListener(listener);


}

public void paintComponent(Graphics g)
{
super.paintComponent(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);

//g.drawLine(0,0,100,100);
}
}

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();
g.drawLine(0,mouseY,width,mouseY);

}
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic