Demonstrates the use of a JColorChooser which presents a dialog with three different tabbed panes to allow the user to select a color preference. The dialog returns a Color object based on the user’s selection or null if the user entered Cancel. import java.awt.*; import java.awt.event.*; import javax.swing.*; /** Simple example illustrating the use of …
Tag: Java
Aug 25
WebClient – Client application that can talk interactively to Web servers. Requires the components listed below
import java.awt.*; // For BorderLayout, GridLayout, Font, Color. import java.awt.event.*; import java.util.*; import javax.swing.*; /** A graphical client that lets you interactively connect to * Web servers and send custom request lines and * request headers. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * . * © …
Aug 25
EchoServer.java A simple HTTP server that creates a Web page showing all data sent from the client (browser), including all HTTP request headers sent form the client. Uses the following classes
EchoServer.java A simple HTTP server that creates a Web page showing all data sent from the client (browser), including all HTTP request headers sent form the client. Uses the following classes: import java.net.*; import java.io.*; import java.util.StringTokenizer; /** A simple HTTP server that generates a Web page showing all * of the data that …
Aug 25
StoppableThread.java A template to place a thread in a RUN, WAIT, or STOP state.
/** 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 …
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
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
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 …