import java.applet.*;
import java.awt.event.*;
import java.awt.image.PixelGrabber;
public class R extends Applet implements MouseListener,MouseMotionListener,Runnable,ActionListener
{
Graphics G;
Image IM;
Thread Ti;
MediaTracker T;
Image ALL;
Image ALLT;
int w;
int h;
int[] pixels;
int pi=0;
int x[][]={{600,100},{600,200},{600,300}};
int xt[][]={{600,100},{600,200},{600,300}};
int o[]={-16777216,-32704,-8388608};
boolean kk[]={false,false,false};
int k=0;
int tt[][]={{100,100,100,50},{300,200,100,50,},{400,300,100,50}};
Button sss=new Button("다시");
boolean ee[]={false,false,false};
public void set()
{
for(int i=0;i<3;i++)
for(int j=0;j<2;j++)
x[i][j]=xt[i][j];
for(int i=0;i<3;i++)kk[i]=false;
}
public void init()
{
setLayout(null);
sss.reshape(700,400,70,20);
sss.addActionListener(this);
add(sss);
IM=createImage(size().width,size().height);
G=IM.getGraphics();
addMouseListener(this);
addMouseMotionListener(this);
ALL=getImage(this.getDocumentBase(),"temp.bmp");
ALLT=getImage(this.getDocumentBase(),"temp1.bmp");
T=new MediaTracker(this);
T.addImage(ALL,0);
T.addImage(ALLT,0);
try{
T.waitForAll();
}catch(InterruptedException e){}
w=565;
h=415;
pixels = new int[w*h];
PixelGrabber pg = new PixelGrabber(ALLT,0,0,w,h,pixels,0,w);
try {
pg.grabPixels();
} catch (InterruptedException e) {}
pixels = (int[])pg.getPixels() ;
if(Ti==null)
{
Ti=new Thread (this);
Ti.start();
}
}
public void run()
{
while(Ti!=null)
{
try{Ti.sleep(5);
}catch(InterruptedException e){}
for(int i=0;i<3;i++)
if(!(k==i+1))
if(!kk[i])
{
if(!(x[i][0]==xt[i][0]))
{
if(x[i][0]>xt[i][0])x[i][0]--;
else x[i][0]++;
}
if(!(x[i][1]==xt[i][1]))
{
if(x[i][1]>xt[i][1])x[i][1]--;
else x[i][1]++;
}
}
repaint();
}
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
G.setColor(Color.white);
G.fillRect(0,0,size().width,size().height);
if((T.statusAll(true) & MediaTracker.COMPLETE)!=0){
G.drawImage(ALL,0,0,this);
}
else {
G.setColor(Color.red);
G.drawString("Image Loading ",20,170);
}
G.setColor(Color.black);
G.drawString("머리",x[0][0],x[0][1]);
G.drawString("몸",x[1][0],x[1][1]);
G.drawString("다리",x[2][0],x[2][1]);
for(int i=0;i<3;i++)G.drawRect(x[i][0]-20,x[i][1]-10,40,20);
/*
G.drawString(Integer.toString(pi),100,100);
for(int j=0;j<3;j++)
if(ee[j])
for(int i=0;i<pixels.length;i++)
if(pixels[i]==o[1])G.drawLine(i%w,(int)((i-i%w)/w),i%w+1,(int)((i-i%w)/w)+1);
*/
G.drawString("ps:여기서 다리는 앞다리를 말함",100,480);
g.drawImage(IM,0,0,size().width,size().height,this);
}
public void mouseMoved(MouseEvent me){}
public void mouseDragged(MouseEvent me){
if(k!=0)
{
if(!kk[k-1])
{
x[k-1][0]=me.getX();
x[k-1][1]=me.getY();
}
}
repaint();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==sss)set();
repaint();
}
public void mouseClicked (MouseEvent me){}
public void mouseEntered (MouseEvent me){}
public void mouseExited (MouseEvent me){}
public void mouseReleased(MouseEvent me){
pi=pixels[me.getX()+me.getY()*w];
if(k!=0)
{
if(!kk[k-1])
{
if(pi==o[k-1])kk[k-1]=true;
}
}
k=0;
repaint();
}
public void mousePressed (MouseEvent me){
for(int i=0;i<3;i++)
if(x[i][0]<me.getX()+20 && me.getX()-20<x[i][0] &&
x[i][1]<me.getY()+10 &&me.getY()-10<x[i][1])k=i+1;
repaint();
}
}
댓글 없음:
댓글 쓰기