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

Introduction

Content

Apply

Reflect

Extend

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

 
 
Extend Index
Extend Page # 7

Listing of DoubleArrayApplet.java ?version 2

// <APPLET code="DoubleArrayApplet.class" width=275 height=200></APPLET>
// DoubleArrayApplet - version 2
import java.applet.Applet;
import java.awt.*;
public class DoubleArrayApplet extends Applet
  {
  // instance variables
  double sales[] = new double[6];
  // 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;
    }
    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 2", 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;
      }

    }
  } // class 

Back to top
basicline.gif (169 bytes)

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