<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 303  文章 - 883  trackbacks - 0
    <2007年2月>
    28293031123
    45678910
    11121314151617
    18192021222324
    25262728123
    45678910

    歡迎光臨! 
    閑聊 QQ:1074961813

    隨筆分類(357)

    我管理的群

    公共blog

    • n維空間
    • Email : java3d@126.com 群 : 12999758

    參與管理的論壇

    好友的blog

    我的其他blog

    朋友的網站

    搜索

    •  

    最新評論

    Shape Example

    1. Point.java

    ?public class Point
    {
    ??? private float mfX, mfY;

    ??? public Point() {
    ??????? mfX = mfY = 0.0f;
    ??? }

    ??? public Point(float fX, float fY) {
    ??????? mfX = fX;
    ??????? mfY = fY;
    ??? }

    ??? public Point(Point p) {
    ??????? mfX = p.mfX;
    ??????? mfY = p.mfY;
    ??? }

    ??? // You will generally not need to write a finalizer. Member variables that
    ??? // are of reference type will be automatically garbage collected once they
    ??? // are no longer in use. Finalizers are only for cleaning up system resources,
    ??? // e.g. closing files.
    ??? protected void finalize() throws Throwable {
    ??????? System.out.print("In Point finalizer: ");
    ??????? print();
    ??????? super.finalize();? // If you have to write a finalizer, be sure to do this.
    ??? }

    ??? public void print() {
    ??????? System.out.println("Point print: (" + mfX + "," + mfY + ")");
    ??? }
    }

    2. Shape.java

    ?public abstract class Shape
    {
    ??? private Point mCenter;
    ??? protected static int miCount = 0;? // An example of a static member variable.

    ??? public Shape() {
    ??????? mCenter = new Point();
    ??? }

    ??? public Shape(Point p) {
    ??????? mCenter = new Point(p);
    ??? }

    ??? // You will generally not need to write a finalizer.?Member variables that
    ??? // are of reference type (i.e. mCenter) will be automatically garbage collected
    ??? // once they are no longer in use. Finalizers are only for cleaning up system
    ??? // resources, e.g. closing files.
    ??? protected void finalize() throws Throwable {
    ??????? System.out.print("In Shape finalizer: ");
    ??????? print();
    ??????? super.finalize();? // If you have to write a finalizer, be sure to do this.
    ??? }

    ??? public void print() {
    ??????? System.out.print("Shape print: mCenter = ");
    ??????? mCenter.print();
    ??? }

    ??? // An example of a static member function.
    ??? public static int getCount() {
    ??????? return miCount;? // Can only access static members in static functions.
    ??? }
    }

    3. Circle.java

    ?public class Circle extends Shape
    {
    ??? private float mfRadius;

    ??? public Circle() {
    ??????? super();? // Call the base class constructer.
    ??????? mfRadius = 0.0f;
    ??????? miCount++;? // Can access this because it is protected in base class.
    ??? }

    ??? public Circle(float fX, float fY, float fRadius) {
    ??????? super(new Point(fX, fY));? // Call the base class constructer.
    ??????? mfRadius = fRadius;
    ??????? miCount++;
    ??? }

    ??? public Circle(Point p, float fRadius) {
    ??????? super(p);? // Call the base class constructer.
    ??????? mfRadius = fRadius;
    ??????? miCount++;
    ??? }

    ??? // You will generally not need to write a finalizer. Member variables that
    ??? // are of reference type (i.e. mCenter) will be automatically garbage collected
    ??? // once they are no longer in use.?Finalizers are only for cleaning up system
    ??? // resources, e.g. closing files.
    ??? protected void finalize() throws Throwable {
    ??????? System.out.print("In Circle finalizer: ");
    ??????? print();
    ??????? super.finalize();? // If you have to write a finalizer, be sure to do this.
    ??? }

    ??? public void print() {
    ??????? System.out.print("Circle print: mfRadius = " + mfRadius + " ");
    ??????? super.print();
    ??? }
    }

    4. Square.java

    ?public class Square extends Shape
    {
    ??? private float mfLength;

    ??? public Square() {
    ??????? super();? // Call the base class constructer.
    ??????? mfLength = 0.0f;
    ??????? miCount++;? // Can access this because it is protected in base class.
    ??? }

    ??? public Square(float fX, float fY, float fLength) {
    ??????? super(new Point(fX, fY));? // Call the base class constructer.
    ??????? mfLength = fLength;
    ??????? miCount++;
    ??? }

    ??? public Square(Point p, float fLength) {
    ??????? super(p);? // Call the base class constructer.
    ??????? mfLength = fLength;
    ??????? miCount++;
    ??? }

    ??? // You will generally not need to write a finalizer.?Member variables that
    ??? // are of reference type (i.e. mCenter) will be automatically garbage collected
    ??? // once they are no longer in use.?Finalizers are only for cleaning up system
    ??? // resources, e.g. closing files.
    ??? protected void finalize() throws Throwable {
    ??????? System.out.print("In Square finalizer: ");
    ??????? print();
    ??????? super.finalize();? // If you have to write a finalizer, be sure to do this.
    ??? }

    ??? public void print() {
    ??????? System.out.print("Square print: mfLength = " + mfLength + " ");
    ??????? super.print();
    ??? }
    }

    5. Main.java

    ?public class Main
    {
    ??? final static int MAX = 3;? // An example of a constant class member variable.

    ??? public static void main(String[] args)
    ??? {
    ??????? // Create some Point objects.
    ??????? Point a;
    ??????? a = new Point();
    ??????? a.print();

    ??????? Point b;
    ??????? b = new Point(2,3);
    ??????? b.print();

    ??????? Point c = new Point(b);
    ??????? c.print();

    ??????? // Print out the total number of Shapes created so far.?At this point,
    ??????? // no Shapes have been created, however, we can still access static member
    ??????? // function Shape.getCount().
    ??????? System.out.println("Total number of Shapes = " + Shape.getCount());

    ??????? // Create a Circle object and hold on to it using a Shape reference.
    ??????? Shape s;
    ??????? s = new Circle(a,1);
    ??????? s.print(); // This will call the print method in Circle.

    ??????? // Create an array of Shapes.
    ??????? Shape[] shapeArray;
    ??????? shapeArray = new Shape[MAX];? // An array of Shape references.

    ??????? shapeArray[0] = new Square();
    ??????? shapeArray[1] = new Circle(4,5,2);
    ??????? shapeArray[2] = new Square(3,3,1);

    ??????? // Print out the array of Shapes. The length member gives the array size.
    ??????? for (int i = 0; i < shapeArray.length; i++) {
    ??????????? shapeArray[i].print();
    ??????? }

    ??????? // Print out the total number of Shapes created so far. At this point,
    ??????? // 4 Shapes have been created.
    ??????? System.out.println("Total number of Shapes = " + Shape.getCount());

    ??????? // We can mark the objects for destruction by removing all references to
    ??????? // them.?Normally, we do not need to call the garbage collector explicitly.
    ??????? // Note: here we have not provided a way to decrement the Shape counter.
    ??????? a = b = c = null;
    ??????? s = null;
    ??????? for (int i = 0; i < shapeArray.length; i++) {
    ??????????? shapeArray[i] = null;
    ??????? }
    ??????? shapeArray = null;
    ??? }
    }



    地震讓大伙知道:居安思危,才是生存之道。
    posted on 2007-02-25 15:39 小尋 閱讀(253) 評論(0)  編輯  收藏 所屬分類: j2se/j2ee/j2me
    主站蜘蛛池模板: 五月婷婷亚洲综合| 十八禁的黄污污免费网站| 亚洲av无码专区在线| 羞羞视频免费网站日本| 免费a级毛片永久免费| 亚洲成a人无码亚洲成av无码 | 男人的天堂av亚洲一区2区| 黄+色+性+人免费| 亚洲黄色免费电影| 亚洲成年人免费网站| 亚洲国产亚洲片在线观看播放 | 毛片在线播放免费观看| 亚洲va久久久噜噜噜久久男同| 中文字幕免费在线观看动作大片| 亚洲国产精品无码久久一区二区 | 欧洲美熟女乱又伦免费视频| 亚洲6080yy久久无码产自国产| 国产自产拍精品视频免费看| 一级做a爰片性色毛片免费网站 | 亚洲熟妇色自偷自拍另类| ww4545四虎永久免费地址| 国产成人亚洲综合网站不卡| 国产精品国产免费无码专区不卡| 九九久久国产精品免费热6| 亚洲啪啪AV无码片| 国产国产人免费视频成69堂| 亚洲精品国产摄像头| 国产成人亚洲精品影院| 日韩精品在线免费观看| 亚洲中字慕日产2021| 少妇亚洲免费精品| 中文字幕免费不卡二区| 久久精品亚洲AV久久久无码| 国产一区视频在线免费观看 | 国产免费一区二区三区在线观看| 91亚洲国产成人久久精品网站| 成全视频在线观看免费高清动漫视频下载 | 人禽伦免费交视频播放| 久久久久亚洲精品无码蜜桃| 日韩在线免费播放| 精品一卡2卡三卡4卡免费视频|