吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 5285|回复: 20
收起左侧

[Java 转载] 太阳系模型主要代码

[复制链接]
yy852 发表于 2016-11-17 14:41
1  solarFrame
[Java] 纯文本查看 复制代码
package cn.solar.test;

import java.awt.Graphics;
import java.awt.Image;

import cn.lsz.test1.Constant;
import cn.lsz.test1.GameUtil;
import cn.lsz.test1.MyFrame;





public class solarFrame1 extends MyFrame  {
	Image bg = GameUtil.getImage("images/bg.jpg");
	Star1 sun = new Star1("images/sun.jpg",Constant.GAME_WEIGHT/2,Constant.GAME_HEIGHT/2);//太阳
	Planet1 Mercury = new Planet1(sun, "images/Mercury.jpg", 100, 50, 0.1);//水星
	Planet1 Venus = new Planet1(sun, "images/Venus.jpg", 140, 80, 0.5);//金星
	Planet1 earth = new Planet1(sun, "images/earth.jpg", 170, 110, 0.2);//地球
	Planet1 moon = new Planet1(earth, "images/moon.jpg", 30, 20, 0.4,true);
    Planet1 Mars = new Planet1(sun, "images/Mars.jpg", 220, 140, 0.3);//火星
	Planet1 Jupiter = new Planet1(sun, "images/Jupiter.jpg", 290, 200, 0.08);//木星
	Planet1 Saturn = new Planet1(sun, "images/Saturn.jpg", 330, 230, 0.03);//土星
	Planet1 Uranus = new Planet1(sun, "images/Uranus.jpg", 370, 270, 0.1);//天王星
	Planet1 Neptune = new Planet1(sun, "images/Neptune.jpg", 400, 300, 0.05);//海王星
	@Override
	public void paint(Graphics g) {
		g.drawImage(bg, 0, 0, null);
		sun.draw(g);//太阳
		Mercury.draw(g);
		Venus.draw(g);
		earth.draw(g);//地球
		Mars.draw(g);//火星
		Jupiter.draw(g);
		Saturn.draw(g);
		Uranus.draw(g);
		Neptune.draw(g);
		moon.draw(g);
	}

	public static void main(String[] args) {
		new solarFrame1().launchFrame();
	}
	
}


2 Planet1
[Java] 纯文本查看 复制代码
package cn.solar.test;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;

import cn.lsz.test1.GameUtil;



public class Planet1 extends Star1 {
	double longAxis;
	double shortAxis;
	double speed;
	double dreege;
	Star1 center;
	
	boolean satellite;//卫星
	public void draw(Graphics s) {
		super.draw(s);
		move();
		if(!satellite)
		{
			drawTrace(s);			
		}
	}
	public void drawTrace(Graphics s) {
		double _x,_y,_width,_height;
		_width = longAxis*2;
		_height = shortAxis*2;
		_x = (center.x+center.width/2)-longAxis;
		_y = (center.y+center.height/2)-shortAxis;
		Color c = s.getColor();
		s.setColor(Color.blue);
		s.drawOval((int)_x,(int)_y,(int)_width, (int)_height);
		s.setColor(c);
	}
	public void move() {
		x = (center.x+center.width/2)+longAxis*Math.cos(dreege);
		y = (center.y+center.height/2)+shortAxis*Math.sin(dreege);
		dreege += speed;
	}

	public Planet1(Star1 center, String imgpath, double longAxis, double shortAxis, double speed ) {
		super(GameUtil.getImage(imgpath));
		this.center = center;
		this.x = center.x+longAxis;
		this.y = center.y;
		this.width = img.getWidth(null);
		this.height = img.getHeight(null);
		this.longAxis = longAxis;
		this.shortAxis = shortAxis;
		this.speed = speed;
		
	}
	public Planet1(Star1 center, String imgpath, double longAxis, double shortAxis, double speed,boolean satellite ) {
		
		this(center, imgpath, longAxis, shortAxis, speed);
		this.satellite = satellite;
	}
	public Planet1(Image img, double x, double y) {
		super(img, x, y);
		// TODO Auto-generated constructor stub
	}
	public Planet1(String imgpath, double x, double y) {
		super(imgpath, x, y);
		// TODO Auto-generated constructor stub
	}

}


3 Star1
[Java] 纯文本查看 复制代码
package cn.solar.test;

import java.awt.Graphics;
import java.awt.Image;

import cn.lsz.test1.GameUtil;

public class Star1 {
	Image img;
	double x,y;
	int width,height;
	public void draw(Graphics s) {
		s.drawImage(img, (int)x, (int)y, null);
	}
	public Star1(Image img) {
		this.img = img;
		this.width = img.getWidth(null);
		this.height = img.getHeight(null);
	}
	public Star1(Image img,double x,double y) {
		this(img);
		this.x = x;
		this.y = y;
	}
	public Star1(String imgpath,double x,double y) {
		this(GameUtil.getImage(imgpath), x, y);
	}
	
	
}


免费评分

参与人数 3热心值 +3 收起 理由
shun + 1 谢谢@Thanks!
湖北吴彦祖 + 1 不明觉厉
Angela小宝 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

ShadowY 发表于 2016-11-17 17:49
yy852 发表于 2016-11-17 15:48
java 写的一个模拟太阳系的小游戏吧。。。

是自动运行的太阳系还是可以人工控制?
 楼主| yy852 发表于 2016-11-17 21:22
 楼主| yy852 发表于 2016-11-17 14:43
源码,仅供参考。  支持一下!

solarSystem1.rar

75.3 KB, 下载次数: 24, 下载积分: 吾爱币 -1 CB

头像被屏蔽
总有刁民想阴朕 发表于 2016-11-17 14:51
提示: 作者被禁止或删除 内容自动屏蔽
QNLY 发表于 2016-11-17 14:53
好NB的样子
ShadowY 发表于 2016-11-17 14:59
楼主这是干嘛的?
润物细无声 发表于 2016-11-17 15:08
嗯,写的不错!!!!
 楼主| yy852 发表于 2016-11-17 15:47

我是新手,这是前几周写的、、
 楼主| yy852 发表于 2016-11-17 15:48
ShadowY 发表于 2016-11-17 14:59
楼主这是干嘛的?

java 写的一个模拟太阳系的小游戏吧。。。
 楼主| yy852 发表于 2016-11-17 15:49
润物细无声 发表于 2016-11-17 15:08
嗯,写的不错!!!!

我是新手,谢谢支持。
 楼主| yy852 发表于 2016-11-17 15:49

谢谢支持。。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-15 13:57

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表