[Java] למה לא עובד ?
אני מצייר עיגול ובתוכו אני רוצה לצייר את הרדיוס שלו כך שיצביע לאן שהעכבר מצביע, אבל אני לא מצליח לצייר את הרדיוס, רק את העיגול. הנה הקוד של mouseMove :
אני מצייר עיגול ובתוכו אני רוצה לצייר את הרדיוס שלו כך שיצביע לאן שהעכבר מצביע, אבל אני לא מצליח לצייר את הרדיוס, רק את העיגול. הנה הקוד של mouseMove :
public void mouseMoved(MouseEvent e) { int mouseX = e.getX(); int mouseY = e.getY(); int centerX = ball.getXLoc() + ball.getRadius(); int centerY = ball.getYLoc() - ball.getRadius(); double alpha = Math.atan((Math.abs(mouseY - centerY)/Math.abs(mouseX - centerX))); ball.setXSpot((int)(centerX - (ball.getRadius()/Math.cos(alpha)))); ball.setYSpot((int)(centerY - (ball.getRadius()/Math.cos(alpha)))); }
והנה השיטה שמציירת:public void draw(Graphics g) { g.setColor(Color.red); g.fillOval (_xLoc, _yLoc, 2*_radius,2* _radius); g.setColor(Color.BLACK); int centerX = getXLoc() + getRadius(); int centerY = getYLoc() - getRadius(); g.drawLine(centerX, centerY, _xSpot, _ySpot); }//method draw
תודה רבה.