Gauge Bean Samples

Connecting Two Gauges Together

One way to quickly see the Gauge Beans is to try them out using IBM VisualAge for Java. In this sample, you update the value of a Bar Indicator gauge using an editable Needle gauge.

  1. Open IBM VisualAge for Java and import s103_gauges.jar into a palette of your choice. (See the VisualAge for Java documentation if you need help).
  2. Create a new JApplet by choosing Selected -> Add -> Applet... Ensure that the super class of the applet is com.sun.java.JApplet.
  3. Add a Needle Gauge bean to the workspace:

    Selecting and adding a Needle Gauge

  4. Add a Bar Indicator Gauge Bean to the workspace:

    Selecting and adding a Bar Indicator

  5. Double-click the needle gauge to bring up its Properties window:

    Setting Needle Gauge to editable

  6. Set the editable property to True, which lets you click and drag the needle to update the gauges' values.
  7. Now you can connect the Bar Indicator and Needle Gauge beans together. Right-click on the Needle Gauge bean and select Connect -> Connectable Features to bring up the connection dialog:

    Value property of Needle Gauge

  8. Choose the model property from the property list. If the model property does not appear in the list, ensure that Show expert features is checked.
  9. Move the mouse over the Bar Indicator bean and click it to create the connection. This brings up a menu to  complete the connection. Select Connectable Features to bring up the connection dialog and choose the model property from the properties list as before.
  10. To see the connection in action select Bean -> Run -> In AppletViewer. Manipulate the Needle gauge, and the value displayed by the Bar Indicator will change.

Using Accumulation to Set the Gauge Value

In this sample, you set the gauge value by accumulating events. You connect a JTextPane to an LEDCounter Gauge.

  1. Open IBM VisualAge for Java and load gauges.jar and gaugetest.jar into a palette of your choice. (See the IBM VisualAge for Java documentation if you need help doing this). If VisualAge for Java is already open, select Edit - Select All, then Edit - Cut to clear the workspace.
  2. Add an instance of the JTextPane bean and the LEDCounter bean, from the Swing and Gauges palettes respectively, onto the workspace:

    LEDCounter and JTextPane beans

  3. Double-click on the LED Counter bean to bring up its Properties window. Set the accumulatorInterval property to 1000 and the accumulatorEnabled property to True.
  4. Right-click on the JTextPane, and select Connect -> keyTyped:

    Connecting the beans

  5. Move the mouse over the LED Counter bean and click to create the connection. This brings up a menu to allow you to complete the connection. Select Connectable Features to bring up the connection dialog and choose the accumulate( ) method from the method list.

    Selecting the accumulate() method

  6. Select Bean - Run - In AppletViewer, and then type into the text area as fast as you can. The LED Counter bean updates to show you how many keys per second you are typing.

Copyright © IBM Corporation 1998, 1999. All Rights Reserved