home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / desvs7nu / src / jannebuttontest.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  2.2 KB  |  79 lines

  1.  
  2. /** 
  3.  * Simple applet to test JanneButton class
  4.  */
  5. import java.awt.*;
  6. import java.awt.image.*;
  7. import java.applet.Applet;
  8.  
  9. public class JanneButtonTest extends Applet {
  10.    public void init() {
  11.       // test setting of background
  12.       //setFont(new Font("Helvetica", Font.BOLD, 16));
  13.       setBackground(new Color(0xEED5B7));
  14.       setLayout(new BorderLayout());
  15.  
  16.       // get the images
  17.       Image joe = getImage(getDocumentBase(), "images/joe.gif");
  18.       Image left = getImage(getDocumentBase(), "images/left.gif");
  19.  
  20.       // create 1'st panel
  21.       
  22.       Panel panel1 = new Panel();
  23.       // create grid bag
  24.       GridBagLayout gridbag = new GridBagLayout();
  25.       GridBagConstraints c = new GridBagConstraints();
  26.       panel1.setLayout(gridbag);
  27.       Insets insets = new Insets(2, 2, 4, 2);
  28.       c.insets = insets;
  29.       // add a few buttons
  30.       addButton(panel1, gridbag, c, "Label Button:",
  31.         null, "With a Label", false);
  32.       addButton(panel1, gridbag, c, "Image Button:",
  33.         left, "left", false);
  34.       addButton(panel1, gridbag, c, "Image/Label Button:",
  35.         left, "Left", true);
  36.       add("West", panel1);
  37.       
  38.  
  39.       // create 2'nd panel
  40.       Panel panel2 = new Panel();
  41.  
  42.       // create grid bag
  43.       gridbag = new GridBagLayout();
  44.       c = new GridBagConstraints();
  45.       panel2.setLayout(gridbag);
  46.       insets = new Insets(2, 2, 4, 2);
  47.       c.insets = insets;
  48.       // add large button
  49.       addButton(panel2, gridbag, c, "Large Image Button:",
  50.         joe, "joe", false);
  51.       add("Center", panel2);
  52.  
  53.       show();
  54.    }
  55.  
  56.    public void addButton(Panel panel,
  57.              GridBagLayout gridbag, GridBagConstraints c,
  58.              String labelStr, Image image, String buttonStr,
  59.              boolean showLabel)
  60.    {
  61.       Label label = new Label(labelStr);
  62.       JanneButton button;
  63.       if (image != null)
  64.      button = new JanneButton(image, buttonStr, false, showLabel);
  65.       else
  66.      button = new JanneButton(buttonStr);
  67.       c.gridwidth = 2;
  68.       c.anchor = GridBagConstraints.EAST;
  69.       gridbag.setConstraints(label, c);
  70.       panel.add(label);
  71.       c.anchor = GridBagConstraints.WEST;
  72.       c.gridwidth = GridBagConstraints.REMAINDER;
  73.       gridbag.setConstraints(button, c);
  74.       panel.add(button);
  75.    }
  76.    
  77. }
  78.  
  79.