This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

to draw and remove lines on click of mouse  RSS feed

 
cindrella ss
Greenhorn
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 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);

}
}
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!