[Java] java.awt 패키지 - 컴퍼넌트 클래스의 종류와 메서드

chael_lo·2021년 5월 24일
0

Java

목록 보기
39/52

컴퍼넌트 클래스 종류

  • Button: 버튼을 구현한 컴퍼넌트 클래스다. 버튼라벨이 설정가능하다.
  • Label
  • Canvas
  • List
  • Checkbox
  • Choice
  • Scrollbar
  • TextField: 텍스트를 한 줄 입력하거나 출력하기 위한 컴퍼넌트 클래스다.
  • TextArea: 텍스트를 여러 줄 입력하거나 출력하기 위한 컴퍼넌트 클래스다.
  • MenuBar, Menu, MenuItem: MenuBar, Menu, MenuItem 포스팅 바로가기

컴포넌트 메서드의 종류

Component.setSize(int width, int height)

컴퍼넌트의 크기(폭과 높이)를 변경하는 메소드다.
GUI 프로그램에서는 위치 또는 크기 단위로 픽셀을 사용한다.
픽셀(Pixel) : 하나의 색을 출력할 수 있는 점(Dot)

f.setSize(300, 400);

Component.setLocation(int x, int y)

컴퍼넌트의 출력위치(x 좌표와 y좌표)를 변경하는 메소드다.

f.setLocation(600, 100);

Component.setBounds(int x, int y, int width, int height)

컴퍼넌트의 출력위치와 크기를 변경하는 메소드다.

f.setBounds(600, 100, 300, 400);

Component.setVisible(boolean b)

컴퍼넌트의 화면 출력 여부를 설정하는 메소드다.
컨테이너에 대한 설정은 컨테이너에 부착된 컴퍼넌트에 영향을 미친다.
false : 미출력(기본), true : 출력

f.setVisible(true);

Component.setFont(Font f)

컴퍼넌트의 글자 관련 속성을 변경하는 메소드다.
Font는 글자 관련 속성을 저장하기 위한 클래스다.

Component.Font(String name, int style, int size)

name(글꼴), style(스타일), size(크기) 컨테이너의 디자인 관련 속성을 변경하면 종속된 컴퍼넌트의 디자인 관련 속성도 변경할 수 있다.

textfield.setFont(new Font(Font.SERIF, Font.BOLD+Font.ITALIC, 16));

Component.setForeground(Color c)

컴퍼넌트의 글자색을 변경하는 메서드다.
Color는 색상정보(RED:0~255, GREEN:0~255, BLUE: 0~255)를 저장하기 위한 클래스다.

red.setForeground(new Color(255, 0, 0));
green.setForeground(new Color(0, 255, 0));
blue.setForeground(new Color(0, 0, 255));

Component.setEnabled(boolean b)

컴퍼넌트의 활성 여부를 설정하기 위한 메소드다.
false: 컴퍼넌트 비활성, true: 컴퍼넌트 활성(기본)

red.setEnabled(false);

Component.setEditable(boolean b)

텍스트 컴퍼넌트의 텍스트 입력 기능 사용 여부를 설정하기 위한 메서드다.
false: 입력 기능 비활성, true: 입력 기능 활성(기본)

textarea.setEditable(false);

Component.setFocusable(boolean b)

컴퍼넌트의 입력 촛점 위치 여부를 설정하기 위한 메서드다.
false: 입력 촛점 위치 불가능, true: 입력 촛점 위치 가능(기본)

textarea.setFocusable(false);
profile
천천히 꾸준히

0개의 댓글