본문 바로가기

Java/Method

AWT Method II

Font

Method

Explain

Font(String name, int style, int size)

name : 사용할 Font의 이름     style : Font의 Style 지정     size : Font의 크기


Color

Method

Explain

Color(int r, int g, int b)

0~255의 정수 값을 이용해 색 조절(r : red / g : green / b : blue)

Color(float r, float g, float b)

0.0~1.0의 정수 값을 이용해 색 조절(r : red / g : green / b : blue)

Color(int r, int g, int b, int a)

a : Alpha 값이 추가되어 있으며 0~255사이의 정수 값을 갖음

Color(float r, float g, float b, float a)

a : Alpha 값이 추가되어 있으며 0.0~1.0사이의 정수 값을 갖음


BorderLayout

Method

Explain

BorderLayout(int hgap, int vgap)

각 영역 사이에 간격이 있는 BorderLayout을 생성

hgap : 각 영역 사이에 좌우 간격을 줌

vgap : 각 영역 사이에 위아래 간격을 줌

BorderLayout()

영역 사이에 간격이 없는 BorderLayout을 생성

add(String name, Component c)

add(Component c, String name)

c : 추가하려는 Component

name : 추가하는 영역 선택

(BorderLayout.NORTH/BorderLayout.SOUTH/BorderLayout.EAST

/BorderLayout.WEST/BorderLayout.CENTER)


FlowLayout

Method

Explain

FlowLayout(int align, int hgap, int vgap)

align : Component들의 정렬 방법 지정

(FlowLayout.LEFT/FlowLayout.RIGHT/FlowLayout.CENTER)

hgap : 각 Component 사이에 좌우 간격을 줌
hgap : 각 Component 사이에 위아래 간격을 줌

FlowLayout(int align)

정렬 방법을 지정할 수 있는 hgap과 vgap이 5Pixel인 FlowLayout 생성

FlowLayout()

가운데 정렬이면서 hgap과 vgap이 5Pixel인 FlowLayout 생성


GridLayout

Method

Explain

GridLayout(int row, int col, int hgap, int vgap)

영역들 간의 사이에 간격이 있는 GridLayout을 생성

row : Container를 몇 개의 행으로 나눌 것인지 지정

col : Container를 몇 개의 줄로 나눌 것인지 지정

hgap : 각 영역 사이에 좌우 간격을 줌

vgap : 각 영역 사이에 위아래 간격을 줌

GridLayout(int row, int col)

영역들 간의 사이에 간격이 없는 GridLayout을 생성

row : Container를 몇 개의 행으로 나눌 것인지 지정

col : Container를 몇 개의 줄로 나눌 것인지 지정


CardLayout

Method

Explain

CardLayout(int hgap, int vgap)

hgap : Container와 CardLayout 사이에 좌우 간격을 줌

vgap : Container와 CardLayout 사이에 위아래 간격을 줌

CardLayout()

Container와 간격이 없는 CardLayout 생성

add(Container parent, String name)

주어진 이름으로 지정된 Container에 추가

show(Continer parnet, String name)

주저진 이름의 Component를 Container에 보여줌

first(Container parent)

perent : 지정된 Container에 첫 번째로 추가된 Component를 보여줌

last(Container parent)

perent : 지정된 Container에 마지막으로 추가된 Component를 보여줌

pervious(Container parent)

지정된 Container에 현재 보이는 Component보다 이전에 추가된 것을 보여주며 현재 보이는 것이 첫 번째 것일 경우 마지막 것이 나타남

next(Container parent)

지정된 Container에 현재 보이는 Component보다 다음에 추가된 것을 보여주며 현재 보이는 것이 마지막 것일 경우 첫 번째 것이 나타남


Event 종류와 관련 Interface 및 Method

Event

Interface

Method

Call Time

ActionEvent

ActionListener

actionPerformed(ActionEvent ae)

Button Click 시, Menu Click 시, TextField에서 Enter를 눌렀을 시, List의 item하나를 선택해 DoubleClick 시

Component

Event

ComponentListener

componentMoved(ActionEvent ae)

Component가 이동되었을 시

componentHidden(ActionEvent ae)

Component가 화면에 보이지 않게 되었을 시

componentResized(ActionEvent ae)

Component의 크기가 변경되었을 시

componentShown(ActionEvent ae)

Component가 화면에 보일 시

MouseEvent

MouseMotion

mouseDragged(MouseEvent me)

Mouse Button을 누른 채로 Mouse를 움직였을 시

mouseMoved(MouseEvent me)

Mouse Pointer를 이동시킬 시

MouseListener

mousePressed(mouseEvent me)

Mouse Button을 눌렀을 시

mouseReleased(mouseEvent me)

Mouse Button을 떼었을 시

mouseEntered(mouseEvent me)

