Tag: Java

HelloWWW.java Basic Hello World (Wide Web) Applet

********************* 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);   } } <<<<<<<<<<<<<<<<<<<<<

Basic Hello World application

******************* HelloWorld.java Basic Hello World application. *******************  */ public class HelloWorld {  public static void main(String[] args) {     System.out.println(“Hello, world.”);   } } /*

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) …

Continue reading

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 { …

Continue reading

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());   …

Continue reading

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) {     …

Continue reading

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) {     …

Continue reading

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.      …

Continue reading

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 …

Continue reading

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 …

Continue reading