Hi guys,
Here is my code:
public class drawing extends Canvas implements MouseListener, MouseMotionListener { private int x, y; public drawing() { setBackground(Color.WHITE); addMouseListener(this); addMouseMotionListener(this); } public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setColor(Color.BLACK); g2.setStroke(new BasicStroke(1.5f)); g2.drawLine(x, y, x, y); } public void mouseClicked(MouseEvent e) {} public void mousePressed(MouseEvent e) { x = e.getX(); y = e.getY(); paint(this.getGraphics()); } public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mouseDragged(MouseEvent e) { x = e.getX(); y = e.getY(); paint(this.getGraphics()); } public void mouseMoved(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} }
I would like to draw with Pencil and the line should be continuous. But when I use this code, fastly motion mouse cause something like that:
obrazek.jpg
How can I resolve it?
Thanks for your responses!