import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class FareTesti extends Applet
implements MouseListener, MouseMotionListener,ActionListener
{ int INCR=1 ;
int DECR=-1 ;
int yay=0;
int PREDX=1;
int par1,par2;
int PREDY=0;
private int nx,ny,nnx,nny=-10;
int say=0,r=0;
int[] xx=new int[2];
int[] yy=new int[2];
private String s="";
private Button B1,B2,B3,B4;
private TextField T1,T2;
public void init()
{ T1=new TextField("25");
add(T1);
T2=new TextField("25");
add(T2);
B1=new Button("týklanan iki nokta arasý doðru çiz");
B1.addActionListener(this);
add(B1);
B2=new Button("yarýçaplý yayý çiz");
B2.addActionListener(this);
add(B2);
B3=new Button("yarýçaplý daireyi çiz");
B3.addActionListener(this);
add(B3);
B4=new Button("alaný tara da yolumuzu bulalým");
B4.addActionListener(this);
add(B4);
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g)
{ if(nnx!=-1){int x1,y1,x2,y2,dx,dy,e=0,e_noinc=0,e_inc=0;
x1=xx[0];x2=xx[1];y1=yy[0];y2=yy[1];
int incdec, t, i ;
if ( x1 > x2 )
{
t = x1 ; x1 = x2 ; x2 = t ;
t = y1 ; y1 = y2 ; y2 = t ;
}
dx = x2 - x1 ; dy = y2 - y1 ;
if ( dx == 0 ) /* vertical line */
{
if ( y1 > y2 )
{
t = y1 ; y1 = y2 ; y2 = t ;
}
for ( i = y1 ; i <= y2 ; i++ )
g.drawLine ( x1, i, x1,i) ;
}
if ( dy == 0 ) /* horizontal line */
{
for ( i = x1 ; i < x2 ; i++ )
g.drawLine ( i, y1, i,y1) ;
}
/* 0 < m < 1 */
if ( dy < dx && dy > 0 )
{
e_noinc = 2 * dy ;
e = 2 * dy - dx ;
e_inc = 2 * ( dy - dx ) ;
xx[0]=x1;xx[1]=x2;yy[0]=y1;yy[1]=y2;par1=PREDX;par2=INCR;
}
/* m = 1 */
if ( dy == dx && dy > 0 )
{
e_noinc = 2 * dy ;
e = 2 * dy - dx ;
e_inc = 2 * ( dy - dx ) ;
xx[0]=x1;xx[1]=x2;yy[0]=y1;yy[1]=y2;par1=PREDX;par2=INCR;
}
/* 1 < m < infinity */
if ( dy > dx && dy > 0 )
{
e_noinc = 2 * dx ;
e = 2 * dx - dy ;
e_inc = 2 * ( dx - dy ) ;
xx[0]=x1;xx[1]=x2;yy[0]=y1;yy[1]=y2;par1=PREDY;par2=INCR;
}
/* 0 > m > -1 */
if ( -dy < dx && dy < 0 )
{
dy = -dy ;
e_noinc = 2 * dy ;
e = 2 * dy - dx ;
e_inc = 2 * ( dy - dx ) ;
xx[0]=x1;xx[1]=x2;yy[0]=y1;yy[1]=y2;par1=PREDX;par2=DECR;
}
/* m = -1 */
if ( dy == -dx && dy < 0 )
{
dy = -dy ;
e_noinc = ( 2 * dy ) ;
e = 2 * dy - dx ;
e_inc = 2 * ( dy - dx ) ;
xx[0]=x1;xx[1]=x2;yy[0]=y1;yy[1]=y2;par1=PREDX;par2=DECR;
}
/* -1 > m > 0 */
if ( -dy > dx && dy < 0 )
{
dx = -dx ;
e_noinc = - ( 2*dx ) ; e = 2 * dx - dy ;
e_inc = - 2 * ( dx - dy ) ;
xx[0]=x2;xx[1]=x1;yy[0]=y2;yy[1]=y1;par1=PREDY;par2=DECR;
}
x1=xx[0]; y1=yy[0]; x2=xx[1]; y2=yy[1]; int pred=par1; incdec=par2;
int ij, start, end, var ;
if ( pred == PREDX )
{
start = x1 ; end = x2 ; var = y1 ;
}
else
{
start = y1 ; end = y2 ; var = x1 ;
}
for ( ij = start ; ij <= end ; ij++ )
{
if ( pred == PREDY )
g.drawLine ( var, ij, var,ij ) ;
else
g.drawLine ( ij, var,ij,var) ;
if ( e < 0 )
e += e_noinc ;
else
{
var += incdec ;
e += e_inc ;
}
} }
if(yay>0){
int xo=0;int yo=r;int delta=2-2*r;int limit=yay;int ciku;
do{
if(delta<0)
{ ciku=2*delta+2*yo-1;
if(ciku>0){xo++;yo--;delta=delta+2*xo-2*yo+2;}
else{xo++;delta=delta+2*xo+1;}
}
else{
if(delta>0){
ciku=2*delta-2*xo-1;
if(ciku>0){yo--;delta=delta-2*yo+1;}
else{xo++;yo--;delta=delta+2*xo-2*yo+2;}
}
else{xo++;yo--;delta=delta+2*xo-2*yo+2;}
}
g.drawLine(r-xo+xx[0]-r,r-yo+yy[0]-r,r-xo+xx[0]-r,r-yo+yy[0]-r);
}while(yo>yo-yo*yay/100);
}
if(r>0&& yay==0){
int xo=0;int yo=r;int delta=2-2*r;int limit=0;int ciku;
do{
if(delta<0)
{ ciku=2*delta+2*yo-1;
if(ciku>0){xo++;yo--;delta=delta+2*xo-2*yo+2;}
else{xo++;delta=delta+2*xo+1;}
}
else{
if(delta>0){
ciku=2*delta-2*xo-1;
if(ciku>0){yo--;delta=delta-2*yo+1;}
else{xo++;yo--;delta=delta+2*xo-2*yo+2;}
}
else{xo++;yo--;delta=delta+2*xo-2*yo+2;}
}
g.drawLine(r-xo+xx[0]-r,r-yo+yy[0]-r,r-xo+xx[0]-r,r-yo+yy[0]-r);
g.drawLine(xo+r+xx[0]-r,yo+r+yy[0]-r,xo+r+xx[0]-r,yo+r+yy[0]-r);
g.drawLine(r+xo+xx[0]-r,r-yo+yy[0]-r,r+xo+xx[0]-r,r-yo+yy[0]-r);
g.drawLine(r-xo+xx[0]-r,r+yo+yy[0]-r,r-xo+xx[0]-r,r+yo+yy[0]-r);
}while(yo>limit);
}
}
public void degerleriGir(int xx,int yy,int x,int y,int rr,int yoz)
{ nny=y;
nnx=x;
nx=xx;
ny=yy;
r=rr;
yay=yoz;
repaint();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==B1)
{degerleriGir(xx[0],yy[0],xx[1],yy[1],0,0);}
if(e.getSource()==B2)
{int ar=Integer.parseInt(T1.getText());
int arc=Integer.parseInt(T2.getText());
degerleriGir(xx[0],yy[0],-1,-1,ar,arc);}
if(e.getSource()==B3)
{int ar=Integer.parseInt(T1.getText());
degerleriGir(xx[0],yy[0],-1,-1,ar,0);}
}
public void mouseClicked(MouseEvent e)
{
if(say==0){
xx[0]=e.getX();
yy[0]=e.getY();say=1;
}
else if(say==1){
xx[1]=e.getX();
yy[1]=e.getY();say=0;
}
}
public void mousePressed(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{ }
public void mouseEntered(MouseEvent e)
{ }
public void mouseExited(MouseEvent e)
{ }
public void mouseDragged(MouseEvent e)
{ }
public void mouseMoved(MouseEvent e)
{ }
}
--------------------------------------------------------------------------------------------------------------
Sanırsam bu kodu kimse teslim etmedi bi ara yapmıştım ama proje notuna gerek kalmayınca vermedim bi incelersiniz.Ayrıca kapalı alan taranması bu kodun içinde yok.Kullanılması durumunda tüm sorumluluk kullanan öğrenciye aittir.
|