home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 3.1 KB | 121 lines |
-
- /**
- * Simple applet to test JanneButton class
- */
- import java.awt.*;
- import java.awt.image.*;
- import java.applet.Applet;
-
- public class ButtonTest extends Applet {
- Image joe;
- JanneButton button3;
- // used by ctrl panel...
- Checkbox isEnabled;
- Checkbox isVisible;
- Checkbox imageUsed;
- Checkbox labelUsed;
- Checkbox resizeImage;
- TextField labelText;
-
- public void init() {
- // test setting of background
- //setBackground(new Color(0xEED5B7));
-
- // Create a grid where we add the buttons
- setLayout(new BorderLayout());
- Panel grid = new Panel();
- grid.setLayout(new GridLayout(0, 2));
- add("Center", grid);
- add("East", ctrlPanel());
-
- // get the image
- joe = getImage(getDocumentBase(), "images/joe.gif");
-
- // create buttons (one standard awt to compare...)
- // The 3'rd button is controlled by a ctrl panel
- grid.add(new Button("button1"));
- grid.add(new JanneButton(joe, "button2"));
- grid.add(button3 = new JanneButton(joe, "button3", false, false));
- grid.add(new JanneButton("button4"));
-
- show();
- }
-
- public Panel ctrlPanel() {
- Panel ctrlPanel = new Panel();
- ctrlPanel.setLayout(new BorderLayout());
-
- Panel p1 = new Panel();
- p1.setLayout(new BorderLayout());
- p1.add("North", new Label(""));
- p1.add("Center", new Label("Control Button 3:"));
- p1.add("South", new Label(""));
- ctrlPanel.add("North", p1);
-
- Panel p2 = new Panel();
- p2.setLayout(new GridLayout(0, 2, 4, 4));
-
- p2.add(new Label("Enabled:"));
- isEnabled = new Checkbox("", null, true);
- p2.add(isEnabled);
-
- p2.add(new Label("Visible:"));
- isVisible = new Checkbox("", null, true);
- p2.add(isVisible);
-
- p2.add(new Label("Display Image:"));
- imageUsed = new Checkbox("", null, true);
- p2.add(imageUsed);
-
- p2.add(new Label("Display Label:"));
- labelUsed = new Checkbox("", null, false);
- p2.add(labelUsed);
-
- p2.add(new Label("Resize Image:"));
- resizeImage = new Checkbox("", null, false);
- p2.add(resizeImage);
-
- p2.add(new Label("String Label:"));
- labelText = new TextField("button3", 8);
- p2.add(labelText);
-
- ctrlPanel.add("Center", p2);
- Panel p3 = new Panel();
- p3.setLayout(new FlowLayout());
- p3.add(new JanneButton("Update"));
- ctrlPanel.add("South", p3);
-
- return ctrlPanel;
- }
-
-
- /**
- * Called when we press the buttons
- */
- public boolean action(Event evt, Object arg) {
- if (evt.target instanceof Checkbox) {
- }
- else if(evt.target instanceof JanneButton &&
- ("Update".equals(arg))) {
- // update button 3
- if (isEnabled.getState())
- button3.enable();
- else
- button3.disable();
- button3.show(isVisible.getState());
- if (imageUsed.getState())
- button3.setImage(joe);
- else
- button3.setImage(null);
- button3.setResizeImage(resizeImage.getState());
- button3.setShowLabel(labelUsed.getState());
- button3.setLabel(labelText.getText());
- }
- else
- System.out.println("Button selected: " + (String)arg);
- return true;
- }
-
- }
-
-