Category: Java/J2EE/J2ME

Six buttons arranged in a 2 row x 3 column grid by GridLayout

/././././././ GridTest.java Six buttons arranged in a 2 row x 3 column grid by GridLayout.GridLayout divides the window into equal-sized rectangles based upon the number of rows and columns specified. ****************** import java.applet.Applet; import java.awt.*; /** An example of GridLayout.  *  /./././././. public class GridTest extends Applet {   public void init() {     setLayout(new …

Continue reading

ListEvent2.java

# ListEvents.java Uses the following classes:     * CloseableFrame.java     * SelectionReporter.java     * ActionReporter.java /././././././././././././ import java.awt.event.*; /././././././ public class ListEvents2 extends ListEvents {   public static void main(String[] args) {     new ListEvents2();   }   /** Extends ListEvents with the twist that    *  typing any of the letters of “JAVA” or …

Continue reading

A Frame that can actually quit

import java.awt.*; import java.awt.event.*; /** A Frame that you can actually quit. Used as the starting  *  point for most Java 1.1 graphical applications.  * public class CloseableFrame extends Frame {   public CloseableFrame(String title) {     super(title);     enableEvents(AWTEvent.WINDOW_EVENT_MASK);   }   /** Since we are doing something permanent, we need    *  to …

Continue reading

creating a simple Swing application using a JFrame

JFrameExample.java Demonstrates creating a simple Swing application using a JFrame. As with a JApplet, components must be added to the content pane, instead of the window directly.import java.awt.*; import javax.swing.*; /** Tiny example showing the main difference in using  *  JFrame instead of Frame: using the content pane  *  and getting the Java (Metal) look …

Continue reading

Explicit placement of five buttons with the layout manager turned off

NullTest.java Explicit placement of five buttons with the layout manager turned off (set to null) ########################## import java.applet.Applet; import java.awt.*; /** Layout managers are intended to help you, but there  *  is no law saying you have to use them.  *  Set the layout to null to turn them off.  * ******************* public class NullTest …

Continue reading

JTree Examples

SimpleTree.java Basic tree built out of DefaultMutableTreeNodes. A DefualtMutableTreeNode is a starting point for a root node, in which children nodes can be added. import java.awt.*; import javax.swing.*; import javax.swing.tree.*; /** Example tree built out of DefaultMutableTreeNodes.  *  */ public class SimpleTree extends JFrame {   public static void main(String[] args) {     new SimpleTree(); …

Continue reading

Printing in Java 2

   *           o PrintExample.java Demonstrates printing a Graphics2D object. import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.awt.print.*; /** An example of a printable window in Java 1.2. The key point  *  here is that any component is printable in Java 1.2.  *  However, you have to be careful to turn off double buffering  *  …

Continue reading

BetterCircleTest.java

********************** BetterCircleTest.java ********************** import java.awt.*; import java.applet.Applet; /** Position circles down the diagonal so that their borders  *  just touch. Illustrates that Java 1.1 lightweight  *  components can be partially transparent.  *   */ public class BetterCircleTest extends Applet {   public void init() {     setBackground(Color.lightGray);     setLayout(null);     BetterCircle circle;     int radius …

Continue reading

RMI Example – Numerical Integration, a more realistic RMI example that sends an evaluatable object (function) from a client to a server for numerical integration.

Integral.java  Performs actual numerical integration of the function (evaluatable object). /** A class to calculate summations and numeric integrals. The  *  integral is calculated according to the midpoint rule.  *  *  Taken from Core Web Programming from  *  Prentice Hall and Sun Microsystems Press,  *  .  *  © 2001 Marty Hall and Larry Brown;  *  …

Continue reading

A JPanel that displays six radio buttons with labels.

A JPanel that displays six radio buttons with labels. import java.awt.*; import javax.swing.*; /** A JPanel that displays six JRadioButtons.  *  *.  */ public class SixChoicePanel extends JPanel {   public SixChoicePanel(String title, String[] buttonLabels) {     super(new GridLayout(3, 2));     setBackground(Color.lightGray);     setBorder(BorderFactory.createTitledBorder(title));     ButtonGroup group = new ButtonGroup();     JRadioButton option;     int …

Continue reading