x htm applet codex class width200 height50 applet

  • Slides: 15
Download presentation

กราฟฟกในเวบเพจแบบอ x. htm นเทอรแอกทฟ >applet code="x. class" width=200 height=50< />applet< DOS>appletviewer x. htm http:

กราฟฟกในเวบเพจแบบอ x. htm นเทอรแอกทฟ >applet code="x. class" width=200 height=50< />applet< DOS>appletviewer x. htm http: //www. thaiall. com/class Page: 2

เขยนตวอกษร (1/4( import java. applet; *. import java. awt; *. public class x extends

เขยนตวอกษร (1/4( import java. applet; *. import java. awt; *. public class x extends Applet} public void paint(Graphics g} ( g. set. Color(new Color(240, 0, 0; (( g. draw. String("test", 10, 20; ( { { 10 20 Y http: //www. thaiall. com/class X test Page: 3

เขยนตวอกษร (2/4( RGB (Red Green Blue( >font face=#00 ff 00 size=0< Color Sample Hexadecimal:

เขยนตวอกษร (2/4( RGB (Red Green Blue( >font face=#00 ff 00 size=0< Color Sample Hexadecimal: Decimal : 000000 0, 0, 0 ffdddd 255, 238 00 ff 00 0, 255, 0 ddddff 238, 255 http: //www. thaiall. com/class Page: 4

เขยนตวอกษร (3/4( g. draw. String("test", 10, 20; ( http: //www. yonok. ac. th/pmy/j 2

เขยนตวอกษร (3/4( g. draw. String("test", 10, 20; ( http: //www. yonok. ac. th/pmy/j 2 sdk-1_4_2 -doc. zip 10 20 Y http: //www. thaiall. com/class X test Page: 5

เขยนตวอกษร import java. applet; *. import java. awt; *. public class j 1102 extends

เขยนตวอกษร import java. applet; *. import java. awt; *. public class j 1102 extends Applet} int i, j; String istr, p; public void init} () set. Background(Color. yellow; ( p = get. Parameter("x; (" { public void paint(Graphics g} ( g. set. Color(Color. black; ( g. draw. String(p, 0, 10; ( i = 1; while (i <= 10} ( j = 10 * i; istr= Integer. to. String(i; ( g. draw. String(istr, 72, j ; ( i++; // column = 1 inch { { { http: //www. thaiall. com/class (4/4( 72 10 70 x X 1 2 3 4 5 6 7 8 9 10 Y Page: 6

วาดเสนตรง void draw. Line(int x 1, int y 1, int x 2, int y

วาดเสนตรง void draw. Line(int x 1, int y 1, int x 2, int y 2( Draws a line, using the current color, between the points (x 1, y 1) and (x 2, y 2) in this graphics context's coordinate system. Parameters: x 1 - the first point's x coordinate. y 1 - the first point's y coordinate. x 2 - the second point's x coordinate. y 2 - the second point's y coordinate. http: //yn 1. yonok. ac. th/burin/javadocs/api/java/awt/Graphics. html g. draw. Line(x 1, y 1, x 2, y 2; ( g. draw. Line(10, 20, 30, 20); 10 30 X 20 Y http: //www. thaiall. com/class Page: 7

วาดสเหลยม void draw. Rect(int x, int y, int width, int height( Draws the outline

วาดสเหลยม void draw. Rect(int x, int y, int width, int height( Draws the outline of the specified rectangle. The left and right edges of the rectangle are at x and x + width. The top and bottom edges are at y and y + height. The rectangle is drawn using the graphics context's current color. Parameters: x - the x coordinate of the rectangle to be drawn. y - the y coordinate of the rectangle to be drawn. width - the width of the rectangle to be drawn. height - the height of the rectangle to be drawn. http: //yn 1. yonok. ac. th/burin/javadocs/api/java/awt/Graphics. html g. draw. Rect(x 1, y 1, width, height); 10 g. draw. Rect(10, 5, 20, 15); 30 X 5 15 Y http: //www. thaiall. com/class Page: 8

วาดวงกลม void draw. Oval(int x, int y, int width, int height( Draws the outline

วาดวงกลม void draw. Oval(int x, int y, int width, int height( Draws the outline of an oval. The result is a circle or ellipse that fits within the rectangle specified by the x, y, width, and height arguments. Parameters: x - the x coordinate of the upper left corner of the oval. y - the y coordinate of the upper left corner of the oval. width - the width of the oval to be drawn. height - the height of the oval to be drawn. http: //yn 1. yonok. ac. th/burin/javadocs/api/java/awt/Graphics. html g. draw. Oval(x 1, y 1, width, height); 10 g. draw. Oval(10, 5, 20, 15); 30 X 5 15 Y http: //www. thaiall. com/class Page: 9

วาดเสนรอบวง void draw. Arc(int x, int y, int width, int height, int start. Angle,

วาดเสนรอบวง void draw. Arc(int x, int y, int width, int height, int start. Angle, int arc. Angle( Draws the outline of a circular or elliptical arc covering the specified rectangle. http: //yn 1. yonok. ac. th/burin/javadocs/api/java/awt/Graphics. html g. draw. Arc(10, 5, 20, 15, 0, 180); 10 30 X 5 15 Y http: //www. thaiall. com/class Page: 10

วาดหลายเหลยม void draw. Polygon(Polygon p) Draws the outline of a polygon defined by the

วาดหลายเหลยม void draw. Polygon(Polygon p) Draws the outline of a polygon defined by the specified Polygon object. Parameters: p - the polygon to draw. See Also: fill. Polygon(int[], int) draw. Polyline(int[], int) http: //yn 1. yonok. ac. th/burin/javadocs/api/java/awt/Graphics. html int[] x={10, 50, 100; { int[] y={10, 100, 50; { g. draw. Polygon(x, y, 3; ( 10 50 100 X 10 50 100 http: //www. thaiall. com/class Y Page: 11

ปม และซอนทละปม import java. applet; *. import java. awt. event; *. public class x

ปม และซอนทละปม import java. applet; *. import java. awt. event; *. public class x extends Applet implements Action. Listener} Button b 1 = new Button("exit 1; (" Button b 2 = new Button("exit 2; (" public void init} () add(b 1; ( add(b 2; ( b 1. add. Action. Listener(this; ( b 2. add. Action. Listener(this; ( { public void action. Performed(Action. Event e}( if (e. get. Action. Command(). equals("exit 1")) b 1. set. Visible(false; ( if (e. get. Action. Command(). equals("exit 2")) b 2. set. Visible(false; ( { { http: //www. thaiall. com/class Page: 12

เพมคาใหกบ Text. Field import java. applet; *. import java. awt. event; *. public class

เพมคาใหกบ Text. Field import java. applet; *. import java. awt. event; *. public class x extends Applet implements Action. Listener} Text. Field t = new Text. Field("1; (" public void init} () add(t; ( t. add. Action. Listener(this; ( { public void paint(Graphics g{ } ( public void action. Performed(Action. Event e}( int n 1 = Integer. parse. Int(e. get. Action. Command; (() String n 2 = Integer. to. String(n 1 + 1; ( t. set. Text(n 2; ( { { http: //www. thaiall. com/class Page: 13

วาดโดราเอมอนดวย Applet import java. applet; *. import java. awt. event; *. public class x

วาดโดราเอมอนดวย Applet import java. applet; *. import java. awt. event; *. public class x extends Applet} public void paint(Graphics g}( g. set. Color(Color. black); g. draw. Rect(140, 285, 220, 5 ; ( g. draw. Oval(240, 180, 20); g. draw. Oval(210, 130, 40, 60; ( g. draw. Oval(250, 130, 40, 60); g. draw. Oval(233, 160, 15, 20; ( g. draw. Oval(240, 290, 20); g. draw. Line(250, 200, 250; ( g. draw. Line(240, 230, 180, 240); g. draw. Line(260, 230, 320, 240; ( g. draw. Line(240, 220, 180, 220); g. draw. Line(260, 220, 320, 220; ( g. draw. Line(240, 210, 180, 200); g. draw. Line(260, 210, 320, 200; ( g. draw. Line(245, 300, 255, 300); g. draw. Line(250, 300, 250, 310; ( g. draw. Arc(255, 165, 10, 30, 120; ( g. draw. Arc(150, 200, 240, 60; ( g. draw. Arc(150, 160, 200, 250, 113, 67; ( g. draw. Arc(150, 160, 200, 250, 0, 67; ( g. draw. Arc(135, 125, 230, 240, 340, 220; ( { { โดย สรยา http: //www. thaiall. com/class พงษปญญ Page: 14

Awt ผาน Java (ไมใช Applet) import java. awt; *. import java. awt. event; *.

Awt ผาน Java (ไมใช Applet) import java. awt; *. import java. awt. event; *. public class x implements Action. Listener} Frame s = new Frame("awt; (" Button bclose = new Button("Exit; (" public static void main(String[] args}( new x(). init; () { public void init} ( ) s. set. Size(200, 200; ( s. add(bclose; ( bclose. add. Action. Listener(this; ( s. show; () { public void action. Performed(Action. Event a} ( if(a. get. Source()==bclose) System. exit(0; ( { { http: //www. thaiall. com/class Page: 15