Listing of ReverseArrayApplet.java ?version 2 // <APPLET code="ReverseArrayApplet.class" width=275 height=200></APPLET> // ReverseArrayApplet - version 2 import java.applet.Applet; import java.awt.*; public class Rextends Applet { // instance variables char forward[] = {'h', 'e', 'l', 'l', 'o'}; char backward[]; // methods public void init() { // define array backward backward = new char[ forward.length ]; // loop to put chars from 'forward' into 'backward' // (in reverse order) int index; for( index = 0; index < forward.length; index++) backward[ index ] = forward[ forward.length - index - 1 ]; } public void paint( Graphics g ) { // local variables for position of text int x = 10; int y = 10; // display class name in window g.drawString("Reverse Array Applet - version 2", x, y ); y = y + 20; // Display "char array 'forward' contains:" in window g.drawString("char array 'forward' contains:", x, y ); y = y + 20; // use Graphics method 'drawChars' to display char array g.drawChars( forward, 0, forward.length, x + 10, y ); y = y + 30; // Display "char array 'backward' contains:" in window g.drawString("char array 'backward' contains:", x, y ); y = y + 20; // use Graphics method 'drawChars' to display char array g.drawChars( backward, 0, backward.length, x + 10, y ); } } // class Back to top
 RITSEC - Global Campus Copyright © 1999 RITSEC- Middlesex University. All rights reserved. webmaster@globalcampus.com.eg
|