import java.net.*; import java.io.*; /** A multithreaded variation of EchoServer. * * 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 ThreadedEchoServer extends EchoServer implements Runnable { public static …
Category: Java/J2EE/J2ME
Aug 25
Implementing a Server : Network Server
NetworkServerTest.java Establishes a network Server that listens for client requests on the port specified (command-line argument). Uses the following classes: /** 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 …
Aug 25
UrlTest.java Demonstrates the ease in which the various components of an URL can be determined (host, port, protocol, etc.)
জা import java.net.*; /** Read a URL from the command line, then print * the various components. * * 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 UrlTest { …
Aug 25
Counter2Test.java Driver class that creates three threaded objects (Counter2) that count from 0 to 4.
/** Try out a few instances of the Counter2 class. Driver class that creates three threaded objects (Counter2) that count from 0 to 4. In this case, the driver does not start the threads, as each thread is automatically started in Counter2’s constructor. Uses the following class: Counter2Test.java Counter2.java ************************** public class Counter2Test { …
Aug 25
Template illustrating the first approach for creating a class with thread behavior.
** 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 ThreadClass extends Thread { public void run() { // Thread behavior here. } }
Aug 25
Creates three radio buttons and illustrates handling
JRadioButtonTest.java Creates three radio buttons and illustrates handling ItemEvents in response to selecting a radio button. import javax.swing.JRadioButton; import javax.swing.ButtonGroup; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** */ public class JRadioButtonTest extends JPanel implements ItemListener { public JRadioButtonTest() { String[] labels = {“Java Swing”,”Java Servlets”, “JavaServer Pages”}; JRadioButton[] …
Aug 25
Simple button that the user can select to load the entered URL.
JIconButton.java A simple button that the user can select to load the entered URL. import javax.swing.*; /** A regular JButton created with an ImageIcon and with borders * and content areas turned off. * */ public class JIconButton extends JButton { public JIconButton(String file) { super(new ImageIcon(file)); setContentAreaFilled(false); setBorderPainted(false); …
Aug 25
A simple button that contains an image and a label for use in a toolbar
ToolBarButton.java A simple button that contains an image and a label for use in a toolbar. import java.awt.*; import javax.swing.*; /** Part of a small example showing basic use of JToolBar. * The point here is that dropping a regular JButton in a * JToolBar (or adding an Action) in JDK 1.2 doesn’t give * …
Aug 25
Demonstrates the use of a JColorChooser which presents a dialog with three different tabbed panes to allow the user to select a color preference
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 …
Aug 25
Creates various buttons. In Swing
import java.awt.*; import javax.swing.*; /** Simple example illustrating the use of JButton, especially * the new constructors that permit you to add an image. * */ public class JButtons extends JFrame { public static void main(String[] args) { new JButtons(); } public JButtons() { super(“Using JButton”); WindowUtilities.setNativeLookAndFeel(); …