i'm having the problem of capturing all the coordinate value of pixels while dragging with the mouse using mousedragged event in java

while i'm dragging slowly i'm able to get all the coordinate value of pixels
but when i'm doing it fast i'm getting only one third of the pixel coordinate values
for example if i drag it slowly i'm getting 760 pixel values but when i'm doing it fast i'm getting only 60 pixel coordinate values
please help me

I need all the points because i'm going to use all those points for the signature comparision...

Project Description :
User will put the sign using mouse in log in page, this sign will be compared with the sign which the user already put in sign up page...

I'm going to compare the sign using the pixel values, so by getting all the coordinate values only i can compare the sign...
pls help me...

Here is the coding

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;


class SeparateTask extends Thread
{
    Pan pa;
    public SeparateTask(Pan pa)
    {
        this.pa=pa;
        start();
    }
    public void run()
    {
        while(pa.bin==0)
        {
            try
            {
                sleep(100);
            }
            catch(InterruptedException e)
            {
                System.err.println("Error: " + e.getMessage());
            }
        }
        if(pa.bin==1)
        {
                        Integer elex=(Integer) pa.arrx.get(0); 
            Integer eley=(Integer) pa.arry.get(0);
            pa.arrx1[pa.counter].add(elex);
            pa.arry1[pa.counter].add(eley);
            for(int i=1;i<pa.arrx.size();i++) 
                        {
                pa.condition=0;
                Integer elex2=(Integer) pa.arrx.get(i);
                Integer eley2=(Integer) pa.arry.get(i);
                for(int j=0;j<pa.arrx1[pa.counter].size();j++)
                {
                    Integer elex1=(Integer) pa.arrx1[pa.counter].get(j);
                    Integer eley1=(Integer) pa.arry1[pa.counter].get(j);
                    if(((elex2.equals(elex1)) && (eley2.equals(eley1)))|| ((elex2.equals(new Integer(0))) && (eley2.equals(new Integer(0)))))
                    {
                        pa.arrx1[++pa.counter].add(elex2);
                        pa.arry1[pa.counter].add(eley2);
                        pa.condition=1;
                        System.out.println("counter ="+pa.counter);
                    }       
                }
                if(pa.condition==0)
                {
                    pa.arrx1[pa.counter].add(elex2);
                    pa.arry1[pa.counter].add(eley2);
                }
                        }
            try
            {
                FileWriter fstream1=new FileWriter("out2.txt");
                            BufferedWriter out2=new BufferedWriter(fstream1);
                System.out.println("error");
                out2.write("Total array has been divided is :"+pa.counter);
                out2.newLine();
                out2.newLine();
                for(int i=0;i<=pa.counter;i++)
                {
                                out2.write("Array List "+i);
                    out2.newLine();
                    out2.newLine();
                    for(int j=0;j<pa.arrx1[i].size();j++)
                    {
                        Integer elex3=(Integer) pa.arrx1[i].get(j);
                        Integer eley3=(Integer) pa.arry1[i].get(j);
                        out2.write("pt("+elex3+","+eley3+")");
                        out2.newLine();
                    }
                    out2.newLine();
                }
                out2.close();
                System.out.println("Written in out2.txt");
                System.out.println("No of arrays "+pa.arrx.size());
            }
            catch (Exception e)
            {   
                    System.err.println("Error: " + e.getMessage());
                }
        }
    }
}



class SeparateTask1 extends Thread
{
    Pan pa;
                MouseEvent  e;

    public SeparateTask1(Pan pa,MouseEvent e)
    {
        this.pa=pa;
        this.e=e;
        start();
    }
    public void run()
    {
        int j=e.getX();
        int k=e.getY();
        pa.arrx.add(new Integer(j));
        pa.arry.add(new Integer(k));
    }
}

class SeparateTask3 extends Thread
{
    Pan pa;
    MouseEvent e;
    public SeparateTask3(Pan pa,MouseEvent e)
    {
        this.pa=pa;
        this.e=e;
        start();
    }
    public void run()
    {
        int j=e.getX();
        int k=e.getY();
        Point panelBound = new Point(pa.jp.getLocationOnScreen());
        int px=panelBound.x;
        int py=panelBound.y;
        if(pa.i==1)
        {
            pa.prevpnt.x=px+j;
            pa.prevpnt.y=py+k;
            pa.curpnt.x=px+j;
            pa.curpnt.y=py+k; 
            pa.i=2;
        }   
        else
        {
            pa.prevpnt.x=pa.curpnt.x;
            pa.prevpnt.y=pa.curpnt.y;
            pa.curpnt.x=px+j;
            pa.curpnt.y=py+k;
        }

        pa.repaint();
    }
}

class SeparateTask2 extends Thread
{
    Pan pa;
                MouseEvent  e;

