JAVA

210823_Swing(버튼)+image

요옫 2021. 8. 23. 17:22

public class SwingImageIcon_07 extends JFrame{

 

Container cp;

JButton btn1,btn2,btn3,btn4;

 

ImageIcon icon1=new ImageIcon("/Library/sist0730/image/01.png");  //컴퓨터에 있는 이미지 저장경로

ImageIcon icon2=new ImageIcon("/Library/sist0730/image/02.png");

ImageIcon icon3=new ImageIcon("/Library/sist0730/image/03.png");

ImageIcon icon4=new ImageIcon("/Library/sist0730/image/04.png");

ImageIcon icon5=new ImageIcon("/Library/sist0730/image/05.png");

 

public SwingImageIcon_07(String title) {

super(title);

 

cp=this.getContentPane();

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setBounds(200,300,400,400);  //정사각형

cp.setBackground(new Color(155,155,200));

 

initDesign();

this.setVisible(true);

}

 

 

//디자인

public void initDesign() {

 

//버튼4개 생성.. 그리드..행열배치

this.setLayout(new GridLayout(2, 2));  //버튼을 2행2열로 배치

 

//버튼1

btn1=new JButton("Hello",icon1);

btn1.setHorizontalTextPosition(JButton.CENTER);  //텍스트 가로 위치

btn1.setVerticalTextPosition(JButton.BOTTOM);  //텍스트 세로 위치  

 

this.add(btn1);  //생성했으면 프레임에 올리기

btn1.setRolloverIcon(icon2);  //마우스 올렸을 때 icon2가 나옴

btn1.setPressedIcon(icon3);  //마우스 클릭했을 때 icon3가 나옴

 

//버튼2

btn2=new JButton(icon4);

this.add(btn2);

 

//버튼3

btn3=new JButton("JAVA");  //텍스트

this.add(btn3);

 

//버튼4

btn4=new JButton("Good",icon5);

this.add(btn4);

}

 

 

public static void main(String[] args) {

 

    new SwingImageIcon_07("이미지아이콘 연습");

}

}

 

'JAVA' 카테고리의 다른 글

210823_Swing(버튼)+image+Arrays  (0) 2021.08.23
210823_Swing(버튼)+image+Null  (0) 2021.08.23
210823_swing(버튼)  (0) 2021.08.23
210823_swing+layout(버튼 생성)  (0) 2021.08.23
210823_Swing  (0) 2021.08.23