Hello html 1 applet codeHello class width200 height150

  • Slides: 60
Download presentation

예제 예제 : Hello. html 1 <applet code=Hello. class width=200 height=150> % appletviewer 2

예제 예제 : Hello. html 1 <applet code=Hello. class width=200 height=150> % appletviewer 2 </applet> 예제 : Hello. java 1 import java. awt. *; 2 import java. applet. *; 3 4 public class Hello extends Applet { 5 private String Greeting[] = { 6 "Hello, world" 7 }; 8 9 public void paint(Graphics g){ 10 g. draw. String(Greeting[0], 25); 11 } 12 } Hello. html

자바 애플릿 웹페이지 등록하기 n n HTML에서 applet 태그는 웹에서 애플릿 등록을 위한 태그

자바 애플릿 웹페이지 등록하기 n n HTML에서 applet 태그는 웹에서 애플릿 등록을 위한 태그 실제 애플릿은. class 파일에 저장되어 있고, applet 태그는 애플릿 클래스 파일을 기술 <applet codebase archive align name vspace hspace width height </applet> n = = = = = classfile. class directory archivefile. zip aligndirection appletname 20 30 200 100 > applet 태그에서 code, width, height 어트리뷰트는 항상 존재해야

예제 : Hello. Param. java 1 import java. awt. *; 2 import java. applet.

예제 : Hello. Param. java 1 import java. awt. *; 2 import java. applet. *; 3 4 public class Hello. Param extends Applet { 5 String message = ""; 6 7 public void init() { 8 message = get. Parameter("msg"); 9 if(message == null) 10 message = "Hello"; 11 } 12 13 public void paint(Graphics g) { 14 g. draw. String(message, 25); 15 } 16 } Hello. Param. html 파일 1 <applet code=Hello. Param. class width=300 height=200> 2 <param name="msg" value="안녕하세요"> 3 </applet>

