Tag: code

CheckboxGroups

CheckboxGroups.java /./././././././././ ///////////////////// import java.applet.Applet; import java.awt.*; ////////////////////   public class CheckboxGroups extends Applet {   public void init() {     setLayout(new GridLayout(4, 2));     setBackground(Color.lightGray);     setFont(new Font(“Serif”, Font.BOLD, 16));     add(new Label(“Flavor”, Label.CENTER));     add(new Label(“Toppings”, Label.CENTER));     CheckboxGroup flavorGroup = new CheckboxGroup();     add(new Checkbox(“Vanilla”, flavorGroup, true));     add(new Checkbox(“Colored Sprinkles”));     …

Continue reading

A textfield and three buttons arranged by a verticle BoxLayout

BoxLayoutTest.java A textfield and three buttons arranged by a verticle BoxLayout. Uses WindowUtilities.java and ExitListener.java. ################## import java.awt.*; import java.awt.event.*; import javax.swing.*; /** An example of BoxLayout.  *  *********** public class BoxLayoutTest extends JPanel                            implements ActionListener{   BoxLayout layout;   JButton topButton, middleButton, bottomButton;   public BoxLayoutTest() {     layout = new BoxLayout(this, BoxLayout.Y_AXIS); …

Continue reading

Implementation of a simple browser in Swing (The user can specify a URL to load into the browser (JEditorPane))

Browser.java Implementation of a simple browser in Swing. The user can specify a URL to load into the browser (JEditorPane). By attaching an Hyperlink Listener, the editor pane is responsive to hyperlinks selected by the user. Uses the following class and image: import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import java.net.*; import java.io.*; /** …

Continue reading

A simple applet (JApplet) created in Swing.

import java.awt.*; import javax.swing.*; /** Tiny example showing the main differences in using  *  JApplet instead of Applet: using the content pane,  *  getting Java (Metal) look and feel by default, and  *  having BorderLayout be the default instead of FlowLayout.  *   */   public class JAppletExample extends JApplet {   public void init() …

Continue reading

Illustrates the insertion of menu entries in Frame menu bars.

************** ColorMenu.java ************** import java.awt.*; import java.awt.event.*; /** Illustrates the insertion of menu entries in Frame  *  menu bars.  *   public class ColorMenu extends CloseableFrame                        implements ActionListener {                            private String[] colorNames =     { “Black”, “White”, “Light Gray”, “Medium Gray”,       “Dark Gray” };   private Color[] colorValues =     …

Continue reading

JTable Examples

# JTableSimpleExample.java Simple table that takes column names and data from arrays of Strings. import java.awt.*; import javax.swing.*; /** Simple JTable example that uses a String array for the  *  table header and table data.  *  */ public class JTableSimpleExample extends JFrame {   public static void main(String[] args) {     new JTableSimpleExample();   } …

Continue reading

Eight buttons: four each in two panels

mport java.applet.Applet; import java.awt.*; *************************** /** Eight buttons: four each in two panels. * */ public class ButtonTest2 extends Applet { public void init() { String[] labelPrefixes = { “Start”, “Stop”, “Pause”, “Resume” }; Panel p1 = new Panel(); for (int i=0; i<4; i++) { p1.add(new Button(labelPrefixes[i] + ” Thread1″)); } Panel p2 = new …

Continue reading

JList Examples

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) …

Continue reading

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 = …

Continue reading

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));   } }