Professor Kit Romano's Web Site

 



Site Index

About Me

Welcome
Definition of Program
Variable Types
Understanding Memory
Declaring Variables
Simple Commands
Concatenation and Strings
Sleep-Threads-Try Catch
Campus Scenes
Pictures
Java simplified
Application Shell Styles
Reading Data From File
Overview of Applets
Excellent Graphics Applet
Online Reference
Nested if statements
Arrays
Sorting Arrays
Using Strings
Functions
Top 20 Replies 
First program 211
Important Class Example
JAVA in SDK Environment
Understanding OOP
OOP simple example
Recursion example
Example of Inheritance
     and use of JTextArea



*** Web Related **********
Build Student Web Page ?
What is FTP
Download WS ftp95
Download Java Plug In
Applets from jbuilder to sdk
Practice Problems

 

Programming Examples

 

 

                                                


// applet to draw an orbit and planet on orbit
import java.awt.*;
import javax.swing.*;
import java.math.*;

public class Applet7 extends JApplet {
int point1,point2;
double angle=1.7;
int x1=250; int y1=250; int xos=20; int yos=20; int R=220; int step=22;
boolean clockwise = true; 
public void paint(Graphics g) 
{
g.setColor(Color.white);
g.fillRect(0,0,500,500);
g.setColor(Color.red); 
g.drawOval(250-R,250-R,R*2,R*2);
point1=(int)(R * Math.cos(angle) + x1);
point2=(int)(y1-R * Math.sin(angle)); // changed from 1st version


g.fillOval(point1-(xos/2),point2-(yos/2),xos,yos);
//g.fillOval(point1,point2,xos,yos);
if(clockwise) angle -= Math.PI/step;
else angle += Math.PI/step; // changed from 1st version 
try{Thread.sleep(300);} catch(Exception e){} 
repaint();

}
}