My program draws a line along the path of the mouse pointer when the mouse is dragged.
When I move the mouse slowly the line appears continuous. But When I move the mouse fast, the line(straight or curved)appears broken. I want the line to be continuous at any mouse speed, as one can see in Microsoft Paint App.
Can anyone help
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
class Z_MouseMotionListenerExample1 extends JFrame implements MouseMotionListener{
private Vector v;
static BufferedImage[] image;
Z_MouseMotionListenerExample1(){
v = new Vector();
addMouseMotionListener(this);
setSize(300,300);
setLayout(null);
setVisible(true);
}
public void mouseDragged(MouseEvent e) {
Graphics g=getGraphics();
g.setColor(Color.BLUE);
//g.fillOval(e.getX(),e.getY(),1,1);
v.add(e.getPoint());
repaint(); // calling the repaint() method
}
public void paint(Graphics g) { // paint() method
super.paint(g); // calling the paint method present in the super class or parent class
g.setColor(Color.red); // fixing the outline colour of the ovel as white
Enumeration e = v.elements(); // creating the object to the enumeration class
while(e.hasMoreElements()) {
Point point = (Point)(e.nextElement());
g.drawImage(image[1],point.x, point.y, this );
//g.drawOval(point.x-20, point.y-20, 40, 40);
}
}
public void mouseMoved(MouseEvent e) {}
public static void main(String[] args) {
try {
image = new BufferedImage[3];
File input = new File("Z_DisplayedPic3.png");
image[1] = ImageIO.read(input);
}
catch (IOException ie) {
System.out.println("Error:"+ie.getMessage());
}
new Z_MouseMotionListenerExample1();
}
}