/** A template to control the state of a thread through setting * an internal flag. public class StoppableThread extends Thread { public static final int STOP = 0; public static final int RUN = 1; public static final int WAIT = 2; private int state = RUN; /** Public …
Category: Java/J2EE/J2ME
Aug 25
mall example showing the basic use of a JToolBar
mall example showing the basic use of a JToolBar import java.awt.*; import javax.swing.*; import java.awt.event.*; /** Small example showing basic use of JToolBar. * * */ public class JToolBarExample extends JFrame implements ItemListener { private BrowserToolBar toolbar; private JCheckBox labelBox; public static void main(String[] args) { new JToolBarExample(); } …
Aug 25
UrlRetriever2.java Illustrates how the URL class can simplify communication to an HTTP server.
UrlRetriever2.java Illustrates how the URL class can simplify communication to an HTTP server. import java.net.*; import java.io.*; /** Read a remote file using the standard URL class * instead of connecting explicitly to the HTTP server. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * © …
Aug 25
RMI Example – Message, illustrates retrieving a message from an object located on a remote server. Requires the following classes
Rem.java Establishes which methods the client can access in the remote object. import java.rmi.*; /** The RMI client will use this interface directly. The RMI * server will make a real remote object that implements this, * then register an instance of it with some URL. * * Taken from Core Web Programming from * …
Aug 25
Creates three common types of sliders
Creates three common types of sliders: one without tick marks, one with tick marks, and one with both tick marks and labels. import java.awt.*; import javax.swing.*; /** Simple example illustrating the use of JSliders, especially * the ability to specify tick marks and labels. * * */ public class JSliders extends JFrame { …
Aug 25
Basic Swing Details
WindowUtilities.java Utility class that simplifies creating a window and setting the look and feel. ExitListener.java A WindowListener with support to close the window. JAppletExample.java A simple applet (JApplet) created in Swing. Illustrates setting the look and feel, adding components to the content pane, and changing the layout to FlowLayout (default is BorderLayout). See JAppletExample.html (requires …
Aug 24
UrlRetriever.java Accepts an URL from the command line, parses the host, port, and URI components from the URL and then retrieves the document. Requires the following classes
UrlRetriever.java Accepts an URL from the command line, parses the host, port, and URI components from the URL and then retrieves the document. Requires the following classes: import java.util.*; /** This parses the input to get a host, port, and file, then * passes these three values to the UriRetriever class to * grab the …
Aug 24
AddressVerifier.java Connects to an SMTP server and issues a expn request to display details about a mailbox on the server. Uses the following classes
import java.net.*; import java.io.*; /** Given an e-mail address of the form user@host, * connect to port 25 of the host and issue an * ‘expn’ request for the user. Print the results. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * © 2001 Marty Hall …
Aug 23
Buggy Counter Applet.java Demonstrates that data shared by multiple threads is candidate for a potential race condition
import java.applet.Applet; import java.awt.*; /** Emulates the Counter and Counter2 classes, but this time * from an applet that invokes multiple versions of its own run * method. This version is likely to work correctly * except when an important customer is visiting. public class BuggyCounterApplet extends Applet implements Runnable{ private int totalNum …
Aug 23
SplitTest.java Illustrates parsing a string with a String.split
SplitTest.java Illustrates parsing a string with a String.split /** Prints the tokens resulting from treating the first * command-line argument as the string to be tokenized * and the second as the delimiter set. Uses * String.split instead of StringTokenizer. */ public class SplitTest { public static void main(String[] args) { if (args.length == 2) …