hi all
i'm trying to a function that listen to the mouse
basically i want to start drawing square till the user released the mouse
and than the square will disappear
this is my function please help
and my repaintpublic void StartDelete() { _pointX = new int[4]; _pointY = new int[4]; addMouseListener(new MouseAdapter(){ @Override public void mousePressed(MouseEvent e){ if(_clearFlag) { _pointX[3] = e.getX(); _pointY[3]= e.getY(); } } }); addMouseMotionListener(new MouseAdapter(){ public void mouseDragged(MouseEvent e){ if(_clearFlag) { _pointX[0]=(e.getX()-_pointX[3])+_pointX[3]; _pointY[0]=_pointY[3]; _pointX[1]= e.getX(); _pointY[1] = e.getY(); _pointX[2]=_pointX[3]; _pointY[2]=e.getY(); repaint(); } } }); addMouseMotionListener(new MouseAdapter(){ public void mouseReleased(MouseEvent e){ if(_clearFlag) { _pointX=null; _pointY=null; repaint(); } } }); }
public void paintComponent(Graphics g){ super.paintComponent(g); //////////////////////////////--------------------Display obstacle points----------------////////////////////////////////////////////////// g.setColor(Color.BLACK); LinkedList[] positive = new LinkedList[_obstacleDataPoints.getPositiveArraySize()] ; LinkedList[] negative = new LinkedList[_obstacleDataPoints.getNegativeArraySize()]; negative = _obstacleDataPoints.getNegativeNumbers(); positive = _obstacleDataPoints.getPositiveNumbers(); for(int i=0;i<positive.length-1;i++) { PointX x; for(int j=0;j<positive[i].size();j++) { x= (PointX)positive[i].get(j); // IfPointOutOfFrame(x.getX(),i); g.fillOval(ConvertXRobotDataToDraw(x.getX()),ConvertYRobotDataToDraw(i), 4, 4); } } for(int i=1;i<negative.length-1;i++) { PointX x; for(int j=0;j<negative[i].size();j++) { x= (PointX)negative[i].get(j); // IfPointOutOfFrame(x.getX(),i); g.fillOval(ConvertXRobotDataToDraw(x.getX()),ConvertYRobotDataToDraw(-i), 4, 4); } } [B]if(_pointX!=null&&_pointY!=null) g.drawPolygon(_pointX, _pointY, 4);[/B] }
in run time this mouseReleased dosent work he wont get in to this func when i Release the button
10X