ShipSimulation.java Illustrates the basic approach of multithreaded graphics whereas a thread adjusts parameters affecting the appearance of the graphics and then calls repaint to schedule an update of the display. import java.applet.Applet; import java.awt.*; public class ShipSimulation extends Applet implements Runnable { … public void run() { Ship s; …
Category: Java/J2EE/J2ME
Aug 25
Driver class that creates three threaded objects (Counter2) that count from 0 to 4.
/** Try out a few instances of the Counter2 class. public class Counter2Test { public static void main(String[] args) { Counter2 c1 = new Counter2(5); Counter2 c2 = new Counter2(5); Counter2 c3 = new Counter2(5); } } /** A Runnable that counts up to a specified * limit with random …
Aug 25
Template illustrating the second approach for creating a class with thread behavior.
Template illustrating the second approach for creating a class with thread behavior. In this case, the class implements the Runnable interface while providing a run method for thread execution. public class ThreadedClass extends AnyClass implements Runnable { public void run() { // Thread behavior here. } public void startThread() { …
Aug 25
Creates and starts three threaded objects
Creates and starts three threaded objects which count from 0 to 4. Uses the following class: CounterTest.java Counter.java /** Try out a few instances of the Counter class. public class CounterTest { public static void main(String[] args) { Counter c1 = new Counter(5); Counter c2 = new Counter(5); Counter c3 = new Counter(5); c1.start(); c2.start(); …
Aug 25
DOM example that represents the basic structure of an XML document as a JTree
//XMLTree.java //Uses the following files Uses the following files: * XMLFrame.java:Swing application to select an XML document and display in a JTree. ExtensionFileFilter.java Allows you to specify which file extensions will be displayed in a JFileChooser. test.xml Default file loaded if none selected by user. perennials.xml and perennials.dtd Data on daylilies and corresponding DTD. …
Aug 25
Simple example illustrating the use of check boxes
JCheckBoxTest.java Simple example illustrating the use of check boxes. import javax.swing.*; import java.awt.event.*; */ public class JCheckBoxTest extends JPanel implements ItemListener, ActionListener{ JCheckBox checkBox1, checkBox2; public JCheckBoxTest() { checkBox1 = new JCheckBox(“Java Servlets”); checkBox2 = new JCheckBox(“JavaServer Pages”); checkBox1.setContentAreaFilled(false); checkBox2.setContentAreaFilled(false); checkBox1.addItemListener(this); …
Aug 25
Basic tool bar for holding multiple buttons.
BrowserToolBar.java A basic tool bar for holding multiple buttons. import java.awt.*; import javax.swing.*; /** Part of a small example showing basic use of JToolBar. * Creates a small dockable toolbar that is supposed to look * vaguely like one that might come with a Web browser. * Makes use of ToolBarButton, a small extension of …
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 of …
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 …