Java Applet ile yapılmış top üzerine gelince topun rengini değiştirme

package kodsozluk;

import java.awt.*;
import java.applet.Applet;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

public class mouseekseni extends Applet implements MouseMotionListener {

    int x,y,dikdortgenx,dikdortgeny,dikdortgenen,dikdortgenboy;
    
    boolean rect1Active;
    
    public void init(){
        
        dikdortgenx=300;
        dikdortgeny=350;
        dikdortgenen=200;
        dikdortgenboy=100;
        
       setSize(800,800); 
        
        addMouseMotionListener(this);
    }
    public void paint(Graphics a){
        
        setBackground(Color.RED);
        if(rect1Active)
            a.setColor(Color.CYAN);
        else
            a.setColor(Color.BLACK);
        a.fillOval(dikdortgenx, dikdortgeny, dikdortgenen, dikdortgenboy);
        a.setColor(Color.CYAN);
        a.drawString("("+x+","+y+")", x, y);
    }

  

    @Override
    public void mouseMoved(MouseEvent me) {  // mause hareket ettikçe yapılcaklar
       
        x=me.getX();
        y=me.getY();
        
        if(x>dikdortgenx && x<dikdortgenx+dikdortgenen &&y>dikdortgeny && y<dikdortgeny+dikdortgenboy)
            rect1Active=true;
        else
            rect1Active=false;

        repaint();
        


    }
    
      @Override
    public void mouseDragged(MouseEvent me) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    public void mousePressed (MouseEvent me) {
    
        
        
    }
    
}

Ekran Görüntüsü;

 

 

Yorumlar

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