Drag¸¦ ÀÌ¿ëÇÑ ¼±±×¸®±â
DragTest.java
import java.awt.*;
import java.applet.*;
public class DragTest extends Applet{
Image Buffer;
Graphics gBuffer;
int old_x, new_x, old_y, new_y;
public void init(){
Buffer=createImage(size().width,size().height);
gBuffer=Buffer.getGraphics();
gBuffer.setColor(Color.white);
gBuffer.fillRect(0,0,size().width,size().height);
}
public boolean mouseDown(Event evt,int x,int y){
old_x=new_x=x;
old_y=new_y=y;
repaint();
return true;
}
public boolean mouseDrag(Event evt,int x,int y){
old_x=new_x;
old_y=new_y;
new_x=x;
new_y=y;
repaint();
return true;
}
public void update(Graphics g){
paint(g);
}
public void paint(Graphics g){
gBuffer.setColor(Color.black);
gBuffer.drawString("Drag plz~!", 50,20);
gBuffer.setColor(Color.blue);
gBuffer.drawLine(old_x,old_y,new_x,new_y);
g.drawImage(Buffer,0,0,this);
}
}
DragTest.html
<html><head><title>DragTest</title></head>
<body>
<applet code="DragTest.class" width=400 height=200></applet>
</body></html>
C:\AWT>javac -d DragTest.java
C:\AWT>appletviewer DragTest.html
¸¶¿ì½º¸¦ µå·¡±×ÇÒ ¶§¸¶´Ù ÆÄ¶õ»ö ¼±ÀÌ ±×¾îÁý´Ï´Ù.
jabookÀúÀÚ¸íÇÔ |