Skip to content

Commit 20f87d8

Browse files
committed
added first implementation, without the use of factories
0 parents  commit 20f87d8

29 files changed

+427
-0
lines changed

.classpath

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
4+
<attributes>
5+
<attribute name="module" value="true"/>
6+
</attributes>
7+
</classpathentry>
8+
<classpathentry kind="src" path="src"/>
9+
<classpathentry kind="output" path="bin"/>
10+
</classpath>

.project

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Solar-J</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=11
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
13+
org.eclipse.jdt.core.compiler.release=enabled
14+
org.eclipse.jdt.core.compiler.source=11
2.08 KB
Binary file not shown.

bin/CelestialBodies/Planet.class

2.3 KB
Binary file not shown.

bin/CelestialBodies/Star.class

1.75 KB
Binary file not shown.

bin/Main/Main$1.class

1.17 KB
Binary file not shown.

bin/Main/Main.class

604 Bytes
Binary file not shown.

bin/Main/ProgramExecution$1.class

574 Bytes
Binary file not shown.

bin/Main/ProgramExecution$Panel.class

3.1 KB
Binary file not shown.

bin/Main/ProgramExecution.class

3.29 KB
Binary file not shown.

bin/module-info.class

169 Bytes
Binary file not shown.

resources/Earth.png

70.1 KB
Loading

resources/Jupiter.png

70.2 KB
Loading

resources/Mars.png

47.5 KB
Loading

resources/Mercury.png

32.6 KB
Loading

resources/Neptune.png

50.9 KB
Loading

resources/Saturn.png

44.6 KB
Loading

resources/Sun.png

65.1 KB
Loading

resources/Uranus.png

27.5 KB
Loading

resources/Venus.png

72.5 KB
Loading

resources/background.jpg

49.6 KB
Loading

resources/background.png

73 KB
Loading
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package CelestialBodies;
2+
3+
import java.awt.Color;
4+
import java.awt.Font;
5+
import java.awt.Graphics;
6+
import java.awt.Image;
7+
8+
public abstract class CelestialBody {
9+
public int mass;
10+
public String name;
11+
public int diameter;
12+
public double x;
13+
public double y;
14+
public boolean visible;
15+
public double distance;
16+
public int counter = 0;
17+
public Color color;
18+
public Image imageShown;
19+
20+
public double getXPosition(){
21+
return x;
22+
}
23+
public double getYPosition(){
24+
return y;
25+
}
26+
public int getMass(){
27+
return mass;
28+
}
29+
public int getDiameter(){
30+
return diameter;
31+
}
32+
public boolean displayText() {
33+
return visible;
34+
}
35+
public void setDisplayText(boolean b) {
36+
visible = b;
37+
}
38+
39+
public void draw(Graphics g, double size, double panX, double panY){
40+
g.setColor(color);
41+
g.fillOval((int)(panX+650+(x-diameter/2-650)*size), (int)(panY+500+(y-diameter/2-500)*size),
42+
(int)(diameter*size), (int)(diameter*size));
43+
44+
g.drawImage(this.imageShown,(int)(panX+650+(x-diameter/2-650)*size), (int)(panY+500+(y-diameter/2-500)*size),
45+
(int)(diameter*size), (int)(diameter*size),null);
46+
}
47+
public void displayText(Graphics g, double scale, double panX, double panY){
48+
g.setColor(color);
49+
g.setFont(new Font("Arial", Font.PLAIN, 15));
50+
g.setColor(color);
51+
52+
g.drawString((name),
53+
(int)(panX+650+(x-diameter/2-650)*scale), (int)(panY+500+(y-diameter/2-500)*scale));
54+
55+
}
56+
public String getName() {
57+
return name;
58+
}
59+
}

