Category: FromSitesTree.com

ListEvent2.java #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

# 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 "java" * over the language list will result …

Continue reading

BorderLayout divides the window into five regions #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

# BorderTest.java Five buttons arranged by BorderLayout BorderLayout divides the window into five regions: NORTH, SOUTH, EAST, WEST, and CENTER. /./././././././././././././ import java.applet.Applet; import java.awt.*; /** An example of BorderLayout. * &&&&&&&&&&&&&&&&&&&&&&&&&&& public class BorderTest extends Applet { public void init() { setLayout(new BorderLayout()); add(new Button("Button 1"), BorderLayout.NORTH); add(new Button("Button 2"), BorderLayout.SOUTH); add(new Button("Button 3"), …

Continue reading

Six buttons arranged in a 2 row x 3 column grid by GridLayout #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

/././././././ 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 GridLayout(2,3)); // …

Continue reading

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 #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

####################### # 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, King.gif, Queen.gif, Jack.gif. …

Continue reading

A Frame that can actually quit #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

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 call super.processWindowEvent first. */ public void …

Continue reading

Checkboxes #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

Checkboxes.java Inherits from CloseableFrame.java. ****************** import java.awt.*; /./././././././././ public class Checkboxes extends CloseableFrame { public static void main(String[] args) { new Checkboxes(); } public Checkboxes() { super("Checkboxes"); setFont(new Font("SansSerif", Font.BOLD, 18)); setLayout(new GridLayout(0, 2)); Checkbox box; for(int i=0; i<12; i++) { box = new Checkbox("Checkbox " + i); if (i%2 == 0) { box.setState(true); } …

Continue reading

creating a simple Swing application using a JFrame #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

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

Implementation of a simple browser in Swing (The user can specify a URL to load into the browser (JEditorPane)) #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

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

BetterCircleTest.java #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

********************** 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 = getSize().width/6; int deltaX = round(2.0 …

Continue reading

Places a Panel holding 100 buttons in a ScrollPane #Programming Code Examples #Java/J2EE/J2ME #Advanced Swing

import java.applet.Applet; import java.awt.*; /** Places a Panel holding 100 buttons in a ScrollPane that is * too small to hold it. * */ public class ScrollPaneTest extends Applet { public void init() { setLayout(new BorderLayout()); ScrollPane pane = new ScrollPane(); Panel bigPanel = new Panel(); bigPanel.setLayout(new GridLayout(10, 10)); for(int i=0; i<100; i++) { bigPanel.add(new …

Continue reading