-Mars has one of the highest orbital eccentricities of any planet in our solar system (other than Mercury and Pluto) -- its distance from the Sun varies between 1.38 and 1.67 AU over the Martian year. This large variation, combined with an axial tilt slightly greater than Earth's, gives rise to seasonal changes far greater than we experience here on Earth.
-Jupiter has an axial tilt of only 3 degrees, so there is literally no difference between the seasons. However, because of its distance from the sun, seasons change more slowly. The length of each season is roughly three years. Jupiter is the fastest spinning planet in our Solar System, which causes the planet to flatten at the poles and bulge at the equator.
/**
* Title: Three Body Problem, Earth, Sun and Jupiter Euler Method
* @ */
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Graphics;
import java.awt.RenderingHints;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
public class PracticalTest1_AliahSyafinah extends javax.swing.JFrame {
public PracticalTest1_AliahSyafinah() {
initComponents();
}
Graphics2D gg;
@Override
public void paint(Graphics g){
gg = (Graphics2D) g;
super.paint(gg);
gg=(Graphics2D)PlotPanel.getGraphics();
}
double convfx, convfy;
int offsetj,offseti;
public void initPlot(double x1,double y1,double x2, double y2,
int xoffset,int yoffset){
convfx=PlotPanel.getWidth()/(x2-x1);
convfy=PlotPanel.getHeight()/(y2-y1);
double dpx = xoffset/100.0;
double dpy = yoffset/100.0;
offseti=(int)(PlotPanel.getWidth()*dpx);
offsetj=(int)(PlotPanel.getHeight()*dpy);
double W = PlotPanel.getWidth();
double H = PlotPanel.getHeight();
gg.drawLine(0, offsetj ,PlotPanel.getWidth(),offsetj );
gg.drawLine(offseti, 0,offseti,PlotPanel.getHeight());
//PlotPanel.setBackground(Color.YELLOW);
//draw scale x
for(int l=0;l<PlotPanel.getWidth();l=l+50){
gg.drawLine(offseti+l, offsetj,offseti+l,offsetj+5);
gg.drawString(""+String.format("%.1f",x2*(l/W)), offseti+l, offsetj+15);
}
//draw scale y
for(int l=0;l<PlotPanel.getHeight();l=l+20){
gg.drawLine(offseti, offsetj-l,offseti-5,offsetj-l);
gg.drawString(""+String.format("%.1f",y2*(l/H)), offseti-35, offsetj-l);
}
}
public void plotPoint(double datax, double datay){
double sx,sy;
int i,j;
//calculate screen coordinates
sx=datax*convfx;
sy=datay*convfy;
//converst to integer plus axis offset
i=offseti+(int)sx;
j=offsetj-(int)sy;
gg.drawLine(i,j,i,j);
}
private void setPenSize (int penSize) {
gg.setStroke(new BasicStroke(penSize));
gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
}
//Urusan File
public PrintStream openfile (String filename){
PrintStream ps = null;
try{
ps = new PrintStream (new FileOutputStream(filename));
}catch (IOException e){
System.err.printf("\nProblem creating file:%s\n\n",filename);}
return ps;
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
PlotPanel = new javax.swing.JPanel();
plotButton = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jTextField5 = new javax.swing.JTextField();
jTextField6 = new javax.swing.JTextField();
jTextField7 = new javax.swing.JTextField();
jTextField8 = new javax.swing.JTextField();
jLabel17 = new javax.swing.JLabel();
jLabel19 = new javax.swing.JLabel();
jTextField9 = new javax.swing.JTextField();
jTextField10 = new javax.swing.JTextField();
jLabel18 = new javax.swing.JLabel();
jTextField11 = new javax.swing.JTextField();
jLabel13 = new javax.swing.JLabel();
jLabel14 = new javax.swing.JLabel();
jLabel15 = new javax.swing.JLabel();
jLabel20 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel21 = new javax.swing.JLabel();
jLabel16 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jTextField3 = new javax.swing.JTextField();
jTextField12 = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel5 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
PlotPanel.setBackground(new java.awt.Color(204, 204, 255));
javax.swing.GroupLayout PlotPanelLayout = new javax.swing.GroupLayout(PlotPanel);
PlotPanel.setLayout(PlotPanelLayout);
PlotPanelLayout.setHorizontalGroup(
PlotPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 303, Short.MAX_VALUE)
);
PlotPanelLayout.setVerticalGroup(
PlotPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 256, Short.MAX_VALUE)
);
plotButton.setFont(new java.awt.Font("Gravedigger", 0, 18)); // NOI18N
plotButton.setText("PLOT");
plotButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
plotButtonActionPerformed(evt);
}
});
jLabel1.setFont(new java.awt.Font("Gravedigger", 0, 24)); // NOI18N
jLabel1.setText("effect of jupiter on mars");
jLabel6.setFont(new java.awt.Font("Futurist Fixed-width", 0, 12)); // NOI18N
jLabel6.setText("POSITION (AU)");
jLabel7.setFont(new java.awt.Font("Futurist Fixed-width", 0, 11)); // NOI18N
jLabel7.setText("VELOCITY ");
jLabel8.setFont(new java.awt.Font("Futurist Fixed-width", 0, 24)); // NOI18N
jLabel8.setText("MARS");
jLabel8.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 51, 0), 3));
jLabel9.setFont(new java.awt.Font("Futurist Fixed-width", 0, 24)); // NOI18N
jLabel9.setText("JUPITER");
jLabel9.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 153, 153), 2));
jLabel10.setText("x-component");
jLabel11.setText("y-component");
jLabel12.setText("x-component");
jTextField1.setText("1.52 ");
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jTextField2.setText("0.0");
jTextField4.setText("5.2");
jTextField4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField4ActionPerformed(evt);
}
});
jTextField5.setText("0.0");
jTextField5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField5ActionPerformed(evt);
}
});
jTextField6.setText("1.618*Pi");
jTextField6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField6ActionPerformed(evt);
}
});
jTextField7.setText("0.0");
jTextField7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField7ActionPerformed(evt);
}
});
jTextField8.setText("0.873*Pi");
jTextField8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField8ActionPerformed(evt);
}
});
jLabel17.setFont(new java.awt.Font("Futurist Fixed-width", 0, 12)); // NOI18N
jLabel17.setText("PERIOD, T ");
jLabel19.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Picture5.jpg"))); // NOI18N
jTextField9.setText("1.0075");
jTextField10.setText("1.015");
jTextField10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField10ActionPerformed(evt);
}
});
jLabel18.setText("y-component");
jTextField11.setText("0.0");
jTextField11.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField11ActionPerformed(evt);
}
});
jLabel13.setText("x-component");
jLabel14.setText("y-component");
jLabel15.setText("x-component");
jLabel20.setText("y-component");
jLabel2.setFont(new java.awt.Font("Futurist Fixed-width", 0, 12)); // NOI18N
jLabel2.setText("where, T = Period");
jLabel3.setFont(new java.awt.Font("Futurist Fixed-width", 0, 12)); // NOI18N
jLabel3.setText("and a = semimajor of orbit.");
jLabel21.setFont(new java.awt.Font("Futurist Fixed-width", 0, 12)); // NOI18N
jLabel21.setText("(ORBIT/YEAR)");
jLabel16.setFont(new java.awt.Font("Futurist Fixed-width", 0, 11)); // NOI18N
jLabel16.setText("(AU/YEAR)");
jLabel4.setFont(new java.awt.Font("Futurist Fixed-width", 0, 12)); // NOI18N
jLabel4.setText("MASS (KG)");
jTextField3.setText("6.39E23");
jTextField12.setText("2000.0E27");
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jTextArea1.setText("RESULT: \nWE CAN SEE, THE ORBIT OF MARS \nIS STABLE WHEN THE MASS OF \nJUPITER IS SET TO ITS TRUE MASS.\n\nOTHERWISE, THE ORBIT OF MARS \nIS UNSTABLE WHEN THE MASS OF \nJUPITER IS 1000 TIMES ITS \nTRUE MASS.\n");
jScrollPane1.setViewportView(jTextArea1);
jLabel5.setText("**1000 times its true mass.");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(252, 252, 252)
.addComponent(jLabel8))
.addGroup(layout.createSequentialGroup()
.addGap(34, 34, 34)
.addComponent(PlotPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(38, 38, 38)
.addComponent(jLabel3))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(38, 38, 38)
.addComponent(jLabel2))
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(jLabel19)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(plotButton)
.addGap(63, 63, 63))))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel21)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel7)
.addComponent(jLabel16)
.addComponent(jLabel6)
.addComponent(jLabel4))
.addGap(37, 37, 37)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel11)
.addComponent(jLabel10)
.addGroup(layout.createSequentialGroup()
.addGap(81, 81, 81)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTextField1)
.addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE)
.addComponent(jTextField2)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel14)
.addComponent(jLabel13))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField5, javax.swing.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE)))
.addComponent(jTextField9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 91, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel9)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel15)
.addComponent(jLabel20))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTextField7)
.addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel12)
.addComponent(jLabel18))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField11)
.addComponent(jTextField4)
.addComponent(jTextField12)
.addComponent(jTextField10))))
.addGap(34, 34, 34)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE))))))))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel17)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(160, 160, 160)
.addComponent(jLabel1)
.addGap(0, 0, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(PlotPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel19, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2))
.addComponent(plotButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8)
.addComponent(jLabel9))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(13, 13, 13)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel21, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel10)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel11)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel12)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(15, 15, 15)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel18)
.addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(18, 18, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel16))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel13))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel14))))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel15))
.addGap(15, 15, 15)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel20))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(29, 29, 29)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
);
pack();
}// </editor-fold>
private void plotButtonActionPerformed(java.awt.event.ActionEvent evt) {
initPlot(0.0,0.0,12.0,12.0,50,50);
setPenSize(1);
double x_m[]= new double [10000]; //position mars
double y_m[]= new double [10000];
double x_j[]=new double [10000]; //position jupiter
double y_j[]=new double [10000];
double v_x_m[]=new double [10000]; // vx mars
double v_y_m[]=new double [10000]; //vy mars
double v_x_j[]=new double [10000]; //vx jup
double v_y_j[]=new double [10000]; //vy jup
//mass m=mars, j= jupiter, s=sun, e=earth
double m_m = 6.39E23;
double m_j=2000.0E27;
double m_s=2.0E30;
// double m_e=6E24;
double dt=0.01;
/* double x_e[]= new double [10000];
double y_e[]= new double [10000];
double v_x_e[]=new double [10000];
double v_y_e[]=new double [10000];
*/
calculateJupiterMars(x_m, v_x_m, y_m, v_y_m, x_j, v_x_j, y_j, v_y_j, m_s, m_m, m_j, dt);
//calculateEarth(x_e, v_x_e, y_e, v_y_e, x_j, v_x_j , y_j, v_y_j,m_s, m_e, m_j,dt);
}
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField8ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField11ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField10ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
public double calculateJupiterMars(double x_m[], double v_x_m[],double y_m [],double v_y_m [],double x_j[], double v_x_j[] , double y_j[], double v_y_j[],double m_s, double m_m,
double m_j,double dt){
double r_m, r_j, r_mj, r_mjx, r_mjy;
double Pi=Math.PI;
x_m[0]=1.52; x_j[0]=5.2; y_m[0]=0; y_j[0]=0;
v_x_m[0]=0; v_y_m[0]=1.618*Pi;
v_x_j[0]=0; v_y_j[0]=0.873*Pi;
for (int i=0; i<10000-1; i++){
r_m = Math.sqrt(x_m[i]*x_m[i] + y_m[i]*y_m[i]); //distance mars from sun
r_j= Math.sqrt(x_j[i]*x_j[i] + y_j[i]*y_j[i]);// distance jupiter from sun
//distance mars - jupiter
r_mjx= x_m[i]-x_j[i] ; // xcomponent
r_mjy= y_m[i]-y_j[i]; //ycomp
//mag distance mar-jup
r_mj=Math.sqrt(r_mjx*r_mjx + r_mjy*r_mjy);
//velocity mars
v_x_m[i+1]= v_x_m[i]-(4*Pi*Pi*x_m[i]*dt)/(r_m*r_m*r_m)
- ((4*Pi*Pi)*(m_j/m_s)*(x_m[i]-x_j[i]*dt)/(r_mj*r_mj*r_mj)) ;
v_y_m[i+1]= v_y_m[i]-(4*Pi*Pi*y_m[i]*dt)/(r_m*r_m*r_m)
- (4*Pi*Pi*(m_j/m_s)*(y_m[i]-y_j[i]*dt)/(r_mj*r_mj*r_mj));
//velocity jupiter
v_x_j[i+1]= v_x_j[i]-(4*Pi*Pi*x_j[i]*dt)/(r_j*r_j*r_j)
- (4*Pi*Pi*(m_m/m_s)*(x_j[i]-x_m[i]*dt)/(r_mj*r_mj*r_mj));
v_y_j[i+1]=v_y_j[i]-(4*Pi*Pi*y_j[i]*dt)/(r_j*r_j*r_j)
- (4*Pi*Pi*(m_m/m_s)*(y_j[i]-y_m[i]*dt)/(r_mj*r_mj*r_mj));
//position any for each planet
x_m[i+1]= x_m[i] + v_x_m[i+1]*dt; //mars
y_m[i+1]= y_m[i] + v_y_m[i+1]*dt;
x_j[i+1]= x_j[i] + v_x_j[i+1]*dt; //jupiter
y_j[i+1]= y_j[i] + v_y_j[i+1]*dt;
gg.setColor(Color.RED);
gg.drawString("Mars" , offseti+10, offsetj+60);
plotPoint(x_m[i],y_m[i]); //plot position mars
gg.setColor(Color.BLUE);
gg.drawString("Jupiter" , offseti+80, offsetj+30);
plotPoint(x_j[i],y_j[i]); //plot position jupiter
}
return 0;
}
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing...
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(PracticalTest1_AliahSyafinah.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(PracticalTest1_AliahSyafinah.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(PracticalTest1_AliahSyafinah.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(PracticalTest1_AliahSyafinah.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new PracticalTest1_AliahSyafinah().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JPanel PlotPanel;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel15;
private javax.swing.JLabel jLabel16;
private javax.swing.JLabel jLabel17;
private javax.swing.JLabel jLabel18;
private javax.swing.JLabel jLabel19;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel20;
private javax.swing.JLabel jLabel21;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField10;
private javax.swing.JTextField jTextField11;
private javax.swing.JTextField jTextField12;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
private javax.swing.JTextField jTextField6;
private javax.swing.JTextField jTextField7;
private javax.swing.JTextField jTextField8;
private javax.swing.JTextField jTextField9;
private javax.swing.JButton plotButton;
// End of variables declaration
}
SpaceApps is a NASA incubator innovation program.