您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)
next.gif
 (2959 bytes)

 
 
Extend Index
Extend Page # 8

Listing of DoubleArrayApplet.java ?version 3

// <APPLET code="DoubleArrayApplet.class" width=275 height=200></APPLET>
// DoubleArrayApplet - version 3
import java.applet.Applet;
import java.awt.*;
public class DoubleArrayApplet extends Applet
  {
  // instance variables
  double sales[] = new double[6];
  double maximum = 0;
  // methods
  public void init()
    {
    sales[0] = 10.5;
    sales[1] = 9.01;
    sales[2] = 16.17;
    sales[3] = 11.22;
    sales[4] = 88.33;
    sales[5] = 5.55;
    // calculate maximum value in array
    // loop to test each element of array
    int index;
    for( index = 0; index < sales.length; index++)
    if( sales[index] > maximum )
    maximum = sales[index];
    }
    public void paint( Graphics g )
    {
    // local variables for position of text
    int x = 10;
    int y = 10;
    // display class name in window
    g.drawString("Double Array Applet - version 3", x, y );
    y = y + 20;
    // loop to display each element of array
    int index;
    for( index = 0; index < sales.length; index++)
      {
      g.drawString("sales[" + index + "] = " + sales[index], x, y );
      y = y + 20;
      }
    // display maximum value
    g.drawString("maximum value in array = " + maximum, x, y );
    }
  } // class 
Back to top
basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright © 1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg