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

 

 

                                                

 

Program 1-7A

// draw 500 balloons fixed size but random colors and positions on the screen
applet with only a PAINT method

package untitled5;
import javax.swing.JOptionPane;
import javax.swing.JApplet; // import class JApplet
import java.awt.Graphics; // import class Graphics
import java.awt.*;
public class Applet1 extends JApplet
{  
     public void paint( Graphics g )
      {
       int n1,n2,n3,n4,n5;
       int i=0;
      do
        {
          // get random numbers for 3 RGB colors
          // and random numbers for the Oval position
          n1=1+(int) (Math.random()*254);
          n2=1+(int) (Math.random()*254);
          n3=1+(int) (Math.random()*254);
          n4=1+(int) (Math.random()*200);
          n5=1+(int) (Math.random()*200);
          Color one = new Color(n1,n2,n3);
          g.setColor(one);
          g.fillOval(n4,n5,35,25);
          i = i + 1;
         }
           while ( i < 500);
   }
}