Java Applet ile yapılmış elips sınır çizgisi üzerinde giden top

package applet;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
//import java.util.logging.Level;
//import java.util.logging.Logger;
public class sf extends Applet implements MouseListener,MouseMotionListener{

    
     int r1=50;
    int r2=25;
    public boolean mousetikstop=false;
    public int x=60,y=r2+50,sy=0;
    boolean ileri=true; 
    
    
    public void init(){
        
        
        
        this.setSize(500,500);
        this.setLayout(null);
        addMouseListener(this);
        addMouseMotionListener(this);
    }

    public void zaman(){
        try{
            /*
           if(sy<25 ) d1();
           else if(sy>=25 && sy<50)d2();
           else if(sy>=50 && sy<75)d3();
           else d4();
           if(sy==99)sy=0;
            Thread.sleep(200);
            */            
            
            int a = x-60-r1;
            
            double m = (double) a;
            double n = (double) r1;
            int b=(int) Math.sqrt((1-(m*m)/(n*n))*r2*r2);
            System.out.println(b);
            if( ileri) 
            y=b+50+r2;
            else 
                y=50+r2-b;
             repaint();
             
             if(ileri) x=x+2;
             else x-=2;
             
             if(x>=60+2*r1){
                 ileri=false;
             }
             if(x<=60){
                 ileri=true;
             }
             Thread.sleep(200);
        }catch(Exception ex){
            
            
           
        }
        
            
    }
    public void paint(Graphics g){
        super.paint(g);
        g.drawOval(60,60,2*r1,2*r2);
        
        g.fillOval(x-10,y,20,20);
        //mousetikstop=true;
        
        zaman();
        repaint();
    }

    @Override
    public void mouseClicked(MouseEvent e) {
      
    }

    @Override
    public void mousePressed(MouseEvent e) {
     
        switch(e.getButton()){
            case MouseEvent.BUTTON1:System.exit(2);
            case MouseEvent.BUTTON2:break;
            case MouseEvent.BUTTON3:break;
            default: break;
        }
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        
    }

    @Override
    public void mouseExited(MouseEvent e) {
        
             
    }

    @Override
    public void mouseDragged(MouseEvent e) {
        
    }

    @Override
    public void mouseMoved(MouseEvent e) {
        
    }
}

Ekran Görüntüsü;

 

 

Yorumlar

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