import javax.swing.JPanel; import java.awt.*; import java.awt.event.*; import javax.swing.border.*; import javax.swing.*; /** *
Title: Data Dictionary Architect
*Description: All of data elements to be documented and data links to be established between business areas.
*Copyright: Copyright (c) 2005
*Company: NASA
* @author Aaron Wilson * @version 1.0 */ public class OrbitPanel extends JPanel implements Runnable, MouseListener { int eX, eY, sX, sY; int radinpix = 36, sRad=5; int gsradinpix = (int)(radinpix*6.6107); double X=6600, Y=0, VV = 0, VX = 0, VY = 7.9; double theta = 90., hc, vc; double DltT = 25.; double radinkms = 6378.15; // radius of Earth (in kms)35,786km // int radinpix = 160; // radius of Earth (in kms) long rate; long lastUpdate; private boolean running = true; public OrbitPanel(long rate_ms) { rate = rate_ms; setBorder(new EtchedBorder(EtchedBorder.LOWERED)); addMouseListener(this); eX = 400; eY = 330; sX = 300; sY = 300; sRad = 5; this.setFocusable(true); this.grabFocus(); } public void goUp() { VX+=.003*Math.cos(theta)*DltT; VY+=.003*Math.sin(theta)*DltT; } public void goDown() { // theta+=Math.PI; } public void goLeft() { theta-=.1; } public void goRight() { theta+=.1; } public void paint(Graphics g) { super.paint(g); Graphics2D g2 = (Graphics2D) g; g2.setColor(Color.blue); g2.fillOval(eX-radinpix, eY-radinpix, radinpix << 1, radinpix << 1); g2.setColor(Color.lightGray); g2.drawOval(eX-gsradinpix, eY-gsradinpix, gsradinpix << 1, gsradinpix << 1); calculateOrbit(); g2.setColor(Color.red); g2.fillOval(sX-1, sY-1, 2, 2); g2.setColor(Color.blue); hc = Math.cos(theta); vc = Math.sin(theta); g2.drawLine((int)(sX+(-1*hc-vc/2)*sRad),(int)(sY+(-1*vc+hc/2)*sRad), (int)(sX+1*hc*sRad),(int)(sY+1*vc*sRad)); g2.drawLine((int)(sX+(-1*hc+vc/2)*sRad),(int)(sY+(-1*vc-hc/2)*sRad), (int)(sX+1*hc*sRad),(int)(sY+1*vc*sRad)); } private void calculateOrbit() { double t, rad; double g1X, g1Y; double VYavg = 0,VXavg = 0,VX1 = 0,VY1 = 0; // double Y = -radinkms*1.05,X = 0; double grav, grav0 = .0098; rad = Math.sqrt(Math.pow(X,2) + Math.pow(Y,2)); grav = grav0 * (6378.15/rad) * (6378.15/rad); // t = t + DltT; g1X = -(X/rad) * grav; g1Y = -(Y/rad) * grav; VX1 = VX + DltT*g1X; VY1 = VY + DltT*g1Y; X = X + DltT * (VX + VX1) / 2 ; Y = Y + DltT * (VY + VY1) / 2 ; // drawOrbit(x,z,Vx1,Vz1); VX = VX1; VY = VY1; VV = Math.sqrt(Math.pow(VX,2) + Math.pow(VY,2)); sX = eX + (int)(radinpix*X/radinkms); sY = eY + (int)(radinpix*Y/radinkms); // System.out.println(sX+" "+sY+" "+X+" "+Y+" "+VX+" "+VY+" "+gX+" "+gY); } /** * run */ public void run() { long ct; while (running) { ct = System.currentTimeMillis(); if ( (ct - lastUpdate) >= rate) { //calculateOrbit(); repaint(); lastUpdate = System.currentTimeMillis(); } else { try { Thread.sleep(rate >> 1); } catch (InterruptedException ex) { } } } } /** * keyPressed * * @param e KeyEvent */ public void keyPressed(KeyEvent e) { } /** * keyReleased * * @param e KeyEvent */ public void keyReleased(KeyEvent e) { } /** * keyTyped * * @param e KeyEvent */ public void keyTyped(KeyEvent e) { System.out.println("Key typed: " + e.getKeyChar()); } /** * mouseClicked * * @param e MouseEvent */ public void mouseClicked(MouseEvent e) { System.out.println("MouseClicked"); } /** * mouseEntered * * @param e MouseEvent */ public void mouseEntered(MouseEvent e) { } /** * mouseExited * * @param e MouseEvent */ public void mouseExited(MouseEvent e) { } /** * mousePressed * * @param e MouseEvent */ public void mousePressed(MouseEvent e) { } /** * mouseReleased * * @param e MouseEvent */ public void mouseReleased(MouseEvent e) { } }