O'Reilly logo

Developing Java Beans by Robert Englander

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building the Simulator

Let’s start building the classes that make up the simulator. We start with the event classes first since they have no dependencies on other classes in the system. After that, we’ll develop the interfaces used to listen for the various events. We’ll finish up with the objects that throw and catch the events in the system. All of the classes will be part of the BeansBook.Simulator package.

Temperature Pulse Events

A temperature pulse event is used to coax a temperature object to alter its value. The pulse contains the temperature value that the source object would like the temperature object to synch up with. First, let’s create a class and call it TemperaturePulseEvent. This is the event object that will be passed as a parameter when the temperature pulse event is fired. The code for the class looks like this:

package BeansBook.Simulator;

// class definition for the temperature pulse event
public class TemperaturePulseEvent
        extends java.util.EventObject
{
   // the pulse temperature
   protected double theTemp;
   
   // constructor
   public TemperaturePulseEvent(Object source, double t)
   {
      // pass the source to the superclass
      super(source);
      
      // save the temperature
      theTemp = t;
   }
   
   // return the pulse temperature
   public double getPulseTemperature()
   {
      return theTemp;
   }
}

As with all event objects, TemperaturePulseEvent extends java.util.EventObject. The variable theTemp stores the value of the temperature pulse. The constructor takes two parameters, named source and t. source is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required