프로그래밍/Java Programming

AWT 기본만들기

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

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


1. MyWindow.java


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


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) {
	}
}