Tag: Java

ReverseLabels.java Inherits from CloseableFrame.java and uses ReversibleLabel.java.

ReverseLabels.java Inherits from CloseableFrame.java and uses ReversibleLabel.java. ********************** ReverseLabels.java ********************** import java.awt.*; ****************** public class ReverseLabels extends CloseableFrame {   public static void main(String[] args) {     new ReverseLabels();   }   public ReverseLabels() {     super(“Reversible Labels”);     setLayout(new FlowLayout());     setBackground(Color.lightGray);     setFont(new Font(“Serif”, Font.BOLD, 18));     ReversibleLabel label1 =       new ReversibleLabel(“Black …

Continue reading

TextFields

import java.applet.Applet; import java.awt.*; /** A TextField from each of the four constructors.  *  ********************* public class TextFields extends Applet {   public void init() {     add(new TextField());     add(new TextField(30));     add(new TextField(“Initial String”));     add(new TextField(“Initial”, 30));   } }

ChoiceTest2

ChoiceTest2.java /././././././././ import java.applet.Applet; import java.awt.*; import java.awt.event.*; /***********************/ public class ChoiceTest2 extends Applet                          implements ItemListener {   private Choice choice;   public void init() {     setFont(new Font(“SansSerif”, Font.BOLD, 36));     choice = new Choice();     choice.addItem(“Choice 1”);     choice.addItem(“Choice 2”);     choice.addItem(“Choice 3”);     choice.addItemListener(this);     add(choice);   }   public void …

Continue reading

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