Mouse Pointer가 Event Source의 영역 안으로 들어왔을 시

mouseExited(mouseEvent me)

Mouse Pointer가 Event Source의 영역 안에서 밖으로 이동할 시

mouseClicked(mouseEvent me)

Mouse Button을 눌렀다 떼었을 시

MouseWeelEvent

MouseWheelListener

mouseWeelMoved(MouseWeelEvent e)

Mouse Wheel의 휠을 움직였을 시

KeyEvent

KeyListener

keyPressed(KeyEvent e)

Keyboard의 Key 눌렀을 시

keyReleased(KeyEvent e)

Keyboard의 Key 떼었을 시

keyTyped(KeyEvent e)

Keyboard의 Key 눌렀다 떼었을 시

TextEvent

TextListener

textValueChanged(TextEvent te)

TextField 또는 Text Area의 내용이 변경되었을 시

FocusEvent

FocusListener

focusGained(FocusEvent fe)

Event Source로 Focus가 이동했을 시

focusLost(FocusEvent fe)

Event Source가 갖고 있던 Focus가 다른 Component로 이동했을 시

ItemEvent

ItemListener

itemStateChanged(ItemEvent ie)

Checkbox, CheckboxItem, List, Choice의 Status가 변경되었을 시

Adjustment

Event

AdjustmentListener

adjustmentValueChanged(AdjustmentEvent ae)

Scroll Bar의 값이 변경되었을 시

WindowEvent

WindowListener

windowClosing(WindowEvent we)

Window가 열렸을 시

windowOpening(WindowEvent we)

Window가 닫힐 시(닫기 Button을 눌렀을 시)

windowIconified(WindowEvent we)

Window가 닫혔을 시(dispose()가 호출되었을 시)

windowDeiconified(WindowEvent we)

Window가 최소화 되었을 시

windowClosed(WindowEvent we)

Window가 최소화 상태에서 다시 원래 크기로 되었을 시

windowActivated(WindowEvent we)

Window가 활성화 되었을 시

windowDeactivated(WindowEvent we)

Window가 비활성화 되었을 시

WindowFocusListener

windowGainedFocus(WindowEvent we)

Window가 Focus를 얻을 시

windowLostFocus(WindowEvent we)

Window가 Focus를 잃을 시

WindowStateListener

windowStateChanged(WindowEvent we)

Window의 상태가 변했을 시

ContainerEvent

ContainerListener

componentAdded(ContainerEvent ce)

Container에 Component가 추가되었을 시

componentRemoved(ContainerEvent ce)

Container에 Component가 삭제되었을 시


각 Event 별 주요 Method

Event

Class

Explain

ActionEvent

String getActionCommand()

Event의 ActionCommand를 반환

int getModifiers()

Event가 발생 시 누르고 있던 특수 Key 반환

long getWhen()

Event가 발생한 시간을 long값으로 반환

AdjustmentEvent

Adjustable getAdjustable()

Event Source를 반환

int getAdjustmentType()

값을 변경시킨 방법을 알려줌

int getValue()

Event 발생 시의 Scroll Bar의 값을 반환

boolean getValueIsAdjusting()

값이 변경되고 있는 중인지를 알려줌

ComponentEvent

Component getComponent()

Event Source를 반환

ContainerEvent

Component getChild()

Container에 추가/삭제된 Component 반환

Container getContainer

Event Source를 반환

FocusEvent

Component getOppositeComponent()

Focus를 잃은 Component를 반환

ItemEvent

Object getItem()

Event가 발생한 Item을 반환

ItemSelectable getItemSelectable()

Event Source 반환

int getStateChange()

Item의 상태를 반환

KeyEvent

char getKeyChar()

눌러진 Key를 반환

int getKeyCode()

눌러진 Key의 Code를 반환

String getKeyModifiersText(int modifiers)

눌러진 특수 Key(Ctrl, Alt) 또는 특수Key 조합을 설명하는 문자열 반환

String getKeyText(int keyCode)

눌러진 Key를 HOME, F1과 같이 Key를 설명하는 문자열로 반환

MouseEvent

int getClickCount()

Mouse를 클릭한 회수를 반환

Point getPoint()

Event가 일어난 위치를 반환

int getX()

Event가 일어난 위치의 x좌표를 반환

int getY()

Event가 일어난 위치의 y좌표를 반환

MouseWheelEvent

int getScrollAmount()

Scroll되어야하는 양을 반환

int getScrollType()

어떤 Scroll Type에 의해 Event가 발생했는지 알려줌

int getUnitsToScroll()

단위당 Scroll해야하는 양을 반환

int getWheelRotation()

Mouse Wheel이 이동한 방향을 알려줌

WindowEvent

int getNewState()

Window의 현재 상태를 반환

int getOldState()

