DAY 10
✍️ AWT , Swing
✏️ Swing Components => GUI 클래스로 만들어진 일종의 GUI틀 / 여러개를 조합해서 하나로 만들어서 구현되는대상
AWT 기능
1. 사용자 components 제공
2. 이벤트 핸들링 모델 제공
3. 그래픽과 이미지 툴킷
4. 레이아웃 매니저를 이용해 container 툴 구현
5. 데이터 전송할수 있는 클래스 연동
- AWT와 Swing 차이
1. 상속관계
2. 기능의 차이
3. 해상도 차이
✏️ AWT
=> Frame은 윈도우객체(브라우저 상단, 창 축소 확대 등)를 상속,
윈도우에서 가져오는 기능 (윈도우에서 바꿔야 자바의 frame이 바뀜 / 윈도우에서 발생할 수 있는 이벤트)
=> Container은 배치관리자
=> Component 1) visual component
- button, check box, label 등등
2) Container`s component
- frame, panel, dialog, menu(menuitem,menubar)
vs component ---------> container`s component
add
- frame -> container -> component
전체적인 frame안에 배치관리자가 있고 그 안에 component들을 올린다
✏️ 추상클래스를 살펴보자
객체 생성이 아닌 주소를 대입받을 수 있는 경우로 객체의 메소드의 return형이 추상 클래스인 경우를 사용함
// 1. 현재 사용하고 있는 전체영역의 gui를 환경값 ge라는 객체로 리턴 받는다.
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
// 2. 모니터 환경설정 값들을 gs로 리턴받는다.
GraphicsDevice [] gs = ge.getScreenDevices();
// 3. 각각의 디바이스 환경 설정 값들을 res로 출력한다.
for(GraphicsDevice res : gs){
GraphicsConfiguration gc = res.getDefaultConfiguration();
Frame f = new Frame (gc);
Rectangle bounds = gc.getBounds();
f.setLocation(10 + bounds.x.10+ bounds.y);
f.setSize(bounds.width,bounds.height);
f.setVisible(true)
}
// GraphicsEnvironment -> ge.getScreenDevices() -> GraphicsDevice ->public abstract class GraphicsConfiguration -> Ractangle
//1.GraphicsEnvironment 이용해서 값을 받아오고
//2. getScreenDevices 리턴이 GraphicsDevice
//3.GraphicsDevice 리턴이 GraphicsConfiguration
//4.getBounds를 통해 Rectangle로 리턴, width,height가져옴
// => 원하는 위치에 프레임을 놓고 싶다. (현재 환경설정에 맞는)
// Frame (GraphicsConfiguration gc)로 생성하는 경우 현재 프레임이 생성될 환경의 모니터가 가진 설정값으로 프레임을 생성하겠다.
BorderLayout Im = new BorderLayout()
public LayoutManager getLayout(){
return new BorderLayout();
}
LayoutManager는 선조 , return new BorderLayout(); 후손의 객체를 생성해서 리턴
후손의 객체를 생성해서 선조의 객체의 주소번지로 받았다 -> 동적바인딩의 원칙 , 다형성(다양한 형태의 성질을 가지고있는 후속 클래스를 선택해서 사용)
✍️ 추상클래스와 인터페이스 연동
1. implements WindowListener / 모든 메소드를 재정의
2. 익명으로 재정의 하는 방법
3. 추상클래스로 대처하는 방법
4. inner class를 선언해서 extends or implements한다.