1. GUI 연습문제 (1)
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | package guiex; import java.awt.BorderLayout; import java.awt.Button; import java.awt.Checkbox; import java.awt.CheckboxGroup; import java.awt.Color; import java.awt.Frame; import java.awt.Label; import java.awt.Panel; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class GuiTest08 extends Frame { Panel p1, p2; Label label; CheckboxGroup cg; Checkbox sub1, sub2, sub3; Button[] btn; String[] btnStr = {"확인", "종료"}; String title = "과목 중에 선택하세요"; public GuiTest08() { // 1. 컨테이너 super("GUI Test01"); setSize(300, 150); setLayout(new BorderLayout()); // 2. 컴포넌트 label = new Label(title, Label.CENTER); label.setBackground(Color.GRAY); p1 = new Panel(); cg = new CheckboxGroup(); sub1 = new Checkbox("JAVA", true, cg); sub2 = new Checkbox("C", false, cg); sub3 = new Checkbox("PYTHON", false, cg); p2 = new Panel(); btn = new Button[2]; btn[0] = new Button(btnStr[0]); btn[1] = new Button(btnStr[1]); // 3. add add(label, BorderLayout.NORTH); add(p1, BorderLayout.CENTER); p1.add(sub1); p1.add(sub2); p1.add(sub3); add(p2, BorderLayout.SOUTH); p2.add(btn[0]); p2.add(btn[1]); setVisible(true); } public static void main(String[] args) { GuiTest08 g8 = new GuiTest08(); } } |
# 실행 화면
2. GUI 연습문제 (2)
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | package guiex; import java.awt.BorderLayout; import java.awt.Button; import java.awt.Frame; import java.awt.Panel; import java.awt.TextArea; import java.awt.TextField; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class GuiTest09 extends Frame { Panel p1, p2, p3; TextField tf; TextArea ta; Button[] btn; String[] str = {"Start", "End"}; public GuiTest09() { super("GUI Test02"); setSize(400, 250); // 1. 컨테이너 setLayout(new BorderLayout(10, 0)); // 2. 컴포넌트 p1 = new Panel(); tf = new TextField("Hello Java", 30); p2 = new Panel(); ta = new TextArea("내용을 입력하세요.", 10, 30, TextArea.SCROLLBARS_VERTICAL_ONLY); p3 = new Panel(); btn = new Button[2]; btn[0] = new Button(str[0]); btn[1] = new Button(str[1]); // 3. add add(p1, BorderLayout.NORTH); p1.add(tf); add(p2, BorderLayout.CENTER); p2.add(ta); add(p3, BorderLayout.SOUTH); p3.add(btn[0]); p3.add(btn[1]); setVisible(true); } public static void main(String[] args) { GuiTest09 g9 = new GuiTest09(); } } | cs |
# 실행 화면
3. GUI 연습문제 (3)
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | package guiex; import java.awt.BorderLayout; import java.awt.Button; import java.awt.Frame; import java.awt.GridLayout; import java.awt.List; import java.awt.Panel; import java.awt.TextField; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; public class GuiTest10 extends Frame { List list; TextField tf; Button[] btn; String[] str = {"추가", "지우기", "전체지우기", "종료"}; Panel p; public GuiTest10() { super("GUI Test03"); setSize(300, 200); // 1. 컨테이너 setLayout(new BorderLayout()); // 2. 컴포넌트 p = new Panel(new GridLayout(0, 1)); btn = new Button[4]; for(int i=0; i<btn.length; i++) { btn[i] = new Button(str[i]); p.add(btn[i]); } list = new List(); tf = new TextField(30); // 3. add add(list, BorderLayout.CENTER); add(p, BorderLayout.EAST); add(tf, BorderLayout.SOUTH); setVisible(true); } public static void main(String[] args) { GuiTest10 g10 = new GuiTest10(); } } | cs |
# 실행 화면
'JAVA > JAVA2' 카테고리의 다른 글
JAVA2_day13 | GUI (PopupMenu, MenuItem) (0) | 2018.01.30 |
---|---|
JAVA2_day12 | 내부 클래스 (Inner class) (0) | 2018.01.30 |
JAVA2_day11 | GUI (LayoutManager) (0) | 2018.01.30 |
JAVA2_day11 | GUI (List, Choice) (0) | 2018.01.30 |
JAVA2_day11 | GUI (Checkbox, CheckboxGroup) (0) | 2018.01.30 |