    public SeparateTask2(Pan pa,MouseEvent e)
    {
        this.pa=pa;
        this.e=e;
        start();
    }
    public void run()
    {
        pa.i=1;
        pa.arrx.add(new Integer(0));
        pa.arry.add(new Integer(0));

    }
}

public class Pan extends JFrame implements ActionListener
{
    JPanel jp,jp1;
    JButton btn1,btn2;
    public SeparateTask sp=null;
                public SeparateTask1 sp1=null;
    public SeparateTask2 sp2=null;
    public SeparateTask3 sp3=null;
                ArrayList arrx,arry;
                ArrayList arrx1[],arry1[];
    Point prevpnt,curpnt;
    int i=1,bin=0;

    int condition=0,counter=0;
    Pan()
    {
                    arrx=new ArrayList();
                    arry=new ArrayList();
                    arrx1=new ArrayList[500];
                    arry1=new ArrayList[500];
                    for(int i=0;i<500;i++)
        {
            arrx1[i]=new ArrayList();
            arry1[i]=new ArrayList();
        }
            setLayout(new BorderLayout());
            setPreferredSize(new Dimension(700,700));
        jp=new JPanel();
        jp1=new JPanel();
            jp1.setBorder(BorderFactory.createTitledBorder("JP1"));
        prevpnt=new Point();
        curpnt=new Point();
        btn1=new JButton("click1");
                                btn1.setActionCommand("click1");
        btn2=new JButton("click2");
        btn2.setActionCommand("click2");
        btn1.addActionListener(this);
        btn2.addActionListener(this);
                    jp1.add(btn1);
                    jp1.add(btn2);
                    jp.setPreferredSize(new Dimension(500,500));
        jp.setBorder(BorderFactory.createTitledBorder("JP"));
        jp.setBackground(Color.WHITE);
                    jp.addMouseMotionListener(new MouseMotionAdapter() 
                                {
                            public void mouseDragged(MouseEvent e)
            {
                sp1=new SeparateTask1(Pan.this,e);
                sp3=new SeparateTask3(Pan.this,e);
            }
        });
        jp.addMouseListener(new MouseAdapter()
                    {
                        public void mouseReleased(MouseEvent e) 
                        {
                sp2=new SeparateTask2(Pan.this,e);
            }
        });
        add(jp1,BorderLayout.NORTH);
        add(jp,BorderLayout.SOUTH);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        pack();
    }
     public void actionPerformed(ActionEvent ae)
    {
        if ("click2".equals(ae.getActionCommand()))
        {
            if(sp==null)
                sp=new SeparateTask(Pan.this);
        }
        if ("click1".equals(ae.getActionCommand()))
        {
            try
            {
                            FileWriter fstream = new FileWriter("out.txt");
                        BufferedWriter out1 = new BufferedWriter(fstream);
                    for(int ss=0;ss<arrx.size();ss++)
                {
                                                        Integer oo=(Integer)arrx.get(ss);
                    Integer oa=(Integer)arry.get(ss);
                    out1.write("pt ("+oo+","+oa+")");
                    out1.newLine();
                                        }
                out1.close();
                                        bin=1;
                System.out.println("Written in out.txt ");

            }
            catch (Exception e)
            {
                    System.err.println("Error: " + e.getMessage());
                }
            System.out.println("No of arrays "+arrx.size());
        }
    }
    public void paint(Graphics g)
    {
        g.drawLine(prevpnt.x - getX(), prevpnt.y - getY(), curpnt.x - getX(), curpnt.y - getY() );
    }
    public static void main(String args[])
    {           
                    java.awt.EventQueue.invokeLater(new Runnable() 
        {
            public void run()
            {
                            Pan pa=new Pan();
                pa.setVisible(true);
                Point fr=new Point(pa.getLocationOnScreen());
                Point fr1=new Point(pa.jp.getLocationOnScreen());
                int xx=fr.x;
                int yy=fr.y;
                int zz=pa.getWidth();
                int mm=pa.getHeight();
                int xx1=fr1.x;
                int yy1=fr1.y;
                int zz1=pa.jp.getWidth();
                int mm1=pa.jp.getHeight();
                System.out.println("The actual frame coordinates are ("+xx+","+yy+") and ("+zz+","+mm+")");
                System.out.println("The jp coordinates are ("+xx1+","+yy1+") and ("+zz1+","+mm1+")");
            }
                });
    }
}

Most probably because your screen is updating much slower than you can move the mouse. How often is your screen "redrawing"?

Your code is unreadable because you have not got the right syntax for your code tags, but at a quick scan it looks like this implementation is massively over-complex and thus far too slow for simply logging mouse drag coords.
I think you should strip it back to bare essentials - respond to the drag event and stuff the coords from the event into an array - no new instances/tasks/threads etc - so you can handle events at the highest possible rate. Then then the mouse is released you can take your time doing whatever with the array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.