반응형
package Swing;
import javax.swing.*;
public class ImageBtn extends JFrame {
ImageIcon [] images = {
new ImageIcon(".\\img\\btn1.png"),
new ImageIcon(".\\img\\btn2.png"),
new ImageIcon(".\\img\\btn3.png"),
};
int index;
public ImageBtn(){
setTitle("Image Btn");
// 레이아웃 변경
setLayout(null);
ImageIcon btnImage1 = new ImageIcon(".\\img\\btn3.png");
ImageIcon btnImage2 = new ImageIcon(".\\img\\btn4.png");
JToggleButton btn = new JToggleButton(new ImageIcon(".\\img\\btn3.png"));
btn.setPressedIcon(btnImage2);
btn.setBounds(50,50,100,100);
btn.setToolTipText("This is Btn");
add(btn);
JLabel label = new JLabel(images[0]);
label.setBounds(50,200,70,70);
add(label);
setBounds(200,200,400,400);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
boolean b = true;
while(true){
try{
Thread.sleep(300);
index++;
label.setIcon(images[index%3]);
int x = label.getX();
label.setBounds(x-1,200,70,70);
b = !b;
label.setVisible(b);
}catch(Exception e){}
}
}
}
'JAVA > Java' 카테고리의 다른 글
| [JAVA] swing 메뉴바 만들기 (0) | 2014.11.18 |
|---|---|
| [JAVA] swing (0) | 2014.11.18 |
| [JAVA] Serializable 사용하기 (0) | 2014.11.18 |
| [JAVA] File 객체 사용 (0) | 2014.11.18 |
| [JAVA] Frame 을 이용한 window 모양 만들기 (0) | 2014.11.18 |