SlideShare a Scribd company logo
การออกแบบ Class แบบ Inheritance                                                                                                                                                                 ssc




การออกแบบ Class แบบ Inheritance คือ ...........................................................................................................................
............................................................................................................................................................................................
ตัวอยางการออกแบบ Class แบบ Inheritance




จากรูป สามารถอธิบายไดวา ..................................................................................................................................................
.............................................................................................................................................................................................
Superclass คือ7 ................................................................................................................................................................
Subclass คือ7 ................................................................................................................................................................
ตัวอยางการสราง Class แบบ Inheritance
Class Point
ขั้นตอนที่ 1 สราง Class Point ขึ้นมา
  public class Point {
  }// end class Point

ขั้นตอนที่ 2 สราง Attribute ตางๆ ตามที่ไดออกแบบไว
  !          private int x = 10;                                                          Note :: .....................................................................
  !          private int y = 10;
  !          private static int count = 0;

ขั้นตอนที่ 3 สราง Constructor method ตางๆ ตามที่ไดออกแบบไว
  !          // no-argument constructor
  !          public Point() {
  !          !        setX(0);
  !          !        setY(0);
  !          !        count++;
  !          }
  !          // constructor
  !          public Point( int xValue, int yValue ) {
  !          !        setX(xValue);
  !          !        setY(yValue);
  !          !        count++;
  !          }


Constructor method 2 method นี้มีไวเพื่อ ............................................................................................................................
.............................................................................................................................................................................................
                                                                                                                                                                            Page 1 of 6
ขั้นตอนที่ 4 สราง “set” method ตางๆ ตามที่ไดออกแบบไว
  !          // set       x in coordinate pair
  !          public       void setX( int xValue ) {
  !          !              x = xValue; // no need for validation
  !          }
  !          // set       y in coordinate pair
  !          public       void setY( int yValue ) {
  !          !              y = yValue; // no need for validation
  !          }


“set” method 2 method นี้มีไวเพื่อ ........................................................................................................................................
.............................................................................................................................................................................................
ขั้นตอนที่ 5 สราง “get” method ตางๆ ตามที่ไดออกแบบไว
  !          // return x from coordinate pair
  !          public int getX() {
  !          !        return x;
  !          }
  !          // return y from coordinate pair
  !          public int getY() {
  !          !        return y;
  !          }


“get” method 2 method นี้มีไวเพื่อ .......................................................................................................................................
.............................................................................................................................................................................................
ขั้นตอนที่ 6 สราง Facilities method ตางๆ ตามที่ไดออกแบบไว
  !          public static int getCount() {
  !          !        return count;
  !          }
  !          // return String representation of Point object
  !          public String toString() {
  !          !        return "[" + getX() + ", " + getY() + "]";
  !          }!
             // finalizer
  !          protected void finalize() {
  !          !        count--;
  !          }


Facilities method 3 method นี้มีไวเพื่อ .................................................................................................................................
.............................................................................................................................................................................................
.............................................................................................................................................................................................
ขั้นตอนที่ 7 ทำการ Compile
โดยใชคำสั่ง ..........................................................................................................................................................................
ผลลัพธที่ได ..........................................................................................................................................................................
ขั้นตอนที่ 8 ทดสอบการทำงานของ Class Point เพียง Class เดียวกอน
                      1) สราง testPoint.html เอาไวสำหรับ Run
                      2) สราง testPoint.java เอาไวทดสอบ Class Point
