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 8-1

//  Applet that shows some very nice concepts involving 
// components and java methods that can be used on them
// It shows some advanced features of JAVA that allow
// you to respond to user input (mouse clicks)

import java.awt.*;
import java.applet.*;
import java.net.*;
import java.awt.event.*;

public class Applet1 extends Applet implements ActionListener

   {
      Label heading = new Label("Use of Button components along with methods");
      int x3=5;
      int position=1;
      Font bigfont = new Font("ariel",Font.PLAIN,20);
      Button slow = new Button("Press A");
      Button fast = new Button("Press B");



     public void init()
     { 
       setLayout( null ); // position components abs.
       heading.setFont(bigfont);
       heading.setBounds(1,1,430,38);
       slow.setBounds(80,150,80,40);
       slow.addActionListener(this);
       fast.setBounds(240,150,80,40);
       fast.addActionListener(this);
       add(heading);
       add(slow);
       add(fast);
     }

     public void actionPerformed(ActionEvent event)
       {
         if(event.getSource() == fast)
       {
          fast.setBounds(position,125,60,30);
          add(fast);
       }
         else
           {
             slow.setBounds(position,75,100,20);
             add(slow);
           }
             position+=10;
      }
}