********************* import java.applet.Applet; import java.awt.*; ********************* public class HelloWWW extends Applet { private int fontSize = 40; public void init() { setBackground(Color.black); setForeground(Color.white); setFont(new Font(“SansSerif”, Font.BOLD, fontSize)); } public void paint(Graphics g) { g.drawString(“Hello, World Wide Web.”, 5, fontSize+5); } } <<<<<<<<<<<<<<<<<<<<<
Tag: Java
Aug 29
Basic Hello World application
******************* HelloWorld.java Basic Hello World application. ******************* */ public class HelloWorld { public static void main(String[] args) { System.out.println(“Hello, world.”); } } /*
Aug 29
StringTest.java Demonstrates various methods of the String class.
/** Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * © 2001 Marty Hall and Larry Brown; * may be freely used or adapted. */ public class StringTest { public static void main (String[] args) { String str = “”; if (args.length > 0) …
Aug 29
NegativeLengthException.java Illustrates defining and throwing your own exceptions.
import java.io.*; /** Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * © 2001 Marty Hall and Larry Brown; * may be freely used or adapted. */ public class NegativeLengthException extends Exception { /** Test NegativeLengthException */ public static void main(String[] args) { try { …
Aug 29
TreeTest.java Builds a binary tree and prints the contents of the nodes. Uses the following classes:
Treetest.java /** A NodeOperator that prints each node. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * © 2001 Marty Hall and Larry Brown; * may be freely used or adapted. */ class PrintOperator implements NodeOperator { public void operateOn(Node node) { System.out.println(node.getNodeValue()); …
Aug 29
Illustrates the use of arrays
/** Report on a round of golf at St. Andy?s. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * © 2001 Marty Hall and Larry Brown; * may be freely used or adapted. */ public class Golf { public static void main(String[] args) { …
Aug 29
Factorial.java Computes an exact factorial, n!, using a BigInteger
import java.math.BigInteger; /** Computes an exact factorial, using a BigInteger. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * © 2001 Marty Hall and Larry Brown; * may be freely used or adapted. */ public class Factorial { public static void main(String[] args) { …
Aug 29
Exec.java Provides static methods for running external processes from applications.
import java.io.*; /** A class that eases the pain of running external processes * from applications. Lets you run a program three ways: * * exec: Execute the command, returning * immediately even if the command is still running. * This would be appropriate for printing a file. …
Aug 29
Controlling Image Loading
~~~~~~~~~~~~~~~~~~~ ImageBox.java A class that incorrectly tries to load an image and draw an outline around it. The problem is that the size of the image is requested before the image is completely loaded, thus, returning a width and height of -1. ~~~~~~~~~~~~~~~~~~~ import java.applet.Applet; import java.awt.*; /** A class that incorrectly tries to load …
Aug 29
HelloWWW2.java Illustrates the ability of an applet to read parameters contained in the HTML document
HelloWWW2.java Illustrates the ability of an applet to read parameters contained in the HTML document (PARAM element containing a NAME-VALUE pair). &&&&&&&&&&&&&&&&&&&&&&&&&&&&&& import java.applet.Applet; import java.awt.*; ************************* public class HelloWWW2 extends Applet { public void init() { setFont(new Font(“SansSerif”, Font.BOLD, 30)); Color background = Color.gray; Color foreground = Color.darkGray; String …