can not display a line at exact location
I made a frame in which I added mouselistener which stores the points (i.e. by e.getX() and getY() functions).Now in the paint when i call g.drawLine() with these cordinates the line is displayed but not accurately as in if the mouse pointer clickes at point x,y=(85,85) then the printed point or the startin point is (57,57)
Why so...?
Is it due to the frame? should i implement it in Canvas class?
Kindly help
[436 byte] By [
catchmea] at [2007-11-26 20:27:47]

# 2
public class check
{
public static int height=650,width=600;
public static void main(String args[])
{
myframe f=new myframe(height,width);
f.setSize(height,width);
f.show();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}//end of main
}//end of class check
class lines
{
int sx,sy,tx,ty;
public lines()
{
sx=sy=tx=ty=-1;
}
}
class myframe extends JFrame
{
public int height,width;
public int n=1;//no of inputs
public int o=1;//no of outputs
JPopupMenu popup;
boolean clicked=false;
int alen=-1;
Image an;
int i,x,y;
int sx,sy,tx,ty;
lines line[]=new lines[40];
int linelength=-1;
andgate and[]=new andgate[10];
public myframe(int h,int w)
{
this.height=h;
this.width=w;
getContentPane().addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
repaint();
if(clicked==false)//1st click
{
linelength++;
line[linelength].sx=e.getX();
line[linelength].sy=e.getY();
clicked=true;//1 click has happened
}
else
{//2nd click thus target
line[linelength].tx=e.getX();
line[linelength].ty=e.getY();
clicked=false;//2 click has happened
}
System.out.println("in center clkd"+e.getX()+" "+e.getY());
repaint();
}
});
public void paint(Graphics g)
{
int i,j;
super.paint(g);
for(j=0;j<linelength;j++)
{
g.drawLine(line[j].sx,line[j].sy,line[j].tx,line[j].ty);
}
}
}//end of class myframe>