import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class MyPanel extends JPanel{
ImageIcon icon4 = new ImageIcon("Tetris backg.png");
Image img = icon4.getImage();
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(img, 0, 0, this);
}
}
class Main extends JFrame {
int makable = 1;
ImageIcon icon1 = new ImageIcon("Tetris Block 1.png");
ImageIcon icon2 = new ImageIcon("Tetris Block 2.png");
ImageIcon icon3 = new ImageIcon("Tetris Block 3.png");
JLabel la5=new JLabel();
int i;
int lay = la5.getY();
Container c;
public Main() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setContentPane(new MyPanel());
c=getContentPane();
c.setLayout(null);
JLabel[]la=new JLabel[4];
ImageIcon[] names = {icon1, icon2, icon3};
for(i=0;i<3;i++) {
la[i]=new JLabel(names[i]);
c.add(la[i]);
la[i].addMouseListener(new MyMouseListener());
la[i].addKeyListener(new MyKeyListener());
la[i].setSize(70, 70);
la[i].setLocation(i*70, 0);
}
c.add(la5);
la5.setSize(70, 70);
la5.setLocation(i*70, 0);
c.setFocusable(true);
c.requestFocus();
//c.setBackground(c);
setSize(500,500);
setVisible(true);
}
class MyMouseListener extends MouseAdapter{
@Override
public void mousePressed(MouseEvent e) {
/*
if(makable==0) return ;
makable=0;
// TODO Auto-generated method stub
//1. 마우스를 클릭하면 랜덤 블록 생성
int a=(int)(Math.random()*3);
if(a==1) {
la5.setIcon(icon1);
}
else if(a==2) {
la5.setIcon(icon2);
}
else if(a==3){
la5.setIcon(icon3);
}
// 블록 내려오기
int x = (int)(Math.random()*450);
while(true) {
lay=lay+20;
la5.setLocation(x, lay); // 블록 아래로 조금 이동하기
System.out.println(lay);
c.repaint();
c.revalidate();
try {
Thread.sleep(200);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} // 0.2초 기다리기==200밀리세컨
if(la5.getY()==500) {// 블록이 바닥에 닿았다면
break;
}
}
makable=1;
}
*/
}
class MyKeyListener extends KeyAdapter{
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
switch(e.getKeyCode()) {
case KeyEvent.VK_SPACE:icon1.
}
}
}
public static void main(String[] args) {
new Main();
}
}
}