So far in this book youve seen how valuable Java is for creating reusable pieces of code. The most reusable unit of code has been the class, since it comprises a cohesive unit of characteristics (fields) and behaviors (methods) that can be reused either directly via composition or through inheritance.
Inheritance and polymorphism are essential parts of object-oriented programming, but in the majority of cases when youre putting together an application, what you really want is components that do exactly what you need. Youd like to drop these parts into your design like the chips an electronic engineer puts on a circuit board. It seems, too, that there should be some way to accelerate this modular assembly style of programming.
Visual programming first became successfulvery successfulwith Microsofts Visual BASIC (VB), followed by a second-generation design in Borlands Delphi (the primary inspiration for the JavaBeans design). With these programming tools the components are represented visually, which makes sense since they usually display some kind of visual component such as a button or a text field. The visual representation, in fact, is often exactly the way the component will look in the running program. So part of the process of visual programming involves dragging a component from a palette and dropping it onto your form. The application builder tool writes code as you do this, and that code will cause the component to be created in the running program.
Simply dropping the component onto a form is usually not enough to complete the program. Often, you must change the characteristics of a component, such as its color, the text thats on it, the database its connected to, etc. Characteristics that can be modified at design time are referred to as properties. You can manipulate the properties of your component inside the application builder tool, and when you create the program, this configuration data is saved so that it can be rejuvenated when the program is started.
By now youre probably used to the idea that an object is more than characteristics; its also a set of behaviors. At design time, the behaviors of a visual component are partially represented by events, meaning Heres something that can happen to the component. Ordinarily, you decide what you want to happen when an event occurs by tying code to that event.
Heres the critical part: The application builder tool uses reflection to dynamically interrogate the component and find out which properties and events the component supports. Once it knows what they are, it can display the properties and allow you to change them (saving the state when you build the program), and also display the events. In general, you do something like double-clicking on an event, and the application builder tool creates a code body and ties it to that particular event. All you have to do at that point is write the code that executes when the event occurs.
All this adds up to a lot of work thats done for you by the application builder tool. As a result, you can focus on what the program looks like and what it is supposed to do, and rely on the application builder tool to manage the connection details for you. The reason that visual programming tools have been so successful is that they dramatically speed up the process of building an applicationcertainly the user interface, but often other portions of the application as well.