home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 2.2 KB | 79 lines |
-
- /**
- * Simple applet to test JanneButton class
- */
- import java.awt.*;
- import java.awt.image.*;
- import java.applet.Applet;
-
- public class JanneButtonTest extends Applet {
- public void init() {
- // test setting of background
- //setFont(new Font("Helvetica", Font.BOLD, 16));
- setBackground(new Color(0xEED5B7));
- setLayout(new BorderLayout());
-
- // get the images
- Image joe = getImage(getDocumentBase(), "images/joe.gif");
- Image left = getImage(getDocumentBase(), "images/left.gif");
-
- // create 1'st panel
-
- Panel panel1 = new Panel();
- // create grid bag
- GridBagLayout gridbag = new GridBagLayout();
- GridBagConstraints c = new GridBagConstraints();
- panel1.setLayout(gridbag);
- Insets insets = new Insets(2, 2, 4, 2);
- c.insets = insets;
- // add a few buttons
- addButton(panel1, gridbag, c, "Label Button:",
- null, "With a Label", false);
- addButton(panel1, gridbag, c, "Image Button:",
- left, "left", false);
- addButton(panel1, gridbag, c, "Image/Label Button:",
- left, "Left", true);
- add("West", panel1);
-
-
- // create 2'nd panel
- Panel panel2 = new Panel();
-
- // create grid bag
- gridbag = new GridBagLayout();
- c = new GridBagConstraints();
- panel2.setLayout(gridbag);
- insets = new Insets(2, 2, 4, 2);
- c.insets = insets;
- // add large button
- addButton(panel2, gridbag, c, "Large Image Button:",
- joe, "joe", false);
- add("Center", panel2);
-
- show();
- }
-
- public void addButton(Panel panel,
- GridBagLayout gridbag, GridBagConstraints c,
- String labelStr, Image image, String buttonStr,
- boolean showLabel)
- {
- Label label = new Label(labelStr);
- JanneButton button;
- if (image != null)
- button = new JanneButton(image, buttonStr, false, showLabel);
- else
- button = new JanneButton(buttonStr);
- c.gridwidth = 2;
- c.anchor = GridBagConstraints.EAST;
- gridbag.setConstraints(label, c);
- panel.add(label);
- c.anchor = GridBagConstraints.WEST;
- c.gridwidth = GridBagConstraints.REMAINDER;
- gridbag.setConstraints(button, c);
- panel.add(button);
- }
-
- }
-
-