2013년 8월 27일 화요일

자바AWT Window,Frame,Font,Color [오라클교육오라클자바교육강의강좌,자바교육,ORACLEJAVA교육강의강좌]

경계바, 타이틀바, 메뉴바가 없는 컴포넌트, 거의 직접 사용되지 않습니다.

오라클자바커뮤니티에서 설립한  개발자실무교육6년차 오엔제이프로그래밍 실무교육센터
(신입사원채용무료교육, 오라클, SQL, 튜닝, 자바, 스프링, Ajax, jQuery, 안드로이드, 아이폰, 닷넷, C#, ASP.Net)   www.onjprogramming.co.kr


그다지 유용하지 않으며 확장하여 사용하거나, ToolTip, PopUp메뉴와 같은 특수한 용도로 사용 합니다.

Window및 그 하위컴포넌트는 다른 컴포넌트에 포함되지않는 최상위 Component

Window및 Dialog 컴포넌트는 부모 컴포넌트로 Frame 컴포넌트를 지정해야만 그 객체를 생성할 수 있습니다.

Window객체를 사용해서 팝업 메뉴를 구현할 수 있으며 창의 기본 배치 관리자는 BorderLayout

WindowOpened나 WindowClosed와 같은 창 이벤트를 생성할 수 있습니다.



생성자 : Window(Frame owner), Window(Window owner), Window(Window owner, GraphicConfiguration gc)

메소드

addNotify() : Window의 피어(peer)를 작성.

addWindowListener(WindowListener) : 지정된 Window 수신기(listener)를 추가하여 Window으로부터 Window 이벤트를 수신.

dispose() :Window에 사용한 자원을 해제 할 때 사용

getFocusOwner() : Window가 활성화된 경우에만 Focus가 있는 창의 하위 컴포넌트를 Return

getOwner() : Window의 Owner를 Return

getOwnedWindows() : 현재 Window를 소유하고 있는 Window 배열을 Return

isShowing() : Windwo가 화면에 나타나 있는지 여부를 점검 합니다.

pack() : Window의 하위 컴포넌트를 환경설정된 크기로 배치 합니다. (최적크기)

processEvent(AWTEvent) : window에 대한 이벤트를 처리 합니다.

processWindowEvent(WindowEvent) : Window에서 발생하는 Window 이벤트를 등록된 WindowListener 객체로 보내 처리 합니다.

removeWindowListener(WindowListener) : Window Event Listener를 제거

show() : Window를 표시하고 앞으로 가져 옵니다.

toBack() : Window를 뒤로 보냅니다.

toFront() : Window를 앞으로 가져 옵니다.





------------------------

java.awt.Frame

--------------------

메소드

Frame() : 초기에는 보이지 않는 Frame의 새로운 인스턴스를 구성

Frame(String) : 지정된 제목으로 초기에는 보이지 않는 새로운 Frame 객체를 구성

getTitle() : 프레임의 제목을 가져옴

setTitle(String) : 프레임의 제목을 Set

isResizable() : 프레임 크기를 재조정할 수 있는지를 표시

getIconImage() : 프레임의 아이콘 이미지를 가져 옵니다.

setIconImage(Image) : 프레임이 아이콘으로 될 때 이미지가 표시되도록 설정

getMenuBar() : 프레임의 메뉴 막대를 가져 옵니다.

setMenuBar(MenuBar) : 지정된 메뉴 막대로 프레임의 Menu component를 설정 합니다.


remove(MenuComponent) : 프레임에서 지정된 Menu Component를 제거





-----------------------

java.awt.Color

-----------------------

java.awt.Object --> java.awt.Color

Paint Interface 구현한 글래스, RGB형식을 사용하여 색을 캡슐화 --> (0,0,0) 검정, (255,255,255) 흰색

색의비교 equals(), Color객체의 getRGB()를 이용


생성자

Color(float, float, float) : 지정된 빨강, 초록, 파랑 값을 사용하여 색상을 만들며, 각 값의 범위는 0.0-1.0

Color(float, float, float, float) : 지정된 빨강, 초록, 파랑 값을 사용하여 색상을 만들며, 불투명도 추가(0.0~1.0)

Color(int) : 지정된 RGB 값으로 색을 만든다. 빨강 컴포넌트는 16-23 비트 인수, 초록 컴포넌트는 8-15 비트 인수, 파랑 컴포넌트는 0-7 비트 인수.

Color(int, int) : ,RGB색상, 불투명도를 정수(0~255)로 나타냄

Color(int, int, int) : 지정된 빨강, 초록, 파랑 컴포넌트로 색을 만듬. (0~255)

Color(int, int, int, int) : 지정된 빨강, 초록, 파랑 컴포넌트로 색을 만듬, 마지막 인자는 불투명도를 나타내는 값(0~255)

Color(ColorSpace, float[], float) : 지정된 ColorSpace, color components float배열,불투명도를 이용해 색을 만듬.



메소드

brighter() : 색을 더 밝게

darker() : 색을 더 어둡게

equals(Object) : 다른 객체가 이 색과 같은지를 결정. 색의 비교시 사용

getBlue() : 색의 파랑 컴포넌트를 가져옴. (0~255)

getColor(String) : 시스템 특성에서 색을 찾는다. String은 시스템 특성

getColor(String, Color) : 시스템 특성에서 색을 찻는다. 지정된 특성이 없거나 정수로 분석될 수 없으면, 두 번째 인수가 지정한 색상이 대신 리턴 됩니다.

getColor(String, int) : 시스템 특성에서 색을 찾습니다. 지정된 특성이 없거나 정수로 분석될 수 없으면, 정수값(int)이 대신 사용되고 색으로 변환

getGreen() : 색의 초록 컴포넌트를 가져온다. (0~255)

getRed() : 색의 빨강 컴포넌트를 가져온다. (0~255)

getRGB() : 기본 RGB ColorModel에 있는 색을 표시하는 RGB 값을 가져옵니다. 리턴되는 정수의 24-31 비트는 0xff를, 16-23 비트는 빨강 값을, 8-15 비트는 초록 값을, 0-7 비트는 파랑 값을 나타 냅니다.




--------------------------------

java.awt.Font - 사용방법

----------------------------

버튼을 생성한 후에 버튼의 라벨을 TimesRoman 형 폰트에 진한 글씨로 크기를 20으로 하고자 할 경우 다음과 같이 설정할 수 있습니다.

Button btn = new Button("확인"); Font font = new Font("TimesRoman", Font.BOLD, 20); btn.setFont(font);

그래픽 컨텍스트에 그려지는?글자에 폰트를 지정하는 방법은 다음과 같습니다.

public void paint(Graphics g) {

Font f = new Font("TimesRoman", Font.BOLD, 20);

g.setFont(f);

g.drawString("Hello, World!", 10, 10);

}


자바 폰트 이름 X 윈도우 폰트 이름 윈도우즈 폰트 이름

Helvetica adobe-hevetica Arial

TimesRoman adobe-times Times New Roman

Courier adobe-courier Courier New

Dialog b&h-lucida MS Sans Serif

DialogInput b&h-lucidatypewriter MS Sans Serif

ZapfDingbats itc-zapfdingbats WingDings

default misc-fixed Arial



[예제] // 폰트 패밀리, 논리폰트명 출력

import java.awt.*;
class FontSample {
static Font font1 = new Font("TimesRoman", Font.ITALIC, 45);
static Font font2 = new Font("Helvetica", Font.BOLD, 12);
static Font font3 = new Font("Verdana", Font.PLAIN, 16);
public static void main(String args[]) {
System.out.println("family name of font1 : " + font1.getFamily());
System.out.println("family name of font2 : " + font2.getFamily());
System.out.println("family name of font3 : " + font3.getFamily());
System.out.println("name of font1 : " + font1.getName());
System.out.println("name of font2 : " + font2.getName());
System.out.println("name of font3 : " + font3.getName());
System.out.println("style of font1 : " + font1.getStyle());
System.out.println("style of font2 : " + font2.getStyle());
System.out.println("style of font3 : " + font3.getStyle());
System.out.println("size of font1 : " + font1.getSize());
System.out.println("size of font2 : " + font2.getSize());
System.out.println("size of font3 : " + font3.getSize());
} }



[예제] // 논리 Font명 및 시스템속성

import java.awt.*;
import java.util.*;
public class SysInfo {
public static void main(String[] args) {
Toolkit thekit = Toolkit.getDefaultToolkit();
System.out.println("\n Screen Resolution : " + thekit.getScreenResolution() + "dots per inch");
Dimension screenDim = thekit.getScreenSize();
System.out.println("Screen Size : " + screenDim.width + " by "+screenDim.height + " pixels");
GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
String[] fontnames = e.getAvailableFontFamilyNames();
System.out.println("\n----- fonts available on this flatform ----");
for(int i=0; i<fontnames.length; i++) { System.out.println(fontnames[i]); }
//System Properties
System.out.println("---- System Properties...... ----");
Properties p = System.getProperties();
p.list(System.out);
}
}



[예제] // CharaterIterator/StringIterator

import java.text.*;

class CharacterIteratorSample
{ public static void main(String[] args) {
//begin index:1, end index=4-1, current:1
CharacterIterator iter= new StringCharacterIterator("abcde", 1, 4, 1);
System.out.println("CharacterIterator iter --> "+iter);
iterateBackward( iter );
}

public static void iterateBackward(CharacterIterator iter) {
for (char ch = iter.last(); ch != CharacterIterator.DONE; ch = iter.previous())
System.out.print(ch);
}
}

댓글 없음:

댓글 쓰기