// File Name : Sample05.java import java.awt.Button; import java.awt.Dimension; import java.awt.Frame; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.Insets; import java.awt.List; import java.awt.Panel; import java.awt.Toolkit; public class Sample05 { public static void main(String[] ar) { Sample05_Sub sam = new Sample05_Sub(); } } class Sample05_Sub extends Frame { private Dimension dimen, dimen1; private int xpos, ypos; private Button bt = new Button("-->"); private Button bt1 = new Button("<--"); private List list = new List(10, true); private List list1 = new List(10); public Sample05_Sub() { super("목록 선택"); this.init(); this.start(); this.setSize(300, 200); dimen = Toolkit.getDefaultToolkit().getScreenSize(); dimen1 = this.getSize(); xpos = (int)(dimen.getWidth() / 2 - dimen1.getWidth() / 2); ypos = (int)(dimen.getHeight() / 2 - dimen1.getWidth() / 2); this.setLocation(xpos, ypos); this.setVisible(true); } public void init() { for (int i=0; i<20; i++) { list.add("TEST "+ (i+1)); } // Grid Class GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints gc = new GridBagConstraints(); this.setLayout(gridbag); gc.insets = new Insets(0, 0, 0, 10); gridbag.setConstraints(list, gc); this.add(list); GridLayout grid = new GridLayout(2, 1, 0, 20); Panel p = new Panel(grid); p.add(bt); p.add(bt1); gc.insets = new Insets(0, 0, 0, 0); gridbag.setConstraints(p, gc); this.add(p); gc.insets = new Insets(0, 10, 0, 0); gridbag.setConstraints(list1, gc); this.add(list1); } public void start() { // Event나 쓰레드 처리할 부분 } }
[결과 화면] - 리스트2개 버튼 2개가 생성된다.
현재 버튼에는 이벤트가 들어가있지 않다.
'프로그래밍 > JAVA' 카테고리의 다른 글
2013-08-18 Frame 클래스 (자바 UI 만들기) (0) | 2013.08.18 |
---|---|
2013-08-18 File 클래스 - Write (0) | 2013.08.18 |
2013-08-18 abstract 클래스 (1) | 2013.08.18 |