java Swing - orbit


/*
Write a java program to plot the path of small circle moving around the circumference of a larger circle.
*/
         
// Java Graphics
// Orbit


import javax.swing.*;

import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics;
import java.awt.geom.*;

import java.lang.Math.*;

public class Orbit extends Frame
{
     double degree=0;
     int x1, y1;
    
     public void paint(Graphics g)
     {  
          g.fillOval(200,200,100,100);
     g.drawOval(50,50,400,400);
    
          degree=(degree+10)%360;
          x1 = (int)(200*java.lang.Math.cos((degree*2.0*3.142)/360.0))+250;
          y1 = (int)(200*java.lang.Math.sin((degree*2.0*3.142)/360.0))+250;

          g.drawOval(x1-15,y1-15,30,30);
             
          try
          {
              Thread.sleep(100);
          }
          catch(Exception e)
          {}
             
          repaint();
     }

     public static void main(String as[])
     {
          Orbit obj = new Orbit();
         
          obj.setSize(new Dimension(500,500));
          obj.setTitle("Orbit");
                       
          obj.setVisible(true);       
     }
}

Output:



No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu