import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.*;
public class Main extends JFrame{
ImageIcon ballon=new ImageIcon("ballon.jpg");
Container ct = getContentPane();
public Main() {
MyMouseListener listener = new MyMouseListener();
ct.addMouseListener(listener);
setSize(1920,1080);
setVisible(true);
setLayout(null);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new Main();
}
class MyMouseListener extends MouseAdapter{
public void mouseClicked(MouseEvent e) {
int x = e.getX();
int y = e.getY();
MyThread th = new MyThread(x,y);
th.start();
//thread 생성 시작
}
}
class MyThread extends Thread{
int i=0;
int x;
int y;
public MyThread(int x,int y) {
this.x=x;
this.y=y;
}
public void run() {
JLabel la = new JLabel(ballon);
ct.add(la);
la.setSize(50, 50);
la.setLocation(x, y);
while(true) {
if(la.getY() <= 0) {
System.out.println("killing");
ct.remove(la);
repaint();
break;
}
la.setLocation(x, y-i*5);
repaint();
try {
sleep(20);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
i++;
}
}
}
//스레드 클래스
}