All examples, except for FileTransfer use WindowUtilities.java and ExitListener.java. WindowUtilities.java: import javax.swing.*; import java.awt.*; // For Color and Container classes. /** A few utilities that simplify using windows in Swing. * */ public class WindowUtilities { /** Tell system to use native look and feel, as in previous * releases. Metal (Java) …
Tag: Java
Aug 26
Position circles down the diagonal so that their borders
import java.awt.*; import java.applet.Applet; /** Position circles down the diagonal so that their borders * just touch. Illustrates that AWT components are * rectangular and opaque. */ public class CircleTest2 extends Applet { public void init() { setBackground(Color.lightGray); setLayout(null); // Turn off layout manager. Circle circle; int radius = …
Aug 26
Insert three circles into an Applet using FlowLayout
import java.awt.*; import java.applet.Applet; /** Insert three circles into an Applet using FlowLayout. * */ public class CircleTest extends Applet { public void init() { setBackground(Color.lightGray); add(new Circle(Color.white, 30)); add(new Circle(Color.gray, 40)); add(new Circle(Color.black, 50)); } }
Aug 26
Message.java Applet that reads customization parameters from an HTML file
******************* Message.java Applet that reads customization parameters from an HTML file ******************* import java.applet.Applet; import java.awt.*; **************** public class Message extends Applet { private int fontSize; private String message; public void init() { setBackground(Color.black); setForeground(Color.white); // Base font size on window height. fontSize = …
Aug 26
Accesses methods in a Ship2 object
********************************************* Test2.java Accesses methods in a Ship2 object ********************************************* // Give the ship public move and printLocation methods. class Ship2 { public double x=0.0, y=0.0, speed=1.0, direction=0.0; public String name = “UnnamedShip”; private double degreesToRadians(double degrees) { return(degrees * Math.PI / 180.0); } public void move() { double …
Aug 26
Placement of buttons in a BoxLayout using rigid areas, struts, and glue
############### InvisibleComponentTest.java Placement of buttons in a BoxLayout using rigid areas, struts, and glue ############### import java.awt.*; import javax.swing.*; import javax.swing.border.*; /** Example of using rigid areas, struts, and glue to * produce the effect of invisible components. * ****************** public class InvisibleComponentTest extends JPanel { Component spacer; public InvisibleComponentTest() { setLayout(new …
Aug 26
Adds typing to the freehand drawing.
import java.applet.Applet; import java.awt.*; import java.awt.event.*; /** A better whiteboard that lets you enter * text in addition to freehand drawing. * ****************** public class Whiteboard extends SimpleWhiteboard { protected FontMetrics fm; public void init() { super.init(); Font font = new Font(“Serif”, Font.BOLD, 20); setFont(font); fm = getFontMetrics(font); …
Aug 26
java Nested container where the top-level panels are positioned by hand
###################### ButtonCol.java Nested container where the top-level panels are positioned by hand ###################### import java.applet.Applet; import java.awt.*; /** An example of a layout performed manually. The top-level * panels are positioned by hand, after you determine the size * of the applet. Since applets can’t be resized in most * browsers, setting the size once …
Aug 26
Layout of complicated GUI by taking advantage of nested containers
################# NestedLayout.java Layout of complicated GUI by taking advantage of nested containers. Uses WindowUtilities.java and ExitListener.java. ################## import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; /** An example demonstrating the use of nested containers * to lay out the components. See GridBagTest.java for * implementation by a single layout manager, GridBagLayout. …
Aug 26
A demo providing multiple buttons to select a playing card-A Panel, using CardLayout control which of four possible subpanels, holding a different card, to display
####################### # CardDemo.java A demo providing multiple buttons to select a playing card. A Panel, using CardLayout control which of four possible subpanels, holding a different card, to display.Uses the following class and images: * CardPanel.java A Panel that displays a playing card. * ImageLabel.java A Canvas for displaying images. * Ace.gif, …