java 太阳系模型练习3-- 行星运行轨迹练习

这是一个使用Java编写的太阳系模型练习,包括星球类`Star`和行星类`Planet`,行星类扩展了星球类并实现了椭圆轨道的运动。程序中定义了太阳、地球、月球、火星以及其他行星,并根据离太阳的距离设置了不同的轨道参数。通过`draw`方法绘制星球和行星,`move`方法更新行星的位置,模拟行星沿椭圆轨道的移动。
摘要由CSDN通过智能技术生成

package solar;

import util.GameUtil;

import java.awt.*;

/**

  • 星球的共同属性
    */
    public class Star {//Star星
    Image img;
    double x,y;
    int width,height;

    //创建方法 :draw画;Graphics制图
    public void draw(Graphics g){//画图
    g.drawImage(img,(int)x,(int)y,null);

    }
    //2:创建空构造器
    public Star() {
    }
    //4:
    public Star(Image img) {
    this.img = img;
    //这样也可以
    this.width = img.getWidth(null);
    this.height = img.getHeight(null);
    }
    //创建构造器 加载星图片
    public Star(Image img, double x, double y) {
    this(img);//这样也可以
    //this.img = img;
    this.x = x;
    this.y = y;
    }
    //获取图片路径 用这个
    public Star(String imgpath,double x,double y){

     this(GameUtil.getImage(imgpath),x,y);
    

    }

    /public Star(Image img, double x, double y, int width, int height) {

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值