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

Introduction

Content

Apply

Reflect

Extend

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

 
 
Extend Index
Extend Page # 4

Listing of CapacityApplet.java ?version 2

/ / <APPLET code="CapacityApplet.class" width=275 height=200></APPLET>
// CapacityApplet - version 2
import java.applet.Applet;
import java.awt.*;
public class CapacityApplet extends Applet
  {
  // instance variables
  int capacity[] = new int[4];
  // methods
  public void init()
    {
    capacity[0] = 55; capacity[1] = 34;
    capacity[2] = 80;
    capacity[3] = 101;
    }
  public void paint( Graphics g )
    {
    // local variables for position of text
    int x = 10;
    int y = 10;
    // display class name in window
    g.drawString("Capacity Applet - version 2", x, y );
    y = y + 25;
    // loop to display each element of 'capacity'
    int index;
    for( index = 0; index < capacity.length; index++)
      {
   g.drawString("capacity[" + index + "] = " + capacity[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