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 6-2

// same program as 6-1 except I showed you what it would look
// like in applet form  study the similarities with 6-1
// This applet also animation and uses a sleep method to
// pause the output so it can be seen.  Students can judge from this
// and 6-1 to see how to take applications and convert to applets
// The "setXORMode" method is critical in animation.  When this 
// mode is set drawing something twice cancells the appearance of 
// the first drawing , making it disappear
// make you applet window larger 600 by 500 to see the entire 
// animation

import java.awt.*;
import java.net.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
public class Applet1 extends JApplet
{
   Thread th=new Thread();

    public void paint(Graphics g)
     {
        int b;
        g.setColor(Color.blue);
        g.setXORMode(Color.white);
        for(int a=1;a<800;a++) // start of loop
          {
               if (a<479) b=a;
                  else b=479;
               g.fillOval(a,b,40,4);
                try
                 {
                     th.sleep(25);
                  }
                  catch(Exception e)
                   {
                   }
                if (a<479) g.fillOval(a,b,40,4);
                    else
                     {
                       b=479;
                       g.fillOval(a,b,40,4);
                      }
            } // end of loop
      }
 }