티스토리 뷰

프로그래밍/Java Programming

AWT 기본만들기

방구석개발 2018. 4. 7. 05:02

기본적인 프로젝트로 실행은 되지 않으며 틀만 구성합니다.


1. MyWindow.java


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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package Window;
 
import java.awt.*;
import java.awt.event.*;
 
class Windows extends Frame {
 
    public Windows(String title) {
 
        super(title);
        this.setSize(900, 600);
        setLayout(null);
        this.setBackground(Color.yellow);
 
        PopupMenu pm;
        MenuBar mb;
        Menu file, edit, windows;
 
        mb = new MenuBar();
        file = new Menu("File");
        edit = new Menu("Edit");
        windows = new Menu("Windows");
 
        file.add("새파일");
        file.add("열기");
        file.addSeparator();
        file.add("저장");
        file.add("새이름으로저장");
        file.addSeparator();
        edit.add("편집");
        edit.add("바꾸기");
        windows.add("정보");
 
        mb.add(file);
        mb.add(edit);
        mb.add(windows);
        setMenuBar(mb);
 
        Label Q;
        Label Q1;
        Label Q2;
        Label Q3;
        Label Q4 = new Label("출력");
 
        // 입력제목란
        Label la1 = new Label("이름");
        Label la2 = new Label("학번");
        Label la3 = new Label("자바");
        Label la4 = new Label("C");
        Label la5 = new Label("자료구조");
        Label la6 = new Label("DB");
 
        la1.setBounds(43, 40, 50, 50);
        add(la1);
        la2.setBounds(43, 80, 50, 50);
        add(la2);
        la3.setBounds(43, 120, 50, 50);
        add(la3);
        la4.setBounds(43, 160, 50, 50);
        add(la4);
        la5.setBounds(43, 200, 50, 50);
        add(la5);
        la6.setBounds(43, 240, 50, 50);
        add(la6);
 
        // 입력란
        TextField text1 = new TextField(50);
        TextField text2 = new TextField(50);
        TextField text3 = new TextField(50);
        TextField text4 = new TextField(50);
        TextField text5 = new TextField(50);
        TextField text6 = new TextField(50);
 
        text1.setBounds(120, 55, 70, 20);
        add(text1);
        text2.setBounds(120, 95, 70, 20);
        add(text2);
        text3.setBounds(120, 135, 70, 20);
        add(text3);
        text4.setBounds(120, 175, 70, 20);
        add(text4);
        text5.setBounds(120, 215, 70, 20);
        add(text5);
        text6.setBounds(120, 255, 70, 20);
        add(text6);
 
        CheckboxGroup group;
        Checkbox Qcb1, Qcb2, Qcb3, Q1cb1, Q1cb2, Q1cb3; // 체크란
        Q = new Label("음악선택");
 
        Qcb1 = new Checkbox("재즈");
        Qcb2 = new Checkbox("클래식");
        Qcb3 = new Checkbox("팝");
 
        Q1 = new Label("좋아하는음식");
        Q1cb1 = new Checkbox("짜장");
        Q1cb2 = new Checkbox("짬뽕");
        Q1cb3 = new Checkbox("볶음밥");
 
        Q.setBounds(43, 300, 100, 20); // 음악선택
        add(Q);
 
        Qcb1.setBounds(30, 350, 50, 20);
        add(Qcb1);
        Qcb2.setBounds(80, 350, 60, 20);
        add(Qcb2);
        Qcb3.setBounds(140, 350, 100, 20);
        add(Qcb3);
 
        Q1.setBounds(43, 400, 80, 20); // 좋아하는음식
        add(Q1);
 
        Q1cb1.setBounds(30, 450, 40, 20);
        add(Q1cb1);
        Q1cb2.setBounds(80, 450, 50, 20);
        add(Q1cb2);
        Q1cb3.setBounds(140, 450, 55, 20);
        add(Q1cb3);
 
        Q2 = new Label("좋아하는 사람");
        Choice choice = new Choice(); // 초이스메뉴
        choice.add("김태희");
        choice.add("송혜교");
        choice.add("전지현");
        choice.add("김사랑");
        choice.add("진세연");
 
        Q2.setBounds(300, 60, 100, 20);
        add(Q2);
 
        choice.setSize(100, 50);
        add(choice);
        choice.setLocation(300, 80);
        add(choice);
 
        Q3 = new Label("좋아하는영화");
 
        List select = new List(6);
 
        select.setLocation(300, 150); // 리스트좌표
        select.setSize(150, 100); // 리스트 크기
 
        select.add("엑스맨");
        select.add("아바타");
        select.add("스파이더맨");
        select.add("어벤져스");
 
        Q3.setBounds(300, 120, 100, 20);
        add(Q3); // 좋아하는영화 제목 좌표
 
        select.setSize(100, 100);
        add(select);
        select.setSize(100, 30);
        add(select);
        select.setSize(100, 30);
        add(select);
        select.setSize(100, 30);
        add(select);
 
        Q4.setBounds(450, 55, 50, 20); // 출력 제목 좌표
        add(Q4);
 
        TextArea ta = new TextArea("아무거나...", 10, 50); // 출력 텍스트 칸
        ta.setBounds(450, 80, 350, 250);
        add(ta);
 
        // 버튼
        Button button1 = new Button("계산");
        Button button2 = new Button("배열저장");
        Button button3 = new Button("배열출력");
        Button button4 = new Button("파일저장");
        Button button5 = new Button("종료");
 
        button1.setBounds(300, 400, 80, 30);
        add(button1);
        button2.setBounds(400, 400, 80, 30);
        add(button2);
        button3.setBounds(500, 400, 80, 30);
        add(button3);
        button4.setBounds(600, 400, 80, 30);
        add(button4);
        button5.setBounds(700, 400, 80, 30);
        add(button5);
 
        boolean bool = true;
        this.setVisible(bool);
        this.addWindowListener(new MyListener());
 
    }
 
}
 
public class MyWindow {
    public static void main(String[] ar) {
 
        Windows windows = new Windows("성적처리 프로그램");
 
    }
}

2. MyListener.java


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
package Window;
 
import java.awt.*;
import java.awt.event.*;
 
public class MyListener implements WindowListener {
    public void windowClosing(WindowEvent ev) {
        System.exit(0);
    }
 
    public void windowActivated(WindowEvent ev) {
    }
 
    public void windowClosed(WindowEvent e) {
    }
 
    public void windowDeactivated(WindowEvent e) {
    }
 
    public void windowDeiconified(WindowEvent e) {
    }
 
    public void windowIconified(WindowEvent e) {
    }
 
    public void windowOpened(WindowEvent e) {
    }
}



'프로그래밍 > Java Programming' 카테고리의 다른 글

학생성적관리시스템 AWT  (0) 2018.04.07
자바 도서관리 AWT  (0) 2018.04.07
자바 강수량 구하기 AWT  (0) 2018.04.07
스레드 파일입력  (0) 2018.04.06
스레드 Thread 기본  (0) 2018.04.06
댓글
공지사항
글 보관함
최근에 올라온 글
최근에 달린 댓글