johnroach1985 0 Junior Poster

well it actually works but the circle kind of slides instead of staying put.Help with the algorithm would be welcomed.(actually i need help:sad: )
----------------------------------
import java.awt.*;
import java.awt.event.*;
public class hata{
public static void main(String args[]){
Pencere pen=new Pencere();
pen.setVisible(true);
}
}
class Pencere extends Frame {
int xcoor,ycoor,width,height, solx,soly;
Checkbox cb_merkez,cb_sol;
CheckboxGroup cbg_baslangic;
boolean merkez_mi;

public Pencere(){
setTitle("nek");
setSize(400,400);
cbg_baslangic=new CheckboxGroup();
cb_merkez=new Checkbox("Merkezden",cbg_baslangic,false);
cb_merkez.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent ie){
merkez_mi=true;
}
});

cb_sol=new Checkbox("Soldan",cbg_baslangic,true);
cb_sol.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent ie){
merkez_mi=false;
}
});

Panel p=new Panel();
p.setBackground(SystemColor.menu);
p.add(cb_merkez);p.add(cb_sol);


add(p,BorderLayout.NORTH);

this.addMouseMotionListener(new MouseMotionAdapter(){
public void mouseDragged(MouseEvent me){
if(!merkez_mi){
int mousex=me.getX();
int mousey=me.getY();

solx=Math.min(xcoor,mousex);
soly=Math.min(ycoor,mousey);

width=Math.abs(xcoor-mousex);
height=Math.abs(ycoor-mousey);
}
else{
int mousex=me.getX();
int mousey=me.getY();

width=Math.abs(xcoor-mousex);
height=Math.abs(ycoor-mousey);

solx=xcoor-width/2;
soly=ycoor-height/2;

}

repaint();
}
});
this.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent me){
xcoor=me.getX();
ycoor=me.getY();
}
});
}
public void paint(Graphics g){
g.drawOval(solx,soly,width,height);
}
}