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

 

 

                                                

import java.awt.*;
import javax.swing.*;
import java.math.*;

public class tree3 extends JApplet {

public int x=250; public int y=500;
public int out=80; public int up=120;
public int mlength=20;
public int rndl=5;
public int x1=250,y1=400,x2,y2;
public int odd_even=1;
public double a=0;
public int aa=20;
//135 //45
public int depth=10;

public void paint(Graphics g) 
{
rm_tree( x, y, up, out, a, depth-1, g);
}//end m_paint

public void rm_tree(int x, int y, int up, int out, double a, int depth, Graphics g) 
{
double a1, a2;
int out1, out2, up1, up2;
g.setColor(Color.black);

if(depth>=0) 
{
out1=out-(int)(out*0.2); up1=up-(int)(up*0.2);
depth--;
a1=a + Math.toRadians(90+aa);
x1=(int)(out1*Math.cos(a1))+x;
y1=y-(int)(up1*Math.sin(a1));
for(int k=0;k<(20/(10-depth))+1;k++) 
{
g.drawLine( x+k, y, x1+k, y1);
}
if(depth==-1) 
{
g.setColor(Color.green);
g.fillOval(x1-5,y1-5,10,10);
}
a1=a+ Math.toRadians(aa);
rm_tree( x1, y1, up1, out1, a1, depth, g);
out2=out-(int)(out*0.2); up2=up-(int)(up*0.2);
a2=a + Math.toRadians(90-aa);
x2=(int)(out2*Math.cos(a2))+x;
y2=y-(int)(up2*Math.sin(a2));
for(int k=0;k<(10/(10-depth))+1;k++) 
{
g.drawLine( x+k, y, x2+k, y2);
}
if(depth<3) {
g.setColor(Color.green);
g.fillOval(x2-5,y2-5,10,10);
}
a2=a + Math.toRadians(-aa);
rm_tree( x2, y2, up2, out2, a2, depth, g);
}//end if depth

}//end m_rm_t 
}//end m_Sierpinski