import java.awt.*; /** An example of using local fonts to perform drawing in * Java 2D. * ********************** public class FontExample extends GradientPaintExample { public FontExample() { GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); env.getAvailableFontFamilyNames(); setFont(new Font(“Goudy Handtooled BT”, Font.PLAIN, 100)); } protected void drawBigString(Graphics2D g2d) { g2d.setPaint(Color.black); g2d.drawString(“Java …
Category: Root
Aug 28
Draws a circle with a gradient fill
GradientPaintExample.java Draws a circle with a gradient fill. Inherits from ShapeExample.java. ************************************** import java.awt.*; /** An example of applying a gradient fill to a circle. The * color definition starts with red at (0,0), gradually * changing to yellow at (175,175). * ********************************** public class GradientPaintExample extends ShapeExample { private GradientPaint gradient = …
Aug 28
An applet that permits freehand drawing
import java.applet.Applet; import java.awt.*; import java.awt.event.*; /** An applet that lets you perform freehand drawing. * **************** public class SimpleWhiteboard extends Applet { protected int lastX=0, lastY=0; public void init() { setBackground(Color.white); setForeground(Color.blue); addMouseListener(new PositionRecorder()); addMouseMotionListener(new LineDrawer()); } protected void record(int x, int y) { …
Aug 28
A TextField that uses key events to correct the spelling of the names of computer languages entered into it
import java.awt.*; import java.awt.event.*; /** A spelling-correcting TextField for entering * a language name. * ******************* public class LanguageField extends TextField { private String[] substrings = { “”, “J”, “Ja”, “Jav”, “Java” }; public LanguageField() { addKeyListener(new SpellingCorrector()); addActionListener(new WordCompleter()); addFocusListener(new SubliminalAdvertiser()); } // Put caret …
Aug 28
DebugTag.java Custom tag that optionally makes use of a tag body
DebugTag.java Custom tag that optionally makes use of a tag body package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; import javax.servlet.*; /** A tag that includes the body content only if * the “debug” request parameter is set. * <P> * Taken from Core Web Programming Java 2 Edition * from Prentice Hall and Sun …
Aug 28
HeadingTag.java Custom tag that makes use of a tag body
HeadingTag.java Custom tag that makes use of a tag body package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; /** Generates an HTML heading with the specified background * color, foreground color, alignment, font, and font size. * You can also turn on a border around it, which normally * just barely encloses the heading, but …
Aug 28
PrimeTag.java Custom tag that outputs a random prime number of a user-specifiable approximate length
PrimeTag.java Custom tag that outputs a random prime number of a user-specifiable approximate length package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; /** Generates an N-digit random prime (default N = 50). * Extends SimplePrimeTag, adding a length attribute * to set the size of the prime. The doStartTag * method of the parent class …
Aug 28
SimplePrimeTag.java Custom tag that outputs a random prime number of a fixed approximate length
SimplePrimeTag.java Custom tag that outputs a random prime number of a fixed approximate length package cwp.tags; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import java.io.*; import java.math.*; import cwp.*; /** Generates a prime of approximately 50 digits. * (50 is actually the length of the random number * generated — the first prime above that number will * …
Aug 28
cwp-taglib.tld Tag Library Descriptor file used by the custom tags in this chapter.
cwp-taglib.tld Tag Library Descriptor file used by the custom tags in this chapter. <?xml version=”1.0″ encoding=”ISO-8859-1″ ?> <!DOCTYPE taglib PUBLIC “-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN” “http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd”> <!– a tag library descriptor –> <taglib> <!– after this the default space is “http://java.sun.com/j2ee/dtds/jsptaglibrary_1_2.dtd” –> <tlibversion>1.0</tlibversion> <jspversion>1.1</jspversion> <shortname>cwp</shortname> <!– …
Aug 28
SharedCounts1.jsp, SharedCounts2.jsp, and SharedCounts3.jsp Three pages that all use the AccessCountBean. Results you get depend on which page is hit first and how many total hits the combined pages receive.
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”> <!– Example of sharing beans. Taken from Core Web Programming Java 2 Edition from Prentice Hall and Sun Microsystems Press, . May be freely used or adapted. –> <HTML> <HEAD> <TITLE>Shared Access Counts: Page 1</TITLE> <LINK REL=STYLESHEET HREF=”JSP-Styles.css” TYPE=”text/css”> </HEAD> <BODY> <TABLE BORDER=5 ALIGN=”CENTER”> <TR><TH …
