2008년 7월 14일 월요일

Canvas - java sample code

마우스 점찍기

import java.awt.*;
import java.awt.event.*;
class aa extends Frame implements ActionListener {
public static Canvas cvas;
public aa()
{
//cvas = new Canvas();
//add("Center",cvas);

}
public boolean mouseDown(Event evt, int x, int y)
{
Graphics g = cvas.getGraphics();
//g.fillOval(x, y, 10,10);
g.fillOval(x-10/2-4, y-10/2-30, 10,10);//마우스와 점의 중심좌표 조절하고 점찍기
return true;
}

public aa(String title)
{
setTitle(title);
Button bt1 = new Button("빠져나가기");
bt1.addActionListener(this);

add(bt1,"South");
setSize(300,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
setVisible(false);
System.exit(0);
}
public static void main(String args[])
{
//Canvas 생성은 여기서 하세요.
Frame f= new aa("ActionEvent 예제");
cvas = new Canvas();//Canvas 생성
f.add("Center",cvas);//Frame에 Canvas 붙이기

}
}
문]
랜덤으로 점찍는 건데요.. 컴파일은 되고 빠져 나가기 버튼 누르면 나가는것도 되는데요..
점 찍을려고 마우스 클릭하면 에러 나는데... 모 때문에 그런지..... 알수가 없어서요.. 자세히좀 알려주세요...

댓글 없음:

댓글 쓰기

-


Sidewinder


World


FishMusic


LaughingBaby