1 / 15

การโปรแกรมเชิงวัตถุด้วยภาษา JAVA

การโปรแกรมเชิงวัตถุด้วยภาษา JAVA. แอพเพล็ตเบื้องต้น (Applet). มหาวิทยาลัยเนชั่น http:// www. nation. ac.th. บุรินทร์ รุจจนพันธุ์ . ปรับปรุง 10 มกราคม 255 1. กราฟฟิกในเว็บเพจแบบอินเทอร์แอ็กทีฟ. x.htm <applet code="x.class" width=200 height=50> </applet> DOS> appletviewer x.htm.

vesna
Download Presentation

การโปรแกรมเชิงวัตถุด้วยภาษา JAVA

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. การโปรแกรมเชิงวัตถุด้วยภาษา JAVA แอพเพล็ตเบื้องต้น (Applet) มหาวิทยาลัยเนชั่น http://www.nation.ac.th บุรินทร์ รุจจนพันธุ์ . ปรับปรุง 10 มกราคม 2551

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

  3. เขียนตัวอักษร (1/4) import java.applet.*; import java.awt.*; public class x extends Applet { public void paint(Graphics g) { g.setColor(new Color(240,0,0)); g.drawString("test",10,20); } } 10 X 20 test Y

  4. เขียนตัวอักษร (2/4) RGB (Red Green Blue) <font face=#00ff00 size=0> Color Sample Hexadecimal: 000000 Decimal : 0,0,0 Hexadecimal: ffdddd Decimal : 255,238,238 Hexadecimal: 00ff00 Decimal : 0,255,0 Hexadecimal: ddddff Decimal : 238,238,255

  5. เขียนตัวอักษร (3/4) g.drawString("test",10,20); http://www.yonok.ac.th/pmy/j2sdk-1_4_2-doc.zip 10 X 20 test Y

  6. เขียนตัวอักษร (4/4) import java.applet.*; import java.awt.*; public class j1102 extends Applet { int i,j; String istr,p; public void init() { setBackground(Color.yellow); p = getParameter("x"); } public void paint(Graphics g) { g.setColor(Color.black); g.drawString(p,0,10); i = 1; while (i <= 10) { j = 10 * i; istr= Integer.toString(i); g.drawString(istr,72,j); i++; // column = 1 inch } } } 72 X 10 x 1 2 3 4 5 6 7 8 9 10 70 Y

  7. วาดเส้นตรง void drawLine(int x1, int y1, int x2,int y2) Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system. Parameters: x1 - the first point's x coordinate. y1 - the first point's y coordinate. x2 - the second point's x coordinate. y2 - the second point's y coordinate. http://yn1.yonok.ac.th/burin/javadocs/api/java/awt/Graphics.html g.drawLine(x1,y1,x2,y2); g.drawLine(10,20,30,20); 10 30 X 20 Y

  8. วาดสี่เหลี่ยม void drawRect(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://yn1.yonok.ac.th/burin/javadocs/api/java/awt/Graphics.html g.drawRect(x1,y1,width,height); g.drawRect(10,5,20,15); 10 30 X 5 15 Y

  9. วาดวงกลม void drawOval(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://yn1.yonok.ac.th/burin/javadocs/api/java/awt/Graphics.html g.drawOval(x1,y1,width,height); g.drawOval(10,5,20,15); 10 30 X 5 15 Y

  10. วาดเส้นรอบวง void drawArc(int x,int y,int width,int height,int startAngle,int arcAngle) Draws the outline of a circular or elliptical arc covering the specified rectangle. http://yn1.yonok.ac.th/burin/javadocs/api/java/awt/Graphics.html g.drawArc(10,5,20,15,0,180); 10 30 X 5 15 Y

  11. วาดหลายเหลี่ยม void drawPolygon(Polygon p) Draws the outline of a polygon defined by the specified Polygon object. Parameters: p - the polygon to draw. See Also: fillPolygon(int[], int[], int) drawPolyline(int[], int[], int) http://yn1.yonok.ac.th/burin/javadocs/api/java/awt/Graphics.html int[] x={10,50,100}; int[] y={10,100,50}; g.drawPolygon(x,y,3); 100 10 50 X 10 50 100 Y

  12. ปุ่ม และซ่อนทีละปุ่ม import java.applet.*; import java.awt.*; import java.awt.event.*; public class x extends Applet implements ActionListener { Button b1 = new Button("exit1"); Button b2 = new Button("exit2"); public void init() { add(b1); add(b2); b1.addActionListener(this); b2.addActionListener(this); } public void actionPerformed(ActionEvent e){ if (e.getActionCommand().equals("exit1")) b1.setVisible(false); if (e.getActionCommand().equals("exit2")) b2.setVisible(false); } }

  13. เพิ่มค่าให้กับ TextField import java.applet.*; import java.awt.*; import java.awt.event.*; public class x extends Applet implements ActionListener { TextField t = new TextField("1"); public void init() { add(t); t.addActionListener(this); } public void paint(Graphics g) { } public void actionPerformed(ActionEvent e){ int n1 = Integer.parseInt(e.getActionCommand()); String n2 = Integer.toString(n1 + 1); t.setText(n2); } }

  14. วาดโดราเอมอนด้วย Applet import java.applet.*; import java.awt.*; import java.awt.event.*; public class x extends Applet { public void paint(Graphics g){ g.setColor(Color.black); g.drawRect(140,285,220,5); g.drawOval(240,180,20,20); g.drawOval(210,130,40,60); g.drawOval(250,130,40,60); g.drawOval(233,160,15,20); g.drawOval(240,290,20,20); g.drawLine(250,200,250,250); g.drawLine(240,230,180,240); g.drawLine(260,230,320,240); g.drawLine(240,220,180,220); g.drawLine(260,220,320,220); g.drawLine(240,210,180,200); g.drawLine(260,210,320,200); g.drawLine(245,300,255,300); g.drawLine(250,300,250,310); g.drawArc(255,165,10,10,30,120); g.drawArc(150,50,200,200,240,60); g.drawArc(150,160,200,250,113,67); g.drawArc(150,160,200,250,0,67); g.drawArc(135,125,230,240,340,220); } } โดย สุริยา พงษ์ปัญญา 4708002

  15. Awt ผ่าน Java (ไม่ใช่ Applet) import java.awt.*; import java.awt.event.*; public class x implements ActionListener { Frame s = new Frame("awt"); Button bclose = new Button("Exit"); public static void main(String[] args){ new x().init(); } public void init( ) { s.setSize(200,200); s.add(bclose); bclose.addActionListener(this); s.show(); } public void actionPerformed(ActionEvent a) { if(a.getSource()==bclose) System.exit(0); } }

More Related