Java Applet ile yapılmış fareye göre hareket eden gözler

package kodsozluk;

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

public class fareyegöregöz extends Applet implements MouseMotionListener {
  int x,y,x1,y1;

    
    public void init() {
        setSize(500,500);
        setBackground(Color.DARK_GRAY);
        addMouseMotionListener(this); x = getWidth()/2;
        x1= getWidth()/2+100;
      y= getHeight()/2;y1= getHeight()/2;
    }
     int farex,farey,farex1,farey1;
    public void paint(Graphics g) {
       g.fillOval(getWidth()/2-30-50, getHeight()/2-50, 100, 100);
       
       g.fillOval(getWidth()/2+50, getHeight()/2-50, 100, 100);
       g.setColor(Color.white);
       g.fillOval(x-30, y-10, 20, 20);
     g.setColor(Color.white);
       g.fillOval(x1-10, y1-10, 20, 20);
      
    }
    public void mouseDragged(MouseEvent e) {
    }
    
    @Override
    public void mouseMoved(MouseEvent e) {
        farex=e.getX();
        farey=e.getY();
        farex1=e.getX();
        farey1=e.getY();
        if (farex>getWidth()/2-50&&farex<getWidth()/2+50&&farey<getWidth()/2+50&&farey>getWidth()/2-50) {
             x=farex;
             y=farey;
             
        }else{double tan = Math.atan2((farey-y),(farex-x));
       double cos = getWidth()/2+40*Math.cos(tan);
        double sin =getWidth()/2+40 *Math.sin(tan);
        x=(int) cos;
        y = (int) sin;}
      
        if (farex1>getWidth()/2+50&&farex1<getWidth()/2+150&&farey1<getWidth()/2+50&&farey1>getWidth()/2-50) {
             x1=farex1;
             y1=farey1;
             
        }else{double tan = Math.atan2((farey1-y1),(farex1-x1));
       double cos = getWidth()/2+100+40*Math.cos(tan);
        double sin =getWidth()/2+40 *Math.sin(tan);
        x1=(int) cos;
        y1 = (int) sin;}
        repaint();
    }
    }

Ekran Görüntüsü;

 

 

Yorumlar

Bu gönderi için yorum yapılmadı.