ตัวอยางหนาจอการทำงาน (http://202.44.47.108/~ssc/inheritance/testPoint.html)




                                                                                                                                                                            Page 2 of 6
testPoint.html
  <html>
  !     <body>
          <h1>Test Class Point</h1>
          <h3>Create by: 5366261111 Supaporn Simcharoen IT1-RC</h3>
  !     !     <applet code="testPoint.class" height="200" width="400">
  !     !     </applet>
  !     </body>
  </html>


testPoint.java
ขั้นตอนที่ 1 สราง Class พรอมกับ import package ที่ตองใช และสราง Method ที่นาจะมี
  import java.awt.*;
  import javax.swing.*;

  public class testPoint extends JApplet{
  !     public void init(){
  !     }
  !     public void paint(Graphics g) {
  !     }
  }


method init มีไวเพื่อ .............................................................................................................................................................
method paint มีไวเพื่อ ..........................................................................................................................................................
ขั้นตอนที่ 2 กำหนดคาเริ่มตนที่ method init พรอมกับตัวแปรตางๆ ที่ตองใช
  !          int num;
  !          Point p[] ;


             public void init()
  !          {
  !          !        String input; // user's input
  !          !        // obtain user's choice
  !          !        input = JOptionPane.showInputDialog("Enter number of point : " );
  !          !        num = Integer.parseInt( input ); // convert input to int
  !          !        p = new Point[num];
  !          !        for(int n = 0 ; n < p.length ; n++) {
  !          !        !       int x = 5 + (int) (Math.random() * 400);
  !          !        !       int y = 5 + (int) (Math.random() * 200);
  !          !        !       p[n] = new Point(x, y);
  !          !        }
  !          } // end method init


Note:: ..................................................................................................................................................................................
.............................................................................................................................................................................................
ขั้นตอนที่ 3 ทดลอง Compile และ Run
วิธีในการ Run คือ .................................................................................................................................................................
ขั้นตอนที่ 4 กำหนดการทำงานใน method paint
  !          // draw shapes on applet's background
  !          public void paint( Graphics g )
  !          {
  !          !        super.paint( g ); //call paint method inherited from JApplet
  !          !        for ( int n = 0; n < p.length; n++ ) {
  !          !        !       // set color
  !          !        !       g.setColor( new Color(255,0,0) );
  !          !        !       // plot point
  !          !        !       g.drawLine( p[n].getX(), p[n].getY(), p[n].getX(), p[n].getY() );
  !          !        } // end for
  !          !        showStatus("จำนวน Object : "+ Point.getCount());
  !          } // end method paint


Note:: ..................................................................................................................................................................................
.............................................................................................................................................................................................
ขั้นตอนที่ 5 ทดลอง Compile และ Run อีกครั้ง


                                                                                                                                                                            Page 3 of 6
Class Rectangle
ขั้นตอนที่ 1 สราง Class Rectangle ขึ้นมา
  public class Rectangle extends Point {
  }


Note:: ..................................................................................................................................................................................
ขั้นตอนที่ 2 สราง Attribute ตางๆ ตามที่ไดออกแบบไว
  !          private int width = 10;
  !          private int height = 10;
  !          private static int count = 0;

ขั้นตอนที่ 3 สราง Constructor method ตางๆ ตามที่ไดออกแบบไว
  !          public Rectangle() {
  !          }
  !          public Rectangle(int x, int y, int w, int h ) {
  !          !        super(x,y);
  !          !        setWidth(w);
  !          !        setHeight(h);
  !          }


super(x,y); คือ .....................................................................................................................................................................
Constructor method 2 method นี้มีไวเพื่อ ............................................................................................................................
............................................................................................................................................................................................
ขั้นตอนที่ 4 สราง “set” method ตางๆ ตามที่ไดออกแบบไว
  !          public void setWidth(int w) {
  !          !        width = w;
  !          }
  !          public void setHeight(int h) {
  !          !        height = h;
  !          }


“set” method 2 method นี้มีไวเพื่อ ........................................................................................................................................
.............................................................................................................................................................................................
ขั้นตอนที่ 5 สราง “get” method ตางๆ ตามที่ไดออกแบบไว
  !          public       int getWidth() {
  !          !              return width;
  !          }
  !          public       int getHeight() {
  !          !              return height;
  !          }
  !          public       int getArea() {
  !          !              return width*height;
  !          }
  !          public       static int getCount() {
  !          !              return count;
  !          }


“get” method 4 method นี้มีไวเพื่อ .......................................................................................................................................
.............................................................................................................................................................................................
ขั้นตอนที่ 6 สราง Facilities method ตางๆ ตามที่ไดออกแบบไว
  !          protected void finalize() {
  !          !        count--;
  !          }
  !          public String toString() {
  !          !        return "Point[x,y]Left = " + super.toString() + "; Width = " +
  !          !        getWidth() + "; Height = " + getHeight();
  !          }


Facilities method 2 method นี้มีไวเพื่อ .................................................................................................................................
.............................................................................................................................................................................................
ขั้นตอนที่ 7 ทำการ Compile
โดยใชคำสั่ง ..........................................................................................................................................................................
ผลลัพธที่ได ..........................................................................................................................................................................
                                                                                                                                                                            Page 4 of 6
ขั้นตอนที่ 8 ทดสอบการทำงานของ Class Rectangle
              1) สราง testRectangle.html เอาไวสำหรับ Run
              2) สราง testRectangle.java เอาไวทดสอบ Class Rectangle