src/CelestialBodies/Planet.java

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package CelestialBodies;
2+
3+
import java.awt.Color;
4+
import java.io.File;
5+
import java.io.IOException;
6+
7+
import javax.imageio.ImageIO;
8+
9+
public class Planet extends CelestialBody{
10+
public double velX;
11+
public double velY;
12+
public double speed;
13+
public double acceleration;
14+
public double xDirection;
15+
public double yDirection;
16+
public int orbitDots[][];
17+
18+
public Planet(double xLoc, double yLoc, double velX, double velY, int mass, int diameter, Color color, double speed, String name) {
19+
this.mass = mass;
20+
this.name = name;
21+
this.diameter = diameter;
22+
this.x = xLoc;
23+
this.y = yLoc;
24+
this.velX = velX;
25+
this.velY = velY;
26+
this.speed = 0;
27+
this.acceleration = 0;
28+
this.xDirection = 0;
29+
this.yDirection = 0;
30+
this.distance = 0;
31+
this.orbitDots = new int[1000][2];
32+
this.counter = 0;
33+
this.color = color;
34+
try {
35+
this.imageShown = ImageIO.read(new File("resources/" + name + ".png"));
36+
} catch (IOException e) {
37+
e.printStackTrace();
38+
}
39+
}
40+
41+
public void move()
42+
{
43+
x += velX;
44+
y += velY;
45+
}
46+
47+
public void update(double StarX, double StarY, int StarMass)
48+
{
49+
if (visible){
50+
orbitDots[counter][0]=(int)(x+.5);
51+
orbitDots[counter][1]=(int)(y+.5);
52+
counter = (counter+1)%1000;
53+
}
54+
else{
55+
orbitDots = new int[1000][2];
56+
counter = 0;
57+
}
58+
distance = Math.sqrt((StarX - x)*(StarX - x) + (StarY - y)*(StarY - y));
59+
60+
acceleration = StarMass/distance/distance;
61+
62+
xDirection = (StarX-x)/distance;
63+
yDirection = (StarY-y)/distance;
64+
65+
velX += xDirection * acceleration;
66+
velY += yDirection * acceleration;
67+
move();
68+
69+
}
70+
public double getSpeed() {
71+
return speed;
72+
}
73+
public void setSpeed(double speed) {
74+
this.speed = speed;
75+
}
76+
77+
}

src/CelestialBodies/Star.java

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package CelestialBodies;
2+
3+
import java.awt.Color;
4+
import java.awt.Graphics;
5+
import java.io.File;
6+
import java.io.IOException;
7+
8+
import javax.imageio.ImageIO;
9+
10+
public class Star extends CelestialBody{
11+
12+
public Star(double xLoc, double yLoc, double velX, double velY, int mass, int diameter, Color color, double speed, String name) {
13+
this.mass = mass;
14+
this.name = name;
15+
this.diameter = diameter;
16+
this.x = xLoc;
17+
this.y = yLoc;
18+
this.distance = 0;
19+
this.counter = 0;
20+
this.color = color;
21+
try {
22+
this.imageShown = ImageIO.read(new File("resources/" + name + ".png"));
23+
} catch (IOException e) {
24+
e.printStackTrace();
25+
}
26+
}
27+
28+
public void drawSunshine(Graphics g, double size, double panX, double panY) {
29+
g.setColor(new Color(219, 113, 20, 50));
30+
g.fillOval((int)(panX+650+(x-(diameter * 1.8)/2-650)*size), (int)(panY+500+(y-(diameter * 1.8)/2-500)*size),
31+
(int)((diameter * 1.8)*size), (int)((diameter * 1.8)*size));
32+
}
33+
34+
35+
36+
37+
}

src/Main/Main.java

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package Main;
2+
3+
import java.awt.Color;
4+
import javax.swing.*;
5+
6+
public class Main extends JPanel {
7+
8+
private static final long serialVersionUID = 1L;
9+
public static void main(String[] args) {
10+
SwingUtilities.invokeLater(new Runnable() {
11+
@Override
12+
public void run() {
13+
System.out.println("Starting Application...");
14+
JFrame viewport = new JFrame("Solar-J - A visual representation of the solar system");
15+
viewport.setContentPane(new ProgramExecution());
16+
viewport.setBackground(Color.BLACK);
17+
viewport.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
18+
viewport.pack();
19+
viewport.setLocationRelativeTo(null);
20+
viewport.setVisible(true);
21+
}
22+
});
23+
24+
}
25+
26+
}

0 commit comments

Comments
 (0)