1 / 24

Introduction to Java AWT

Introduction to Java AWT. What is the AWT?. 자바의 윈도우 시스템인 추상 윈도우 툴킷 (Abstract Window Toolkit) 에 관련된 클래스들로 구성 java.applet.Applet 클래스가 java.awt.Panel 에서 파생되었기 때문에 애플릿의 이해를 위해서도 자세히 알아둘 필요가 있는 패키지 자바의 그래픽 사용자 인터페이스는 모두 AWT 패키지에 기반을 두고 있다. An Example. Class hierachy.

meliora
Download Presentation

Introduction to Java AWT

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Java AWT

  2. What is the AWT? • 자바의 윈도우 시스템인 추상 윈도우 툴킷(Abstract Window Toolkit)에 관련된 클래스들로 구성 • java.applet.Applet 클래스가 java.awt.Panel에서 파생되었기 때문에 애플릿의 이해를 위해서도 자세히 알아둘 필요가 있는 패키지 • 자바의 그래픽 사용자 인터페이스는 모두 AWT 패키지에 기반을 두고 있다

  3. An Example

  4. Class hierachy • class java.awt.Component (implements java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable) • class java.awt.Button • class java.awt.Canvas • class java.awt.Checkbox (implements java.awt.ItemSelectable) • class java.awt.Choice (implements java.awt.ItemSelectable) • class java.awt.Container • class java.awt.Panel • class java.applet.Applet • class java.awt.ScrollPane • class java.awt.Window • class java.awt.Dialog • class java.awt.FileDialog • class java.awt.Frame (implements java.awt.MenuContainer) • class java.awt.Label • class java.awt.List (implements java.awt.ItemSelectable) • class java.awt.Scrollbar (implements java.awt.Adjustable) • class java.awt.TextComponent • class java.awt.TextArea • class java.awt.TextField

  5. Component 클래스의 주요 메소드들(1/2) • public Container getParent() : 상위 윈도우를 구할 때 사용한다. • public Point getLocation() : 상위 윈도우의 좌표 공간에서 현재의 위치를 구한다. • public Dimension getSize() : 현재 크기를 구한다. Dimension은 높이와 폭으로 구성되는 클래스이다. • public synchronized void setEnabled(boolean b) : 인자 값에 따라 사용자 입력을 받을 수 있도록 혹은 없도록 한다. 기본 값은 입력을 받을 수 있는 것이다. • public synchronized void setVisible(boolean b) : 인자 값에 따라 화면에 나타내거나 화면에서 감춘다. • public synchronized void setForeground(Color c) : 주어진 색을 전경색으로 표시한다. • public synchronized void setBackground(Color c) : 주어진 색을 배경색으로 표시한다. • public void setLocation(int x, int y) : 새로운 위치로 이동시킨다. x, y 좌표는 상위 윈도우의 좌표 공간 값으로 주어진다. • public void setSize(int width, int height) : 주어진 폭과 높이로 윈도우 크기를 변경한다. • public synchronized void setBounds(int x, int y, int width, int height) : setLocation(x, y), setSize(width, height)를 연속으로 호출한 효과를 낸다.

  6. Component 클래스의 주요 메소드들(2/2) • public Graphics getGraphics() : 해당 윈도우에 그림을 그리기 위한 그래픽 컨텍스트(마이크로소프트 윈도우 시스템에서는 그래픽 장치 컨텍스트graphic device context라고 한다)를 얻을 때 사용한다. • public FontMetrics getFontMetrics(Font font) : 주어진 글꼴에 관련하여 글꼴 구조 정보를 구할 때 사용한다. 글꼴의 폭이나 높이 등을 구할 때 자주 사용한다. • public void paint(Graphics g) : 윈도우를 다시 그릴 때 AWT에 의해 불려진다. 이 메소드가 불려지는 때에는 처음으로 윈도우 컴퍼넌트가 화면에 나타날 때, 혹은 다른 윈도우에 의하여 가려졌다가 다시 나타날 때, 또 사용자가 직접 repaint() 메소드를 호출하였을 때 등이다. 마이크로소프트 윈도우 프로그래머는 WM_PAINT 메시지를 생각하면 쉽게 이해할 수 있다. • public void repaint() : AWT에게 컴퍼넌트를 완전히 다시 그리도록 요청한다. 이 명령은 실제로는 가능한 한 빨리 update()를 호출하도록 AWT에게 요청하는 것이 된다. • public void update(Graphics g) : repaint() 요청에 따라 AWT에 의해 호출된다. 현재 컴퍼넌트를 지운 다음 paint()를 호출하는 것이 기본 동작이다. • public void requestFocus() : 입력 포커스를 요청한다. • public void transferFocus() : 다음 윈도우로 입력 포커스를 옮긴다. • public void setCursor(Cursor cursor) : 컴퍼넌트의 마우스 커서를 변경한다.

  7. Container 클래스의 주요 메소드들 • public void setLayout(LayoutManager mgr) : 윈도우의 레이아웃 관리자를 지정한다. 레이아웃 관리자 클래스에는 BorderLayout, CardLayout, FlowLayout, GridBagLayout, GridLayout 등이 있다. 레이아웃 관리자 클래스를 사용하면 쉽게 하위 윈도우의 위치를 지정할 수 있고 또 윈도우의 크기가 변경되었을 때 자동으로 재배치할 수 있다. • public synchronized void doLayout() : 레이아웃 관리자에 의해 레이아웃을 한 후에 (하위 윈도우들을 생성한 후에) 호출하여 윈도우들을 유효화한다. 이 메소드를 코드에서 직접 호출하지 말고 대신에 validate()를 호출하여 결과적으로 doLayout()이 수행되도록 한다. • public synchronized Component[] getComponents() : 이 윈도우 내부의 모든 하위 윈도우들을 얻는다. • public Insets getInsets() : 이 윈도우의 인셋(inset)을 지정한다. 인셋은 내부의 하위 윈도우들과 네 방향(상하좌우)의 경계 부분의 크기를 말한다. 예를 들어 프레임 윈도우는 타이틀 바에 해당하는 위쪽 인셋을 가질 것이다. • public Component add(Component comp) : 인자로 주어진 윈도우를 하위 윈도우로 하여 내부에 배치한다. • public synchronized void remove(Component comp) : 지정된 하위 윈도우를 제거한다. • public synchronized void removeAll() : 모든 하위 윈도우들을 제거한다. • public LayoutManager getLayout() : 해당 윈도우의 레이아웃 관리자를 구한다.

  8. 레이아웃 관리자 클래스 • BorderLayout 클래스 • FlowLayout 클래스 • GridLayout 클래스 • GridBagLayout 클래스 • CardLayout 클래스

  9. BorderLayout 클래스(1/2) import java.awt.*; publicclass BorderLayoutApplet extends java.applet.Applet { publicvoid init () { Button northButton=new Button("North"); Button southButton=new Button("South"); Button eastButton=new Button("East"); Button westButton=new Button("West"); Button centerButton=new Button("Center"); setLayout(new BorderLayout()); add("East", eastButton); add("West", westButton); add("Center", centerButton); add("South", southButton); add("North", northButton); layout(); } }

  10. BorderLayout 클래스(2/2)

  11. FlowLayout 클래스(1/2) import java.awt.*; publicclass FlowLayoutApplet extends java.applet.Applet { publicvoid init () { Button oneButton=new Button("One"); Button twoButton=new Button("Two"); Button threeButton=new Button("Three"); setLayout(new FlowLayout(FlowLayout.RIGHT)); add(oneButton); add(twoButton); add(threeButton); validate(); } }

  12. FlowLayout 클래스(2/2)

  13. GridLayout 클래스(1/2) import java.awt.*; publicclass GridLayoutApplet extends java.applet.Applet { publicvoid init () { Button oneButton=new Button("One"); Button twoButton=new Button("Two"); Button threeButton=new Button("Three"); Button fourButton=new Button("Four"); Button fiveButton=new Button("Five"); Button sixButton=new Button("Six"); setLayout(new GridLayout(2, 3/*columns*/)); add(oneButton); add(twoButton); add(threeButton); add(fourButton); add(fiveButton); add(sixButton); validate(); } }

  14. GridLayout 클래스(2/2)

  15. GridBagLayout 클래스(1/2) • Source Code is a little long

  16. GridBagLayout 클래스(2/2)

  17. CardLayout 클래스(1/2)

  18. CardLayout 클래스(2/2)

  19. Reference • http://www.concentric.net/~ttwang/tech/queue.htm

More Related