Enviar pesquisa
Carregar
Applet 5 class_inheritance
•
0 gostou
•
271 visualizações
Nitigan Nakjuatong
Seguir
class_inheritance
Leia menos
Leia mais
Denunciar
Compartilhar
Denunciar
Compartilhar
1 de 6
Baixar agora
Baixar para ler offline
Recomendados
Applet 6 mouse_keyboard
Applet 6 mouse_keyboard
Nitigan Nakjuatong
ทบทวนเลขยกกำลัง
ทบทวนเลขยกกำลัง
Siriyupa Boonperm
3.parabola
3.parabola
Kuntoonbut Wissanu
Applet 7 image_j_panel
Applet 7 image_j_panel
Nitigan Nakjuatong
Applet 5 class_inheritance
Applet 5 class_inheritance
Nitigan Nakjuatong
662305 LAB13
662305 LAB13
Nitigan Nakjuatong
Array
Array
Nitigan Nakjuatong
New Assingment3 array2D
New Assingment3 array2D
Nitigan Nakjuatong
Recomendados
Applet 6 mouse_keyboard
Applet 6 mouse_keyboard
Nitigan Nakjuatong
ทบทวนเลขยกกำลัง
ทบทวนเลขยกกำลัง
Siriyupa Boonperm
3.parabola
3.parabola
Kuntoonbut Wissanu
Applet 7 image_j_panel
Applet 7 image_j_panel
Nitigan Nakjuatong
Applet 5 class_inheritance
Applet 5 class_inheritance
Nitigan Nakjuatong
662305 LAB13
662305 LAB13
Nitigan Nakjuatong
Array
Array
Nitigan Nakjuatong
New Assingment3 array2D
New Assingment3 array2D
Nitigan Nakjuatong
2.circle
2.circle
Tchai Siri
ใบงานที่ 2 ประเภทขององค์ประกอบของระบบสารสนเทศ.pdf
ใบงานที่ 2 ประเภทขององค์ประกอบของระบบสารสนเทศ.pdf
Nattapon
ใบงาน2
ใบงาน2
กิตติศักดิ์ ชยันตร์สุภาพ
Computer12
Computer12
นิตยา อินชาญ
Sing2
Sing2
krusing
แบบทดสอบบทที่1สมบัติของเลขยกกำลัง
แบบทดสอบบทที่1สมบัติของเลขยกกำลัง
Kru Wan Mirantee
แบบทดสอบบทที่1สมบัติของเลขยกกำลัง
แบบทดสอบบทที่1สมบัติของเลขยกกำลัง
Kru Wan Mirantee
Manual proteus (thai)
Manual proteus (thai)
Apple Nongmui
รายการสำรวจอุปกรณ์เทคโนโลยีเพื่อการศึกษา
รายการสำรวจอุปกรณ์เทคโนโลยีเพื่อการศึกษา
ราชประชานุเคราะห์ จังหวัดชุมพร
แบบฝึกหัดจำนวนจริงพื้นฐาน
แบบฝึกหัดจำนวนจริงพื้นฐาน
Nittaya Noinan
4สารบัญ
4สารบัญ
krupornpana55
ไบงานที่ 9
ไบงานที่ 9
thatlada5806
ไบงานที่ 9
ไบงานที่ 9
thatlada5806
ใบงาน
ใบงาน
เขมิกา กุลาศรี
Lesson2
Lesson2
โทโม๊ะจัง นานะ
การเขียนรายงาน
การเขียนรายงาน
Duangsuwun Lasadang
Intermediate Java Programming Language (in Thai)
Intermediate Java Programming Language (in Thai)
Thanachart Numnonda
Hand-on Exercise Java Web Programming
Hand-on Exercise Java Web Programming
IMC Institute
Book1-1
Book1-1
Suthep Lahan
Microsoft Office Word 2007
Microsoft Office Word 2007
Boonlert Aroonpiboon
วิธีการกำหนดสิทธิให้กับ Directory
วิธีการกำหนดสิทธิให้กับ Directory
Nitigan Nakjuatong
Applet 7 image_j_panel
Applet 7 image_j_panel
Nitigan Nakjuatong
Mais conteúdo relacionado
Semelhante a Applet 5 class_inheritance
2.circle
2.circle
Tchai Siri
ใบงานที่ 2 ประเภทขององค์ประกอบของระบบสารสนเทศ.pdf
ใบงานที่ 2 ประเภทขององค์ประกอบของระบบสารสนเทศ.pdf
Nattapon
ใบงาน2
ใบงาน2
กิตติศักดิ์ ชยันตร์สุภาพ
Computer12
Computer12
นิตยา อินชาญ
Sing2
Sing2
krusing
แบบทดสอบบทที่1สมบัติของเลขยกกำลัง
แบบทดสอบบทที่1สมบัติของเลขยกกำลัง
Kru Wan Mirantee
แบบทดสอบบทที่1สมบัติของเลขยกกำลัง
แบบทดสอบบทที่1สมบัติของเลขยกกำลัง
Kru Wan Mirantee
Manual proteus (thai)
Manual proteus (thai)
Apple Nongmui
รายการสำรวจอุปกรณ์เทคโนโลยีเพื่อการศึกษา
รายการสำรวจอุปกรณ์เทคโนโลยีเพื่อการศึกษา
ราชประชานุเคราะห์ จังหวัดชุมพร
แบบฝึกหัดจำนวนจริงพื้นฐาน
แบบฝึกหัดจำนวนจริงพื้นฐาน
Nittaya Noinan
4สารบัญ
4สารบัญ
krupornpana55
ไบงานที่ 9
ไบงานที่ 9
thatlada5806
ไบงานที่ 9
ไบงานที่ 9
thatlada5806
ใบงาน
ใบงาน
เขมิกา กุลาศรี
Lesson2
Lesson2
โทโม๊ะจัง นานะ
การเขียนรายงาน
การเขียนรายงาน
Duangsuwun Lasadang
Intermediate Java Programming Language (in Thai)
Intermediate Java Programming Language (in Thai)
Thanachart Numnonda
Hand-on Exercise Java Web Programming
Hand-on Exercise Java Web Programming
IMC Institute
Book1-1
Book1-1
Suthep Lahan
Microsoft Office Word 2007
Microsoft Office Word 2007
Boonlert Aroonpiboon
Semelhante a Applet 5 class_inheritance
(20)
2.circle
2.circle
ใบงานที่ 2 ประเภทขององค์ประกอบของระบบสารสนเทศ.pdf
ใบงานที่ 2 ประเภทขององค์ประกอบของระบบสารสนเทศ.pdf
ใบงาน2
ใบงาน2
Computer12
Computer12
Sing2
Sing2
แบบทดสอบบทที่1สมบัติของเลขยกกำลัง
แบบทดสอบบทที่1สมบัติของเลขยกกำลัง
แบบทดสอบบทที่1สมบัติของเลขยกกำลัง
แบบทดสอบบทที่1สมบัติของเลขยกกำลัง
Manual proteus (thai)
Manual proteus (thai)
รายการสำรวจอุปกรณ์เทคโนโลยีเพื่อการศึกษา
รายการสำรวจอุปกรณ์เทคโนโลยีเพื่อการศึกษา
แบบฝึกหัดจำนวนจริงพื้นฐาน
แบบฝึกหัดจำนวนจริงพื้นฐาน
4สารบัญ
4สารบัญ
ไบงานที่ 9
ไบงานที่ 9
ไบงานที่ 9
ไบงานที่ 9
ใบงาน
ใบงาน
Lesson2
Lesson2
การเขียนรายงาน
การเขียนรายงาน
Intermediate Java Programming Language (in Thai)
Intermediate Java Programming Language (in Thai)
Hand-on Exercise Java Web Programming
Hand-on Exercise Java Web Programming
Book1-1
Book1-1
Microsoft Office Word 2007
Microsoft Office Word 2007
Mais de Nitigan Nakjuatong
วิธีการกำหนดสิทธิให้กับ Directory
วิธีการกำหนดสิทธิให้กับ Directory
Nitigan Nakjuatong
Applet 7 image_j_panel
Applet 7 image_j_panel
Nitigan Nakjuatong
662305 LAB12
662305 LAB12
Nitigan Nakjuatong
Applet 4 class_composition
Applet 4 class_composition
Nitigan Nakjuatong
662305 11
662305 11
Nitigan Nakjuatong
662305 10
662305 10
Nitigan Nakjuatong
662305 09
662305 09
Nitigan Nakjuatong
Applet 3 design_class_composition
Applet 3 design_class_composition
Nitigan Nakjuatong
662305 08
662305 08
Nitigan Nakjuatong
Applet 2 container and action_listener
Applet 2 container and action_listener
Nitigan Nakjuatong
662305 Lab7new
662305 Lab7new
Nitigan Nakjuatong
Assingment3 array2 d
Assingment3 array2 d
Nitigan Nakjuatong
Lab 6 new
Lab 6 new
Nitigan Nakjuatong
Array2D
Array2D
Nitigan Nakjuatong
Method part2
Method part2
Nitigan Nakjuatong
Control structure
Control structure
Nitigan Nakjuatong
Method JAVA
Method JAVA
Nitigan Nakjuatong
Set putty to use numeric keyboard in pico
Set putty to use numeric keyboard in pico
Nitigan Nakjuatong
Putty basic setting
Putty basic setting
Nitigan Nakjuatong
Mais de Nitigan Nakjuatong
(19)
วิธีการกำหนดสิทธิให้กับ Directory
วิธีการกำหนดสิทธิให้กับ Directory
Applet 7 image_j_panel
Applet 7 image_j_panel
662305 LAB12
662305 LAB12
Applet 4 class_composition
Applet 4 class_composition
662305 11
662305 11
662305 10
662305 10
662305 09
662305 09
Applet 3 design_class_composition
Applet 3 design_class_composition
662305 08
662305 08
Applet 2 container and action_listener
Applet 2 container and action_listener
662305 Lab7new
662305 Lab7new
Assingment3 array2 d
Assingment3 array2 d
Lab 6 new
Lab 6 new
Array2D
Array2D
Method part2
Method part2
Control structure
Control structure
Method JAVA
Method JAVA
Set putty to use numeric keyboard in pico
Set putty to use numeric keyboard in pico
Putty basic setting
Putty basic setting
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
Baixar agora