Graphics 클래스 n 그래픽 컨텍스트(폰트, 컬러 등)와 draw. XXX() 메소 드들로 구성 draw. String(String

Graphics 클래스 n 그래픽 컨텍스트(폰트, 컬러 등)와 draw. XXX() 메소 드들로 구성 draw. String(String msg, int x, int y) n draw. Line(int x 1, int y 1, int x 2, int y 2) n

Graphics 클래스 n draw. Rect(int x, int y, int w, int h) n draw.

Graphics 클래스 n draw. Rect(int x, int y, int w, int h) n draw. Oval(int x, int y, int w, int h)

Graphics 클래스 n n draw. Round. Rect(int x, int y, int w, int h,

Graphics 클래스 n n draw. Round. Rect(int x, int y, int w, int h, int rw, int rh) draw. Arc(int x, int y, int w, int h, int a, int b)

Graphics 클래스 n fill. XXX() 메소드 n n n 도형을 그리고 내부를 색으로 채우는

Graphics 클래스 n fill. XXX() 메소드 n n n 도형을 그리고 내부를 색으로 채우는 메소드 fill. Rect(int x, int y, int w, int h) fill. Oval(int x, int y, int w, int h) fill. Round. Rect(int x, int y, int w, int h, int rw, int rh) fill. Arc(int x, int y, int w, int h, int a, int b)

예제 : Img. Test. java 1 import java. awt. *; 2 3 import java.

예제 : Img. Test. java 1 import java. awt. *; 2 3 import java. applet. Applet; 4 5 public class Img. Test extends Applet { 6 7 Image duke; 8 9 public void init() { 10 duke = get. Image(get. Document. Base(), "duke. gif"); 11 } 12 13 public void paint(Graphics g) { 14 g. draw. Image(duke, 25, this); 15 } 16 }

예제 : Audio. Test. Two. java 1 import java. awt. *; 2 import java.

예제 : Audio. Test. Two. java 1 import java. awt. *; 2 import java. applet. *; 3 4 public class Audio. Test. Two extends Applet { 5 Audio. Clip sound; 6 7 public void init() { 8 sound=get. Audio. Clip(get. Code. Base(), "bark. au"); 9 } 10 11 public void paint(Graphics g) { 12 g. draw. String("Audio Test", 25); 13 } 14 public void start() { 15 sound. loop(); 16 } 17 public void stop() { 18 sound. stop(); 19 } 20 }

더블 버퍼링 기법 n 이미지를 메모리에 먼저 그린 다음 화면에 출력하는 방법 n 예제

더블 버퍼링 기법 n 이미지를 메모리에 먼저 그린 다음 화면에 출력하는 방법 n 예제 : Clock. java ………. . . 6 public class Clock extends Applet implements Runnable { …………. 23 img = create. Image(w, h); 24 gc = img. get. Graphics(); …………. . 43 gc. draw. String(day. to. String(), 5, h -d); 44 repaint(); …………. . . 53 public void update(Graphics g) { 54 paint(g); 55 } 56 57 public void paint(Graphics g) { 58 g. draw. Image(img, 10, 50, this); 59 }

예제 : Hello. Two. java …………. 4 public class Hello. Two extends Applet {

예제 : Hello. Two. java …………. 4 public class Hello. Two extends Applet { 5 String msg; 6 Button ok; 7 8 public void init() { 9 set. Layout(new Border. Layout()); 10 msg = "Hello World. . "; 11 ok = new Button("OK"); 12 add("South", ok); 13 } 14 15 public void paint(Graphics g) { 16 g. draw. String(msg, 25); 17 } 18 19 public static void main(String args[]) { 20 Frame f = new Frame("Application"); 21 Hello. Two hello = new Hello. Two(); 22 hello. init(); 23 hello. start(); 24 f. add(hello, "Center"); 25 f. set. Size(300, 200); …………. .

결과 % java Hello. Two % appletviewer Hello. Two. html

결과 % java Hello. Two % appletviewer Hello. Two. html

Applet. Context를 이용하는 방법 q HTML <applet code=Using. Applet. Context. Receiver. class name="receiver" width=300

Applet. Context를 이용하는 방법 q HTML <applet code=Using. Applet. Context. Receiver. class name="receiver" width=300 height=100> </applet> q Applet Using. Applet. Context. Receiver r = (Using. Applet. Context. Receiver) get. Applet. Context(). get. Applet("receiver"); n get. Applets() 메소드의 사용 방법도 get. Applet() 메소드와 유사 n Applet. Context 문제점 n n n 웹브라우저에서 애플릿은 비동기적으로 클래스들이 로드되기 때문 에 한 클래스에서 다른 클래스가 로드되어 있는지 알기 어렵다. 애플릿이 로드되지 않으면 get. Applet() 메소드 이용 불가 한 페이지 내에 있는 애플릿 간의 통신만 가능

색 n java. awt. Color 클래스 n n n 많이 사용하는 색은 상수로 정의

색 n java. awt. Color 클래스 n n n 많이 사용하는 색은 상수로 정의 많이 사용되지 않는 색은 RGB(Red Green Blue) 값으로 정의 Color 클래스의 상수로 정의된 색 Color. black Color. blue Color. cyan Color. dark. Gray Color. gray n Color. green Color. light. Gray Color. magenta Color. orange Color. pink Color. red Color. white Color. yellow 생성자 Color(int r, int g, int b) - r, g, b 는 0 ~ 255 사이의 값을 갖는다. Color(float r, float g, float b) - r, g, b 는 0. 0 ~ 1. 0 사이의 값을 갖는다.

예제 : Applet. Menu. java …………. 5 public class Applet. Menu extends Applet {

예제 : Applet. Menu. java …………. 5 public class Applet. Menu extends Applet { ……. 9 Cursor wait. Cursor, default. Cursor; …………. . . 13 default. Cursor = get. Cursor(); 14 wait. Cursor = new Cursor(Cursor. WAIT_CURSOR); 15 Menu. Bar menubar = new Menu. Bar(); ………. 32 c = this; 33 while (c != null && !(c instanceof Frame)) { 34 c = c. get. Parent(); 35 } 36 ((Frame)c). set. Menu. Bar(menubar); ………. 63 if(25 <= x && x <= 125 && 25 <= y && y <= 125) { 64 set. Cursor(wait. Cursor); 65 return; 66 } 67 set. Cursor(default. Cursor); ………. . .

예제 : URLButton. java ……… 6 public class URLButton extends Applet implements Action. Listener

예제 : URLButton. java ……… 6 public class URLButton extends Applet implements Action. Listener { 7 URL url = null; 8 String title = null; 9 10 public void init() { ………. 19 try { 20 url = new URL(url. String); 21 }catch(Malformed. URLException e) { 22 System. out. println("Invalid URL: "+ url. String); 23 } 24 Button site = new Button(title); 25 site. add. Action. Listener(this); 26 site. set. Action. Command(title); 27 add(site); 28 } ………. 32 if(cmd. equals(title)) { 33 get. Applet. Context(). show. Document(url); 34 } ……. . .

5. 10 Java 2 D

5. 10 Java 2 D

렌더링 컨텍스트의 종류 n 클립(clip) n n 폰트 n n 문자열을 그림 형태로 표현한다.

렌더링 컨텍스트의 종류 n 클립(clip) n n 폰트 n n 문자열을 그림 형태로 표현한다. 렌더링 힌트 n n 형태의 일부만 화면에 보이도록 하는 것이다. 그림의 화질과 속도 중에서 어느 것을 우선할 것인가를 기술한다. 예: antialiasing 사용 여부 렌더링 컨텍스트에 속성 설정을 위한 set. XXX() 메소드 void set. Stroke(Stroke s) void set. Paint(Paint paint) void set. Composite(Composite comp) void set. Transform(Affine. Transform tx) void set. Clip(Shape clip) void set. Font(Font font) void set. Rendering. Hints(Map hints)

java. awt. goem 패키지 n 점, 선, 곡선, 사각 형, 타원 등의 기본적인 도형을

java. awt. goem 패키지 n 점, 선, 곡선, 사각 형, 타원 등의 기본적인 도형을 위한 클래스들을 제공 Arc 2 D Area Cubic. Curve 2 D Dimension 2 D n Ellipse 2 D General. Path Line 2 D Point 2 D Quad. Curve 2 D Rectangle 2 D Rectangular. Shape Round. Rectangle 2 D Graphics 2 D 클래스 이용 n Graphics 클래스와는 다르게 그림을 그릴 객체를 미리 만들 고, Graphics 2 D 클래스의 draw나 fill 메소드를 이용해서 그림을 화면에 나타낸다.

예제 : Shape. Example. java 1 import java. awt. *; 2 import java. applet.

예제 : Shape. Example. java 1 import java. awt. *; 2 import java. applet. *; 3 import java. awt. geom. *; 4 5 public class Shape. Example extends Applet { 6 Ellipse 2 D. Double circle; 7 Rectangle 2 D. Double rect; 8 9 public void init() { 10 circle = new Ellipse 2 D. Double(10, 200, 200); 11 rect = new Rectangle 2 D. Double(10, 200, 200); 12 } 13 14 public void paint(Graphics g) { 15 Graphics 2 D g 2 = (Graphics 2 D) g; 16 g 2. fill(circle); 17 g 2. draw(rect); 18 } 19 }

예제 : Gradient. Example. java 1 import java. awt. *; 2 import java. applet.

예제 : Gradient. Example. java 1 import java. awt. *; 2 import java. applet. *; 3 import java. awt. geom. *; 4 5 public class Gradient. Example extends Applet { 6 Ellipse 2 D. Double circle; ………. . . 10 public void init() { 11 gradient = new Gradient. Paint(10, Color. red, 200, Color. yellow, true); 12 circle = new Ellipse 2 D. Double(10, 200, 200); 13 rect = new Rectangle 2 D. Double(10, 200, 200); 14 } 15 16 public void paint(Graphics g) { 17 Graphics 2 D g 2 = (Graphics 2 D) g; 18 g 2. set. Paint(gradient); 19 g 2. draw(rect); 20 g 2. fill(circle); ……….

Basic. Stroke 클래스 n 선의 굵기나 스타일을 지정하기 위해서는 스트로크(stroke)를 이용 n 자바 2

Basic. Stroke 클래스 n 선의 굵기나 스타일을 지정하기 위해서는 스트로크(stroke)를 이용 n 자바 2 D에서 스트로크를 설정하기 위해서는 Basic. Stroke 클래 스를 이용 n 생성자 Basic. Stroke() Basic. Stroke(float width, int cap, int join) Basic. Stroke(float width, int cap, int join, float miterlimit, float[] dash, float dash_phase)

예제 : Stroke. Test. java 1 import java. awt. *; 2 import java. applet.

예제 : Stroke. Test. java 1 import java. awt. *; 2 import java. applet. *; 3 import java. awt. geom. *; 4 5 public class Stroke. Test extends Applet { 6 Rectangle 2 D. Double rect; 7 Ellipse 2 D. Double circle; 8 9 public void init() { 10 rect = new Rectangle 2 D. Double(20, 220, 220); 11 circle = new Ellipse 2 D. Double(20, 220, 220); 12 } 13 14 public void paint(Graphics g) { 15 Graphics 2 D g 2 = (Graphics 2 D) g; 16 g 2. set. Stroke(new Basic. Stroke(2)); 17 g 2. draw(rect); 18 float[] dash. Pattern = 30, 10, 10 ; 19 g 2. set. Stroke(new Basic. Stroke(8, Basic. Stroke. CAP_BUTT, 20 Basic. Stroke. JOIN_MITER, 10, dash. Pattern, 0)); 21 g 2. draw(circle); 22 } 23 }

Texture. Paint 클래스 n 텍스쳐 (texture) 배경을 만드는데 사용되는 클래스 n 생성자 n n

Texture. Paint 클래스 n 텍스쳐 (texture) 배경을 만드는데 사용되는 클래스 n 생성자 n n Texture. Paint(Buffered. Image txtr, Rectangle 2 D rect 2 d) 예제 : Texture. Example. java 1 import java. awt. *; 2 import java. applet. *; 3 import java. awt. geom. *; 4 import java. awt. image. *; 5 6 public class Texture. Example extends Applet { 7 Rectangle 2 D. Double rect; 8 Buffered. Image img; 9 Texture. Paint texture; 10 Rectangle img. Rect; 11

Texture. Paint 클래스 12 13 14 15 16 17 18 19 20 21 22

Texture. Paint 클래스 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 } public void init() { rect = new Rectangle 2 D. Double(10, 200, 200); Image im = get. Image(get. Code. Base(), "bird. gif"); Media. Tracker t = new Media. Tracker(this); t. add. Image(im, 0); try { t. wait. For. All(); }catch(Exception e) { System. out. println("Media. Tracker error"); } img = new Buffered. Image(im. get. Width(this), im. get. Height(this), Buffered. Image. TYPE_INT_RGB); Graphics 2 D d 2 = img. create. Graphics(); d 2. draw. Image(im, 0, 0, this); img. Rect = new Rectangle(0, 0, im. get. Width(this), im. get. Height(this)); texture = new Texture. Paint(img, img. Rect); ] } public void paint(Graphics g) { Graphics 2 D g 2 = (Graphics 2 D) g; g 2. set. Paint(texture); g 2. fill(rect); }

tanslate() / rotate() 메소드 n 좌표를 이동하거나 그림을 회전시키기 위한 메소드 n n n

tanslate() / rotate() 메소드 n 좌표를 이동하거나 그림을 회전시키기 위한 메소드 n n n void translate(double tx, double ty) void rotate(double theta) 예제 : Rotate. Test. java 1 import java. awt. *; 2 import java. awt. geom. *; 3 import java. applet. *; 4 5 public class Rotate. Test extends Applet { 6 Rectangle 2 D. Double rect; 7 8 public void init() { 9 rect = new Rectangle 2 D. Double(10, 150, 50); 10 } 11

tanslate() / rotate() 메소드 12 13 14 15 16 17 18 19 20 21

tanslate() / rotate() 메소드 12 13 14 15 16 17 18 19 20 21 22 23 24 n public void paint(Graphics g) { Graphics 2 D g 2 = (Graphics 2 D) g; g 2. draw(rect); g 2. translate(80, 30); g 2. rotate(Math. PI/8. 0); g 2. draw(rect); g 2. translate(150, 150); for(int i=0; i < 4; i++) { g 2. rotate(Math. PI/2. 0); g 2. draw. String("Hello World", 0, 0); } } 설명 15 n 16 g 2. translate(80, 30); (80, 30) 위치로 이동한다. g 2. rotate(Math. PI/8. 0);

General. Path 클래스 n 직선이나 곡선으로 연결되는 도형을 그릴 수 있는 방법 제공 n

General. Path 클래스 n 직선이나 곡선으로 연결되는 도형을 그릴 수 있는 방법 제공 n 예제 : General. Rect 2. java 1 import java. awt. *; 2 import java. awt. geom. *; 3 import java. applet. *; 4 5 public class General. Rect 2 extends Applet { 6 7 public void paint(Graphics g) { 8 Graphics 2 D g 2 =(Graphics 2 D) g; 9 g 2. set. Color(Color. blue); 10 General. Path rect = new General. Path(General. Path. WIND_EVEN_ODD); 11 rect. move. To(25. 0 f, 25. 0 f); 12 rect. line. To(100. 0 f, 25. 0 f); 13 rect. line. To(25. 0 f, 80. 0 f); 14 rect. line. To(100. 0 f, 80. 0 f); 15 rect. close. Path(); 16 g 2. fill(rect); 17 } 18 }