carshape.java~4~

来自「用JBuilder写的又一个接口示例程序,演示接口的用法,主要实现图形的移动.」· JAVA~4~ 代码 · 共 65 行

JAVA~4~
65
字号
package com.bemjh.Shape;

import java.awt.Graphics;

/**
 * <p>Title: MultiMoveableShape</p>
 *
 * <p>Description: MultiMoveable Shape</p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: bemjh</p>
 *
 * @author bemjh
 * @version 1.0
 */
public class CarShape implements IMoveable {
    // private variable
    //the object's coordinate
    private int x, y;
    // the object 's size
    private int size;

    public CarShape() {
    }

    /**
     * the  construct function
     * @param x  the object's x  coordinate
     * @param y  the object's y coordinate
     * @param size the size of the object
     */
    public CarShape(int x, int y, int size) {
        this.x = x;
        this.y = y;
        this.size = size;
    }
    /**
     * this function is to draw a graph
     *
     * @param g graphics object
     * @todo Implement this com.bemjh.Shape.IMoveable method
     */
    public void draw(Graphics g) {
        g.fillOval(x,y,x+size,y+size);
        g.fillOval(250-x,200-y,250-x+size,200-y+size);
    }

    /**
     * the function traslate is to increase the x and y of the object
     *
     * @param dx x direction to crease
     * @param dy y direction to crease
     * @todo Implement this com.bemjh.Shape.IMoveable method
     */
    public void translate(double dx, double dy) {
        if(x>500)
            x=0;
        if(y>300)
            y=0;
        x+=dx;
        y+=dy;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?