OpenFrameWork
오픈프레임워크_Day16
px
2015. 4. 20. 11:23
### : 목차 구분 기호
--- : 목차 내에 항목 구분 기호
목차
1. 이론 및 정보
2. 설정 및 그 밖에
3. 소스코드
4. 과제
###################################
1. 이론 및 정보
-----------------------------------
-----------------------------------
-----------------------------------
-----------------------------------
###################################
2. 설정 및 그 밖에
-----------------------------------
###################################
2. 설정 및 그 밖에
-----------------------------------
-----------------------------------
-----------------------------------
-----------------------------------
###################################
3. 소스코드
###################################
3. 소스코드
----------------------------------- 3-1 /day14/src/awt/component/ComponentTest1.java 수정 package awt.component; import java.applet.Applet; import java.awt.Color; import java.awt.Label; /* * <applet code="ComponentTest1" width="300" height="400"></applet> */ public class ComponentTest1 extends Applet { //#1 웹 브라우저는 init()메서드를 호출함 Label label1, label2, label3; @Override public void init() { label1 = new Label("첫번째 라벨"); label2 = new Label("두번째 라벨"); label3 = new Label("세번째 라벨"); add(label1); add(label2); add(label3); label1.setBackground(Color.green); label2.setBackground(Color.cyan); label3.setBackground(Color.gray); setBackground(Color.yellow); label2.setVisible(false); } } ----------------------------------- 3-2 /day15/src/awt/component/ComponentTest2.java package awt.component; import java.awt.Color; import java.awt.Frame; import java.awt.Label; //#2 Frame 상속을 받지 않음 public class ComponentTest2{ Label label1, label2, label3; Frame f; public ComponentTest2() { f = new Frame("프레임 테스트"); // 같은 위치에 세개가 포개짐 label1 = new Label("첫번째 라벨"); label2 = new Label("두번째 라벨"); label3 = new Label("세번째 라벨"); f.add(label1); f.add(label2); f.add(label3); label1.setBackground(Color.green); label2.setBackground(Color.cyan); label3.setBackground(Color.gray); f.setBackground(Color.yellow); label2.setVisible(false); // 반드시 크기 지정(setSize(), setBounds()) //setSize(300,400); f.setBounds(300, 400, 300, 400); // 반드시 화면 출력 설정(show, setVisible(true)); f.setVisible(true); } public static void main(String[] args) { // TODO Label을 Frame에 담아서 출력하기 new ComponentTest2(); } } //#1 Frame 상속 받은 방식 /* public class ComponentTest2 extends Frame{ Label label1, label2, label3; public ComponentTest2() { // 같은 위치에 세개가 포개짐 label1 = new Label("첫번째 라벨"); label2 = new Label("두번째 라벨"); label3 = new Label("세번째 라벨"); add(label1); add(label2); add(label3); label1.setBackground(Color.green); label2.setBackground(Color.cyan); label3.setBackground(Color.gray); setBackground(Color.yellow); label2.setVisible(false); // 반드시 크기 지정(setSize(), setBounds()) //setSize(300,400); setBounds(300, 400, 300, 400); // 반드시 화면 출력 설정(show, setVisible(true)); setVisible(true); } public static void main(String[] args) { // TODO Label을 Frame에 담아서 출력하기 new ComponentTest2(); } } */ ----------------------------------- 3-3 /day15/src/awt/component/ButtonTest.java package awt.component; import java.applet.Applet; import java.awt.Button; import java.awt.Color; import java.awt.Frame; public class ButtonTest extends Frame{ Button b1,b2,b3; public ButtonTest() { b1 = new Button("첫번째 버튼"); b2 = new Button("두번째 버튼"); b3 = new Button("세번째 버튼"); add(b1); add(b2); add(b3); b3.setBackground(Color.yellow); setBounds(50,50,300,400); setVisible(true); } public static void main(String[] args) { // TODO Button new ButtonTest(); } } /* public class ButtonTest extends Applet{ Button b1,b2,b3; public void init() { b1 = new Button("첫번째 버튼"); b2 = new Button("두번째 버튼"); b3 = new Button("세번째 버튼"); add(b1); add(b2); add(b3); b3.setBackground(Color.yellow); } } */ ----------------------------------- 3-4 /day15/src/awt/component/CheckboxRadioTest.java package awt.component; import java.applet.Applet; import java.awt.Checkbox; import java.awt.CheckboxGroup; import java.awt.Color; public class CheckboxRadioTest extends Applet{ Checkbox c1, c2, c3; Checkbox r1, r2; CheckboxGroup g; @Override public void init() { c1 = new Checkbox("첫번째 체크 박스", true); c2 = new Checkbox("두번째 체크 박스"); c3 = new Checkbox("세번째 체크 박스"); add(c1); add(c2); add(c3); g = new CheckboxGroup(); r1 = new Checkbox("첫번째 라디오 버튼",g,true); r2 = new Checkbox("두번째 라디오 버튼",g,false); add(r1); add(r2); c3.setBackground(Color.green); } } ----------------------------------- 3-5 /day15/src/awt/component/ChoiceTest.java package awt.component; import java.applet.Applet; import java.awt.Choice; public class ChoiceTest extends Applet{ Choice c; @Override public void init() { c = new Choice(); c.addItem("홍길동"); c.addItem("임꺽정"); c.addItem("권율"); c.addItem("신돌석"); add(c); } } ----------------------------------- 3-6 /day15/src/awt/component/ListTest.java package awt.component; import java.applet.Applet; import java.awt.List; public class ListTest extends Applet{ List list1, list2; @Override public void init() { list1 = new List(2); list2 = new List(3, true);//true 다중 선택이 가능해짐 list1.add("사과"); list1.add("배"); list1.add("포도"); list1.add("바나나"); list2.add("짜장면"); list2.add("라면"); list2.add("돈까스"); list2.add("김치"); add(list1); add(list2); } } ----------------------------------- 3-7 /day15/src/awt/component/TextTest.java package awt.component; import java.applet.Applet; import java.awt.TextArea; import java.awt.TextField; public class TextTest extends Applet { TextField tf; TextArea ta; @Override public void init() { tf = new TextField(":한줄만 입력 가능", 50); ta = new TextArea("여러줄 입력 가능", 3, 30); add(tf); add(ta); } } ----------------------------------- 3-8 /day15/src/awt/container/FrameTest.java package awt.container; import java.awt.Button; import java.awt.Frame; public class FrameTest extends Frame { Button b; FrameTest() { b = new Button("버튼 입니다."); add(b); setSize(300,400); setVisible(true); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } //현재 프레임을 종료 dispose(); } public static void main(String[] args) { // TODO Frame test new FrameTest(); } } ----------------------------------- 3-9 /day15/src/awt/container/PanelTest.java package awt.container; import java.applet.Applet; import java.awt.Button; import java.awt.Color; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class PanelTest extends Applet implements ActionListener{ Button b1, b2, b3, b4; Panel p1, p2; @Override public void init() { p1 = new Panel(); p2 = new Panel(); b1 = new Button("패널2 보이기"); b2 = new Button("패널2 안보이기"); b3 = new Button("패널1 보이기"); b4 = new Button("패널1 안보이기"); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); p1.add(b1); p1.add(b2); p2.add(b3); p2.add(b4); p1.setBackground(Color.green); p2.setBackground(Color.yellow); add(p1); add(p2); } @Override public void actionPerformed(ActionEvent e) { //System.out.println("버튼이 눌렀어용"); //System.out.println(e); Button b = (Button)e.getSource(); System.out.println(e.getActionCommand()); if(b.getLabel().equals(b1.getLabel())){ p2.setVisible(true); }else if(b.getLabel().equals(b2.getLabel())){ p2.setVisible(false); }else if(b.getLabel().equals(b3.getLabel())){ p1.setVisible(true); }else if(b.getLabel().equals(b4.getLabel())){ p1.setVisible(false); } } } ----------------------------------- 3-10 /day15/src/awt/container/UserDefineDialogTest.java package awt.container; import java.awt.Button; import java.awt.Color; import java.awt.Dialog; import java.awt.Frame; import java.awt.Label; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; class MessageDialog extends Dialog implements ActionListener{ Button btnExit; String msg; Label label; public MessageDialog(Frame owner, String title) { super(owner, "메시지 박스", false); btnExit = new Button("확인"); msg = title; } void displayUI(){ label = new Label(msg); add("North",label); add(btnExit); btnExit.addActionListener(this); setBackground(Color.gray); setBounds(50,50,200,100); setVisible(true); } @Override public void actionPerformed(ActionEvent e) { dispose(); } } public class UserDefineDialogTest extends Frame implements ActionListener{ Button b1, b2; Panel p; public UserDefineDialogTest(){ b1 = new Button("Dialog 열기"); b1.addActionListener(this); b2 = new Button("종료버튼"); b2.addActionListener(this); p = new Panel(); p.add(b1); p.add(b2); add(p); } @Override public void actionPerformed(ActionEvent e) { String s = ((Button) e.getSource()).getName(); if (s.equals(b1.getName())) { MessageDialog dlgMsg = new MessageDialog(this, "이것은 테스트 입니다."); dlgMsg.displayUI(); } else if (s.equals(b2.getName())) { dispose(); } } public static void main(String[] args) { // TODO 사용자 정의 Dialog UserDefineDialogTest ud = new UserDefineDialogTest(); ud.setSize(300,400); ud.setVisible(true); } } ----------------------------------- 3-11 /day15/src/awt/container/FileDialogTest.java package awt.container; import java.awt.Button; import java.awt.FileDialog; import java.awt.Frame; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class FileDialogTest extends Frame implements ActionListener{ Button b1,b2; Panel p; FileDialog fopen, fsave; public FileDialogTest() { b1 = new Button("파일 열기"); b2 = new Button("파일 저장"); b1.addActionListener(this); b2.addActionListener(this); p = new Panel(); p.add(b1); p.add(b2); add(p); fopen = new FileDialog(this, "파일 열기", FileDialog.LOAD); fsave = new FileDialog(this, "파일 저장", FileDialog.SAVE); } public static void main(String[] args) { FileDialogTest test = new FileDialogTest(); test.setSize(300, 400); test.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals(b1.getActionCommand())) { fopen.setVisible(true); System.out.println(fopen.getDirectory()); System.out.println(fopen.getFile()); }else if (e.getActionCommand().equals(b2.getActionCommand())) { fsave.setVisible(true); } } } ----------------------------------- 3-12 /day15/src/awt/layout/FlowLayoutTest.java package awt.layout; import java.awt.Button; import java.awt.FlowLayout; import java.awt.Frame; public class FlowLayoutTest extends Frame { Button b1, b2, b3, b4, b5; public FlowLayoutTest() { b1 = new Button("첫번째 버튼"); b2 = new Button("두번째 버튼"); b3 = new Button("세번째 버튼"); b4 = new Button("네번째 버튼"); b5 = new Button("다섯번째 버튼"); setLayout(new FlowLayout()); add(b1); add(b2); add(b3); add(b4); add(b5); setVisible(true); setBounds(50,50,300,400); } public static void main(String[] args) { new FlowLayoutTest(); } } ----------------------------------- 3-13 /day15/src/awt/layout/BorderLayoutTest.java package awt.layout; import java.awt.BorderLayout; import java.awt.Button; import java.awt.Frame; public class BorderLayoutTest extends Frame { Button b1, b2, b3, b4, b5; public BorderLayoutTest() { b1 = new Button("첫번째 버튼"); b2 = new Button("두번째 버튼"); b3 = new Button("세번째 버튼"); b4 = new Button("네번째 버튼"); b5 = new Button("다섯번째 버튼"); //setLayout(new BorderLayout()); //add("North",b1); //add(b1,BorderLayout.NORTH); add(BorderLayout.NORTH,b1); add("West",b2); add("East",b3); add("South",b4); add("Center",b5); setVisible(true); setBounds(50,50,300,400); } public static void main(String[] args) { new BorderLayoutTest(); } } ----------------------------------- 3-14 /day15/src/awt/layout/GridLayoutTest.java package awt.layout; import java.awt.Button; import java.awt.Frame; import java.awt.GridLayout; public class GridLayoutTest extends Frame { Button b1, b2, b3, b4, b5; public GridLayoutTest() { b1 = new Button("첫번째 버튼"); b2 = new Button("두번째 버튼"); b3 = new Button("세번째 버튼"); b4 = new Button("네번째 버튼"); b5 = new Button("다섯번째 버튼"); setLayout(new GridLayout(2,3)); add(b1); add(b2); add(b3); add(b4); add(b5); setVisible(true); setBounds(50,50,300,400); } public static void main(String[] args) { new GridLayoutTest(); } } ----------------------------------- |
3-15
-----------------------------------
3-16
-----------------------------------
3-17
-----------------------------------
-----------------------------------
-----------------------------------
-----------------------------------
-----------------------------------
###################################
4. 과제
-----------------------------------
###################################
4. 과제
-----------------------------------
4-1
-----------------------------------
4-2
-----------------------------------
4-3
-----------------------------------
-----------------------------------
###################################
5. 과제 해결
-----------------------------------
5. 과제 해결
-----------------------------------
-----------------------------------
-----------------------------------
-----------------------------------