# 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”), …
Tag: Java
Aug 26
Checkboxes
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 …
Aug 26
Places a Panel holding 100 buttons in a ScrollPane
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)); …
Aug 26
Five buttons arranged by FlowLayout
FlowTest.java ************* FlowTest.java Five buttons arranged by FlowLayout By default, FlowLayout arranges components in rows, left to right, and centered. /././././././././././././ import java.applet.Applet; import java.awt.*; /** FlowLayout puts components in rows. * ************************************ public class FlowTest extends Applet { public void init() { for(int i=1; i<6; i++) { add(new Button(“Button ” + …
Aug 26
A Frame that lets you draw circles with mouse clicks
SavedFrame.java **************** A Frame that lets you draw circles with mouse clicks //************** import java.awt.*; import java.awt.event.*; import java.io.*; /** A Frame that lets you draw circles with mouse clicks * and then save the Frame and all circles to disk. * public class SavedFrame extends CloseableFrame implements ActionListener { /** If …
Aug 26
FrameExample1.java and 2
****************** # FrameExample1.java ****************** import java.awt.*; /** */ public class FrameExample1 { public static void main(String[] args) { Frame f = new Frame(“Frame Example 1”); f.setSize(400, 300); f.setVisible(true); } } ********************* # FrameExample2.java ********************* import java.awt.*; /** */ public class FrameExample2 extends Frame { public static void main(String[] args) …
Aug 26
ThreadedRSAKey.java Illustrates converting a method in an existing class from a single-threaded method to a multi-threaded method.
ThreadedRSAKey.java Illustrates converting a method in an existing class from a single-threaded method to a multi-threaded method. In this example, RSAKey computes an RSA public-private key pair, where the key size has a specified number of digits. As large prime numbers require considerable CPU time, ThreadedRSAKey converts the original computeKey method in RSAKey to a …
Aug 26
Eight ungrouped buttons in an Applet using FlowLayout
mport java.applet.Applet; import java.awt. *; ************************** /** Eight ungrouped buttons in an Applet using FlowLayout. * */ public class ButtonTest1 extends Applet { public void init() { String[] labelPrefixes = { “Start”, “Stop”, “Pause”, “Resume” }; for (int i=0; i<4; i++) { add(new Button(labelPrefixes[i] + ” Thread1″)); } for (int i=0; i<4; i++) { add(new …
Aug 26
A Circle component built using a Canvas
import java.awt.*; /** A Circle component built using a Canvas. * */ public class Circle extends Canvas { private int width, height; public Circle(Color foreground, int radius) { setForeground(foreground); width = 2*radius; height = 2*radius; setSize(width, height); } public void paint(Graphics g) { …
Aug 26
Simplifies the setting of native look and feel
WindowUtilities.java Simplifies the setting of native look and feel. #################### 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) LAF …