Window의 이전 상태를 반환

Window getOppositeWindow()

Event 발생전 Focus를 가진 Window 반환

Window getWindow()

Event Source 반환

All Event Common

Object getSource()

Event Source 반환

paramString()

Event에 관련된 정보를 문자열로 반환


Event Listener를 Component에 추가/제거할 시 사용되는 Method

Listener

Listener를 추가/제거할 시 사용되는 Method

Event Source

ActionListener

void addActionListener(ActionListener I)

Button, List, MenuItem, TextField

void removeActionListener(ActionListener I)

Button, List, MenuItem, TextFieldAdjustmentListener

void addAdjustmentListener(AdjustmentListener I)

Scrollbar

void removeAdjustmentListener(AdjustmentListener I)

ScrollbarComponentListener

void addComponentListener(ComponentListener I)

Component

void removeComponentListener(ComponentListener I)

ComponentContainerListener

void addContainerListener(ContainerListener I)

Container

void removeContainerListener(ContainerListener I)

ContainerFocusListener

void addFocusListener(FocusListener I)

Component

void removeFocusListener(FocusListener I)

ComponentItemListener

void addItemListener(ItemListener I)

Checkbox,Choice, CheckboxMenuItem, List

void removeItemListener(ItemListener I)

Checkbox,Choice, CheckboxMenuItem, ListKeyListener

void addKeyListener(KeyListener I)

Component

void removeKeyListener(KeyListener I)

ComponentMouseListener

void addMouseListener(MouseListener I)

Component

void removeMouseListener(MouseListener I)

ComponentMouseMotionListener

void addMouseMotionListener(MouseMotionListener I)

Component

void removeMouseMotionListener(MouseMotionListener I)

ComponentTextListener

void addTextListener(TextListener I)

TextField, TextArea

TextListenervoid removeTextListener(TextListener I)

TextField, TextAreaWindowListener

void addWindowListener(WindowListener I)

Window

void removeWindowListener(WindowListener I)

WindowWindowFocusListener

void addWindowFocusListener(WindowFocusListener I)

Window

void removeWindowFocusListener(WindowFocusListener I)

WindowWindowStateListener

void addWindowStateListener(WindowStateListener I)

Window

void removeWindowStateListener(WindowStateListener I)


Graphics

Related

Method

Explain

문자

void drawString(String str, int x, int y)

(x, y) 위치에 문자열을 출력

문자Font getFont()

현재 설정되어 있는 Font를 얻음

문자void setFont(Font font)

출력할 문자열의 Font를 지정

문자FontMetrics getFontMetrics()

FontMetrics 객체 반환

Color getColor()

현재 설정되어 있는 Color를 얻음

색void setColor(Color c)

출력할 색을 지정

void drawLine(int x1, int y1, int x2, int y2)

선 그리기

타원

void drawOval(int x, int y, int width, int height)

타원 그리기

타원void fileOval(int x, int y, int width, int height)

둥근

사각형

void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)

둥근 사각형 그리기

둥근 사각형void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight)

입체

사각형

void draw3DRect(int x, int y, int width, int height, boolean raised)

입체 사각형 그리기

입체 사각형void fill3DRect(int x, int y, int width, int height, boolean raised)

void drawArc(int x, int y, int width, int height, int startAngel, int arcAngle)

호 그리기

호void fillArc(int x, int y, int width, int height, int startAngel, int arcAngle)

다각형

void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)

다각형 그리기

다각형void fillPolygon(int[] xPoints, int[] yPoints, int nPoints)

다각형 그리기다각형void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)

기타

void clearRect(int x, int y, int width, int height)

지정된 영역을 지움

기타boolean drawImage(Image img, int x, int y, ImageObserver observer)

(x, y)의 위치에 Image를 그림


Life cycle

Method

Explain

init()

Applet이 생성될 떄 호출되며 객체 생성이나 Image Loading 등, Applet의 초기화 작업에 사용된다.

생성자 다음에 호출된다.

start()

Applet의 실행이 시작 또는 재시작될 때 호출된다.

Web Browser가 Icon화 되었다가 화면에 나타날 때, init()이 호출된 직후에는 반드시 호출된다.

stop()

Applet의 실행을 중지 시킨다.

Web Browser가 Icon화 되던가 다른 Page로 이동할 때, destroy()가 호출되기 직전에 반드시 호출된다.

destroy

Web Browser가 닫히면서 Applet이 소멸되기 직전에 stop() 다음으로 호출된다.

Applet이 사용하던 자원을 반환하는 용도로 사용된다.







'Java > Method' 카테고리의 다른 글

AWT Method I  (0) 2015.09.05
Thread  (0) 2015.08.22
Random  (0) 2015.08.19
Properties  (0) 2015.08.19
TreeMap  (0) 2015.08.19