Category: Applets and Basic Graphics

Jan 02

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

Jan 02

Basic template for a Java applet

AppletTemplate.java >>>>>>>>>>>>>>>>>>>> import java.applet.Applet; import java.awt.*; ******************** public class AppletTemplate extends Applet { // Variable declarations. public void init() { // Variable initializations, image loading, etc. } public void paint(Graphics g) { // Drawing operations. } } >>>>>>>>>>>>>>>>>>>>> Note: Brought from our old site: http://www.salearningschool.com/example_codes/ on Jan 2nd, 2017

Jan 02

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 backgroundType = getParameter("BACKGROUND"); if (backgroundType …

Continue reading

Jan 02

Loading Images

JavaMan1.java Applet that loads an image from a relative URL. ************************************************************* import java.applet.Applet; import java.awt.*; /** An applet that loads an image from a relative URL. * >>>>>>>>>>>>>>>>>>> public class JavaMan1 extends Applet { private Image javaMan; public void init() { javaMan = getImage(getCodeBase(),"images/Java-Man.gif"); } public void paint(Graphics g) { g.drawImage(javaMan, 0, 0, this); } …

Continue reading

Jan 02

PrimeTag.java Custom tag that outputs a random prime number of a user-specifiable approximate length

NULL

Jan 02

PrimeExample.jsp Page that uses the PrimeTag custom tag

NULL

Jan 02

HeadingTag.java Custom tag that makes use of a tag body

NULL

Jan 02

HeadingExample.jsp Page that uses the HeadingTag custom tag

NULL

Jan 02

DebugTag.java Custom tag that optionally makes use of a tag body

NULL

Jan 02

# DebugExample.jsp Page that uses the DebugTag custom tag

NULL

Jan 02

FilterTag.java Custom tag that modifies the tag body

NULL

Jan 02

FilterExample.jsp Page that uses the FilterTag custom tag

NULL

Jan 02

RepeatTag.java Custom tag that repeats the tag body a specified number of times

NULL

Jan 02

IfTag.java, IfConditionTag.java, IfThenTag.java, and IfElseTag.java, Custom tags that make use of tag nesting

NULL

Jan 02

IfExample.jsp Page that uses the custom nested tags

NULL

Jan 02

ForwardSnippet.java Partial servlet illustrating how to use a RequestDispatcher to forward requests

NULL

Jan 02

An example Travel Site

NULL

Jan 02

SimplePrimeTag.java Custom tag that outputs a random prime number of a fixed approximate length

NULL

Jan 02

SimplePrimeExample.jsp Page that uses the SimplePrimeTag custom tag

NULL

Jan 02

An applet that reads arrays of strings packaged inside a QueryCollection and places them in a scrolling TextArea.

import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.net.*; /** Applet reads arrays of strings packaged inside * a QueryCollection and places them in a scrolling * TextArea. The QueryCollection obtains the strings * by means of a serialized object input stream * connected to the QueryGenerator servlet. * * Taken from Core Web Programming Java …

Continue reading

Jan 02

The class that actually gets the strings over the network by means of an ObjectInputStream via HTTP tunneling.

import java.net.*; import java.io.*; /** When this class is built, it returns a value * immediately, but this value returns false for isDone * and null for getQueries. Meanwhile, it starts a Thread * to request an array of query strings from the server, * reading them in one fell swoop by means of an …

Continue reading

Jan 02

StringBean.jsp Page that manipulates the StringBean bean with both jsp:useBean (i.e., XML-style) syntax

NULL

Jan 02

SaleEntry.java Bean used to demonstrate the various approaches to reading request parameters and stuffing them into Java objects.

NULL

Jan 02

SaleEntry1.jsp Page that uses the SaleEntry bean, using explicit Java code to read request parameters and assign them to bean properties.

NULL

Jan 02

SaleEntry2.jsp Page that uses the SaleEntry bean, using the param attribute to read request parameters and assign them to bean properties

NULL

Jan 02

SaleEntry3.jsp Page that uses the SaleEntry bean, using property="*" to read request parameters and assign them to bean properties

NULL

Jan 02

AccessCountBean.java Bean used to illustrate the difference between running jsp:setProperty for every request vs. only when the object is created

NULL

Jan 02

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.

NULL

Jan 02

ExampleTag.java Very simple custom tag. Remember to install it in the WEB-INF/classes/cwp/tags directory.

NULL

Jan 02

cwp-taglib.tld Tag Library Descriptor file used by the custom tags in this chapter.

NULL

Skip to toolbar