본문 바로가기

JAVA/UI

AWT

  Application -> App
 
  자동화 기능 -> Application(C#)문법, 독립적 환경
  Web -> editor 환경
 
  AWt, swing -> User Interface(연결)
 
  AWT(Abstract Window Toolkit) == 문법이 Android와 매우 유사
  에서 쓰이는  button, label, textField..를 보유
 
  Application <==> Database
  JDBC
 
  안드로이드 공부 : 구글에서 안드로이드 스튜디오 검색 -> 무료설치
  안드로이드 기기 연결 검색.. 독학

 

 

new WindowTest();
new WindowTest1();  
new WindowTestJ();

 

Main 테스트 번갈아가며 실행하면 위 사진처럼 됨

public class mainClass {

	public static void main(String[] args) {

		new WindowTest();//인스턴스 필요없어 생성만 함
		//new WindowTest1();
		//new WindowTestJ();
	}
}

테스트 -> 닫았다 열때마다 콘솔에 메세지가 뜸

public class WindowTest extends Frame implements WindowListener{
	
	public WindowTest() {
		
		setSize(640, 480);//해상도 입력(윈도우의 폭과 높이)
		setLocation(0, 0);//윈도우 실행 위치 -> 0,0은 좌측 상단
		setVisible(true);//true 면 윈도우가 보이게 됨 (시각화)
		
		//Listener 동작 
		addWindowListener(this);//현재 리스너가 어디 들어가있는지, this-> 현재클래스 
	}

	@Override
	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub
		System.out.println("windowActivated");
	}
	@Override
	public void windowClosed(WindowEvent e) {
		// TODO Auto-generated method stub
		System.out.println("windowClosed");
	}
	@Override
	public void windowClosing(WindowEvent e) {
		// TODO Auto-generated method stub
		System.out.println("windowClosing");
		System.exit(0);//창의 X버튼(종료버튼) 누르면 창 닫힘이 됨
	}
	@Override
	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub
		System.out.println("windowDeactivated");
	}
	@Override
	public void windowDeiconified(WindowEvent e) {
		// TODO Auto-generated method stub
		System.out.println("windowDeiconified");
	}
	@Override
	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub
		System.out.println("windowIconified");
	}
	@Override
	public void windowOpened(WindowEvent e) {
		// TODO Auto-generated method stub
		System.out.println("windowOpened");
	}
}

테스트1 -> 색상 넣어줌, 창에 제목 입력가능

public class WindowTest1 implements WindowListener {

	public WindowTest1() {
		Frame frame = new Frame();
		
		frame.setTitle("제목");
		frame.setSize(640, 480);
		frame.setLocation(100, 100);
		frame.setBackground(Color.red);
		
		frame.setVisible(true);
		
		frame.addWindowListener(this);
		
	}
	@Override
	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub
	}
	@Override
	public void windowClosed(WindowEvent e) {
		// TODO Auto-generated method stub
	}
	@Override
	public void windowClosing(WindowEvent e) {
		// TODO Auto-generated method stub
		System.exit(0);
	}
	@Override
	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub
	}
	@Override
	public void windowDeiconified(WindowEvent e) {
		// TODO Auto-generated method stub
	}
	@Override
	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub
	}
	@Override
	public void windowOpened(WindowEvent e) {
		// TODO Auto-generated method stub
	}
}

JFrame (swing)으로 간편히 처리

public class WindowTestJ extends JFrame{
//awt를 간단하게 만든게 swing
	
	public WindowTestJ() {
		
		setSize(800, 600);
		setLocation(200, 100);
		
		setVisible(true);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}

'JAVA > UI' 카테고리의 다른 글

가위바위보 게임 프로그램  (0) 2020.06.12
label / 확인창 뜨게하기  (0) 2020.06.11
Observer  (0) 2020.06.11
Label 과 Panel  (0) 2020.06.11
Lable  (0) 2020.06.11