티스토리 뷰

반응형

⊙ 문제

 

이미지를 포함한 레이블이 있는 형태의 프로그램을 작성하시오.

 

ImageIcon 객체를 인수로 가진 JLabel() 생성자를 사용하면 되는데, ImageIcon 객체는 이미지 파일로 생성할 수 있다.

 

⊙ 문제 접근 과정

 

java파일과 같은 폴더에 그림 파일을 넣어주자!

 


 

⊙ 문제 풀이

 

import javax.swing.*;

public class Main extends JFrame {
    public Main() {
        setTitle("이미지를 포함한 레이블");

        ImageIcon icon = new ImageIcon(getClass().getResource("bear.png"));
        JLabel label = new JLabel("곰인형",icon,JLabel.CENTER);
        add(label);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(400,200);
        setVisible(true);
    }
    public static void main(String[] args) {
        new Main();
    }
}

 


⊙ 결과


 

⊙ 마무리

 

 

NONE

 

좋아요는 로그인하지 않아도 누를 수 있습니다!

728x90
반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함