ตัวอยางหนาจอการทำงาน (http://202.44.47.108/~ssc/inheritance/testRectangle.html)




testRectangle.html
  <html>
  !     <body>
          <h1>Test Class Rectangle</h1>
          <h3>Create by: 5366261111 Supaporn Simcharoen IT1-RC</h3>
  !     !     <applet code="testRectangle.class" height="250" width="400">
  !     !     </applet>
  !     </body>
  </html>


testRectangel.java
ขั้นตอนที่ 1 สราง Class พรอมกับ import package ที่ตองใช และสราง Method ที่นาจะมี
  import java.awt.*;
  import javax.swing.*;

  public class testRectangle extends JApplet{
  !     public void init(){
  !     }
  !     public void paint(Graphics g) {
  !     }
  }


ขั้นตอนที่ 2 กำหนดคาเริ่มตนที่ method init พรอมกับตัวแปรตางๆ ที่ตองใช
  !          int x, y;
  !          Rectangle r ;


  !          public void init()
  !          {
  !          !        String input; // user's input
  !          !        // obtain user's choice
  !          !        input = JOptionPane.showInputDialog("Enter value x                                                       of left point : " );
  !          !        x = Integer.parseInt( input ); // convert input to                                                       int
  !          !        input = JOptionPane.showInputDialog("Enter value y                                                       of left point : " );
  !          !        y = Integer.parseInt( input ); // convert input to                                                       int
  !          !        int w = 10 + (int) (Math.random() * 280);
  !          !        int h = 10 + (int) (Math.random() * 180);
  !          !        r = new Rectangle(x, y, w, h);
  !          } // end method init


Note:: ..................................................................................................................................................................................
.............................................................................................................................................................................................
ขั้นตอนที่ 3 ทดลอง Compile และ Run

                                                                                                                                                                            Page 5 of 6
ขั้นตอนที่ 4 กำหนดการทำงานใน method paint
  !          // draw shapes on applet's background
  !          public void paint( Graphics g )
  !          {
  !          !        super.paint( g ); //call paint method inherited from JApplet
  !          !        // set color
  !          !        g.setColor( Color.ORANGE );
  !          !        g.drawRect(r.getX(), r.getY(), r.getWidth(),r.getHeight() );
  !          !        g.setColor( Color.BLUE );
  !          !        g.drawString( "Point Left : " + r.getX() + ", " + r.getY(), r.getX(), r.getY());
  !          !        g.drawString( "Width : " + r.getWidth() , r.getX(), r.getY() + 15);
  !          !        g.drawString( "Height : " + r.getHeight() , r.getX(), r.getY() + 30);
  !          !        g.drawString( "Area : " + r.getArea() , r.getX(), r.getY() + 45);
  !          } // end method paint


Note:: ..................................................................................................................................................................................
.............................................................................................................................................................................................
ขั้นตอนที่ 5 ทดลอง Compile และ Run อีกครั้ง


การบาน
แกไขการทำงานของ testRectangle ใหสามารถรับคาจำนวนของ Rectangle ที่จะสรางได
ตัวอยางหนาจอการทำงาน (http://202.44.47.108/~ssc/inheritance-hw/testRectangle.html)




                                                                                                                                                                            Page 6 of 6

More Related Content

PDF
Applet 6 mouse_keyboard
PDF
ทบทวนเลขยกกำลัง
PDF
3.parabola
PDF
Applet 7 image_j_panel
PDF
Applet 5 class_inheritance
PDF
662305 LAB13
PDF
New Assingment3 array2D
Applet 6 mouse_keyboard
ทบทวนเลขยกกำลัง
3.parabola
Applet 7 image_j_panel
Applet 5 class_inheritance
662305 LAB13
New Assingment3 array2D

Similar to Applet 5 class_inheritance (20)

PDF
Java-Chapter 08 Methods
PDF
Java-Answer Chapter 12-13
PDF
Java-Chapter 13 Advanced Classes and Objects
PDF
Java-Chapter 12 Classes and Objects
PDF
Applet 3 design_class_composition
PPT
Chapter1 uml3
PPT
Chapter1 uml3
PDF
Java-Chapter 14 Creating Graphics with DWindow
PDF
Java-Answer Chapter 08-09
PDF
งานนำเสนอ1
PPT
PPTX
Computer Programming 4
PPT
Java Programming [5/12] : Build Graphical User Interface
PDF
คลาสและการเขียนโปรแกรมเชิงวัตถุเบื้องต้น
PDF
คลาสและการเขียนโปรแกรมเชิงวัตถุเบื้องต้น
PDF
Java 7&12 6 2
PDF
Java Programming: การเขียนโปรแกรมภาษาจาวาเชิงอ็อบเจกต์
PDF
บทที่5 ข้อมูลชนิดอาร์เรย์และสตริง
PDF
Java Programming: หลักการเชิงอ็อบเจกต์
Java-Chapter 08 Methods
Java-Answer Chapter 12-13
Java-Chapter 13 Advanced Classes and Objects
Java-Chapter 12 Classes and Objects
Applet 3 design_class_composition
Chapter1 uml3
Chapter1 uml3
Java-Chapter 14 Creating Graphics with DWindow
Java-Answer Chapter 08-09
งานนำเสนอ1
Computer Programming 4
Java Programming [5/12] : Build Graphical User Interface
คลาสและการเขียนโปรแกรมเชิงวัตถุเบื้องต้น
คลาสและการเขียนโปรแกรมเชิงวัตถุเบื้องต้น
Java 7&12 6 2
Java Programming: การเขียนโปรแกรมภาษาจาวาเชิงอ็อบเจกต์
บทที่5 ข้อมูลชนิดอาร์เรย์และสตริง
Java Programming: หลักการเชิงอ็อบเจกต์
Ad

More from Nitigan Nakjuatong (18)

PDF
วิธีการกำหนดสิทธิให้กับ Directory
PDF
Applet 7 image_j_panel
PDF
662305 LAB12
PDF
Applet 4 class_composition
PDF
PDF
PDF
PDF
PDF
Applet 2 container and action_listener
PDF
662305 Lab7new
PDF
Assingment3 array2 d
PDF
PPT
PPT
Method part2
PPT
Control structure
PPT
Method JAVA
PPT
Set putty to use numeric keyboard in pico
PDF
Putty basic setting
วิธีการกำหนดสิทธิให้กับ Directory
Applet 7 image_j_panel
662305 LAB12
Applet 4 class_composition
Applet 2 container and action_listener
662305 Lab7new
Assingment3 array2 d
Method part2
Control structure
Method JAVA
Set putty to use numeric keyboard in pico
Putty basic setting
Ad

Applet 5 class_inheritance

  • 1. การออกแบบ Class แบบ Inheritance ssc การออกแบบ Class แบบ Inheritance คือ ........................................................................................................................... ............................................................................................................................................................................................ ตัวอยางการออกแบบ Class แบบ Inheritance จากรูป สามารถอธิบายไดวา .................................................................................................................................................. ............................................................................................................................................................................................. Superclass คือ7 ................................................................................................................................................................ Subclass คือ7 ................................................................................................................................................................ ตัวอยางการสราง Class แบบ Inheritance Class Point ขั้นตอนที่ 1 สราง Class Point ขึ้นมา public class Point { }// end class Point ขั้นตอนที่ 2 สราง Attribute ตางๆ ตามที่ไดออกแบบไว ! private int x = 10; Note :: ..................................................................... ! private int y = 10; ! private static int count = 0; ขั้นตอนที่ 3 สราง Constructor method ตางๆ ตามที่ไดออกแบบไว ! // no-argument constructor ! public Point() { ! ! setX(0); ! ! setY(0); ! ! count++; ! } ! // constructor ! public Point( int xValue, int yValue ) { ! ! setX(xValue); ! ! setY(yValue); ! ! count++; ! } Constructor method 2 method นี้มีไวเพื่อ ............................................................................................................................ ............................................................................................................................................................................................. Page 1 of 6
  • 2. ขั้นตอนที่ 4 สราง “set” method ตางๆ ตามที่ไดออกแบบไว ! // set x in coordinate pair ! public void setX( int xValue ) { ! ! x = xValue; // no need for validation ! } ! // set y in coordinate pair ! public void setY( int yValue ) { ! ! y = yValue; // no need for validation ! } “set” method 2 method นี้มีไวเพื่อ ........................................................................................................................................ ............................................................................................................................................................................................. ขั้นตอนที่ 5 สราง “get” method ตางๆ ตามที่ไดออกแบบไว ! // return x from coordinate pair ! public int getX() { ! ! return x; ! } ! // return y from coordinate pair ! public int getY() { ! ! return y; ! } “get” method 2 method นี้มีไวเพื่อ ....................................................................................................................................... ............................................................................................................................................................................................. ขั้นตอนที่ 6 สราง Facilities method ตางๆ ตามที่ไดออกแบบไว ! public static int getCount() { ! ! return count; ! } ! // return String representation of Point object ! public String toString() { ! ! return "[" + getX() + ", " + getY() + "]"; ! }! // finalizer ! protected void finalize() { ! ! count--; ! } Facilities method 3 method นี้มีไวเพื่อ ................................................................................................................................. ............................................................................................................................................................................................. ............................................................................................................................................................................................. ขั้นตอนที่ 7 ทำการ Compile โดยใชคำสั่ง .......................................................................................................................................................................... ผลลัพธที่ได .......................................................................................................................................................................... ขั้นตอนที่ 8 ทดสอบการทำงานของ Class Point เพียง Class เดียวกอน 1) สราง testPoint.html เอาไวสำหรับ Run 2) สราง testPoint.java เอาไวทดสอบ Class Point ตัวอยางหนาจอการทำงาน (http://202.44.47.108/~ssc/inheritance/testPoint.html) Page 2 of 6
  • 3. testPoint.html <html> ! <body> <h1>Test Class Point</h1> <h3>Create by: 5366261111 Supaporn Simcharoen IT1-RC</h3> ! ! <applet code="testPoint.class" height="200" width="400"> ! ! </applet> ! </body> </html> testPoint.java ขั้นตอนที่ 1 สราง Class พรอมกับ import package ที่ตองใช และสราง Method ที่นาจะมี import java.awt.*; import javax.swing.*; public class testPoint extends JApplet{ ! public void init(){ ! } ! public void paint(Graphics g) { ! } } method init มีไวเพื่อ ............................................................................................................................................................. method paint มีไวเพื่อ .......................................................................................................................................................... ขั้นตอนที่ 2 กำหนดคาเริ่มตนที่ method init พรอมกับตัวแปรตางๆ ที่ตองใช ! int num; ! Point p[] ; public void init() ! { ! ! String input; // user's input ! ! // obtain user's choice ! ! input = JOptionPane.showInputDialog("Enter number of point : " ); ! ! num = Integer.parseInt( input ); // convert input to int ! ! p = new Point[num]; ! ! for(int n = 0 ; n < p.length ; n++) { ! ! ! int x = 5 + (int) (Math.random() * 400); ! ! ! int y = 5 + (int) (Math.random() * 200); ! ! ! p[n] = new Point(x, y); ! ! } ! } // end method init Note:: .................................................................................................................................................................................. ............................................................................................................................................................................................. ขั้นตอนที่ 3 ทดลอง Compile และ Run วิธีในการ Run คือ ................................................................................................................................................................. ขั้นตอนที่ 4 กำหนดการทำงานใน method paint ! // draw shapes on applet's background ! public void paint( Graphics g ) ! { ! ! super.paint( g ); //call paint method inherited from JApplet ! ! for ( int n = 0; n < p.length; n++ ) { ! ! ! // set color ! ! ! g.setColor( new Color(255,0,0) ); ! ! ! // plot point ! ! ! g.drawLine( p[n].getX(), p[n].getY(), p[n].getX(), p[n].getY() ); ! ! } // end for ! ! showStatus("จำนวน Object : "+ Point.getCount()); ! } // end method paint Note:: .................................................................................................................................................................................. ............................................................................................................................................................................................. ขั้นตอนที่ 5 ทดลอง Compile และ Run อีกครั้ง Page 3 of 6
  • 4. Class Rectangle ขั้นตอนที่ 1 สราง Class Rectangle ขึ้นมา public class Rectangle extends Point { } Note:: .................................................................................................................................................................................. ขั้นตอนที่ 2 สราง Attribute ตางๆ ตามที่ไดออกแบบไว ! private int width = 10; ! private int height = 10; ! private static int count = 0; ขั้นตอนที่ 3 สราง Constructor method ตางๆ ตามที่ไดออกแบบไว ! public Rectangle() { ! } ! public Rectangle(int x, int y, int w, int h ) { ! ! super(x,y); ! ! setWidth(w); ! ! setHeight(h); ! } super(x,y); คือ ..................................................................................................................................................................... Constructor method 2 method นี้มีไวเพื่อ ............................................................................................................................ ............................................................................................................................................................................................ ขั้นตอนที่ 4 สราง “set” method ตางๆ ตามที่ไดออกแบบไว ! public void setWidth(int w) { ! ! width = w; ! } ! public void setHeight(int h) { ! ! height = h; ! } “set” method 2 method นี้มีไวเพื่อ ........................................................................................................................................ ............................................................................................................................................................................................. ขั้นตอนที่ 5 สราง “get” method ตางๆ ตามที่ไดออกแบบไว ! public int getWidth() { ! ! return width; ! } ! public int getHeight() { ! ! return height; ! } ! public int getArea() { ! ! return width*height; ! } ! public static int getCount() { ! ! return count; ! } “get” method 4 method นี้มีไวเพื่อ ....................................................................................................................................... ............................................................................................................................................................................................. ขั้นตอนที่ 6 สราง Facilities method ตางๆ ตามที่ไดออกแบบไว ! protected void finalize() { ! ! count--; ! } ! public String toString() { ! ! return "Point[x,y]Left = " + super.toString() + "; Width = " + ! ! getWidth() + "; Height = " + getHeight(); ! } Facilities method 2 method นี้มีไวเพื่อ ................................................................................................................................. ............................................................................................................................................................................................. ขั้นตอนที่ 7 ทำการ Compile โดยใชคำสั่ง .......................................................................................................................................................................... ผลลัพธที่ได .......................................................................................................................................................................... Page 4 of 6
  • 5. ขั้นตอนที่ 8 ทดสอบการทำงานของ Class Rectangle 1) สราง testRectangle.html เอาไวสำหรับ Run 2) สราง testRectangle.java เอาไวทดสอบ Class Rectangle ตัวอยางหนาจอการทำงาน (http://202.44.47.108/~ssc/inheritance/testRectangle.html) testRectangle.html <html> ! <body> <h1>Test Class Rectangle</h1> <h3>Create by: 5366261111 Supaporn Simcharoen IT1-RC</h3> ! ! <applet code="testRectangle.class" height="250" width="400"> ! ! </applet> ! </body> </html> testRectangel.java ขั้นตอนที่ 1 สราง Class พรอมกับ import package ที่ตองใช และสราง Method ที่นาจะมี import java.awt.*; import javax.swing.*; public class testRectangle extends JApplet{ ! public void init(){ ! } ! public void paint(Graphics g) { ! } } ขั้นตอนที่ 2 กำหนดคาเริ่มตนที่ method init พรอมกับตัวแปรตางๆ ที่ตองใช ! int x, y; ! Rectangle r ; ! public void init() ! { ! ! String input; // user's input ! ! // obtain user's choice ! ! input = JOptionPane.showInputDialog("Enter value x of left point : " ); ! ! x = Integer.parseInt( input ); // convert input to int ! ! input = JOptionPane.showInputDialog("Enter value y of left point : " ); ! ! y = Integer.parseInt( input ); // convert input to int ! ! int w = 10 + (int) (Math.random() * 280); ! ! int h = 10 + (int) (Math.random() * 180); ! ! r = new Rectangle(x, y, w, h); ! } // end method init Note:: .................................................................................................................................................................................. ............................................................................................................................................................................................. ขั้นตอนที่ 3 ทดลอง Compile และ Run Page 5 of 6
  • 6. ขั้นตอนที่ 4 กำหนดการทำงานใน method paint ! // draw shapes on applet's background ! public void paint( Graphics g ) ! { ! ! super.paint( g ); //call paint method inherited from JApplet ! ! // set color ! ! g.setColor( Color.ORANGE ); ! ! g.drawRect(r.getX(), r.getY(), r.getWidth(),r.getHeight() ); ! ! g.setColor( Color.BLUE ); ! ! g.drawString( "Point Left : " + r.getX() + ", " + r.getY(), r.getX(), r.getY()); ! ! g.drawString( "Width : " + r.getWidth() , r.getX(), r.getY() + 15); ! ! g.drawString( "Height : " + r.getHeight() , r.getX(), r.getY() + 30); ! ! g.drawString( "Area : " + r.getArea() , r.getX(), r.getY() + 45); ! } // end method paint Note:: .................................................................................................................................................................................. ............................................................................................................................................................................................. ขั้นตอนที่ 5 ทดลอง Compile และ Run อีกครั้ง การบาน แกไขการทำงานของ testRectangle ใหสามารถรับคาจำนวนของ Rectangle ที่จะสรางได ตัวอยางหนาจอการทำงาน (http://202.44.47.108/~ssc/inheritance-hw/testRectangle.html) Page 6 of 6