자바

자바 소스코드: JList를 이용한 리스트 만들기 예제

드린 2016. 11. 12. 00:43
반응형
package javaapplication59;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

class ListEx extends JFrame{
    String[] fruits={"apple", "banana", "kiwi", "mango", "pear", "peach", "berry", "strawberry", "blackberry"};
    ImageIcon[] images={new ImageIcon("image0.jpg"), new ImageIcon("image1.jpg"), new ImageIcon("image2.jpg"), new ImageIcon("image3.jpg")};
    ListEx(){
        this.setTitle("리스트 만들기 예제");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLayout(new FlowLayout());
        
        JList strList = new JList(fruits);
        this.add(strList);
        
        JList imageList = new JList(images);
        this.add(imageList);
        
        JList scrollList = new JList(fruits);
        this.add(new JScrollPane(scrollList));
        
        this.setLocationRelativeTo(null);
        this.setSize(300,300);
        this.setVisible(true);
    }
}
public class JavaApplication59 {
    public static void main(String[] args) {
        new ListEx();
    }
}

<결과>

2016/11/12 - [자바] - 자바 소스코드: JTextArea를 이용한 텍스트 영역만들기 예제

2016/10/29 - [자바] - 자바 소스코드: 랜덤위치의 숫자를 순서대로 클릭하여 없애기

2016/10/29 - [자바] - 자바 소스코드: 랜덤함수를 이용한 가위바위보 게임

#자바 #자바 소스코드 #리스트 만들기 예제 #JList #실습 예제

반응형