Notes Java J3

Math 10 -- D. C. Smolarski, S.J.
Santa Clara University, Department of Mathematics and Computer Science

[Return to Math 10 Homepage | Return to Notes Listing Page]

Contents


Java Example 1

This example show how a separate function can be used in a self-standing Java program:
class Testprog3{
  public static void output()
  {
    System.out.println(" Printout");
  }

  public static void main (String[] args)
  {
    int i;
    output();
    for(i=0;i<=10;i++)
      {
	System.out.println (i);
      }
  }
}
This can be accessed and downloaded at this link.

Java Example 2

This example show the implementation of a mouse activated applet in which the mouse clicks are independently recorded.
   import java.applet.Applet;
   import java.awt.*;
   import java.io.*;
   import java.util.*;
   import java.awt.event.*;

   public class Example2 
      extends Applet
      implements MouseListener
   {
      TextField t;
      public void init()
      { 
         System.out.println("hello");
	 t = new TextField("Hi There");
         add(t);
         addMouseListener(this);
      }

    public void mousePressed (MouseEvent e)
    { 
       int x = e.getX(); 
       int y = e.getY();
       Graphics g = getGraphics();
       g.fillOval(x,y,10,10);
     }
    public void mouseReleased(MouseEvent e)
    {}
    public void mouseEntered(MouseEvent e)
    {}
    public void mouseExited(MouseEvent e)
    {}
    public void mouseClicked(MouseEvent e)
    {}
   }
This can be accessed and downloaded at this link. It can be viewed at this link with a browser that supports Java 1.1.

Java Example 3

This example show the implementation of a mouse activated applet in which pressing the mouse button is continuously recorded.
   import java.applet.Applet;
   import java.awt.*;
   import java.io.*;
   import java.util.*;
   import java.awt.event.*;

   public class Example5 
      extends Applet
      implements MouseMotionListener
   {
      TextField t;
      public void init()
      { 
        System.out.println("hello");
        t = new TextField("Hi There");
        add(t);
        addMouseMotionListener(this);
      }

      public void mouseDragged(MouseEvent e)
      {
        int x = e.getX();
        int y = e.getY();
        Graphics g = getGraphics();
        g.fillOval(x,y,10,10);
      }
      public void mouseMoved(MouseEvent e)
      {}
   }
This can be accessed and downloaded at this link. It can be viewed at this link with a browser that supports Java 1.1.


This page is maintained by Dennis C. Smolarski, S.J. dsmolarski@math.scu.edu
© Copyright 1998, 2006, Dennis C. Smolarski, SJ, All rights reserved. Last changed: 24 January 2006.