Java code - applets

banner.class

A version of the infamous "Hello World" program, simply displays a text message in a Java applet. Make sure you have enabled Java before clicking on these links.

[Get Java source] banner.java [Load Java] load Java applet

A more complex animated Java applet:

Animation code Java Animation source Load applet page Run Java animation

Using a Stack to Recognize Strings in a Language

import java.util.*;
import java.awt.*;

void MYFunc(String test) {

StringTokenizer t = new StringTokenizer(test,"\n");
numlines = t.countTokens();
lines = new String[numlines];
linewidths = new int[numlines];
for (int i =0;i<numlines;i++) lines[i] = t.nextToken();
}

This turns this sentence into

lines[0] = "This\n"
lines[1] = "turns\n"
lines[2] = "this\n"
lines[3] = "sentence\n"
lines[4] = "into\n"

Use standard if else loops with == or != tests for the rest.



This is part of www.codehelp.co.uk Copyright © 1998-2004 Neil Williams
See the file about.html for copying conditions.