|
Programmers coming from a Windows background (specifically, Visual Basic or C#) will immediately know why beans are so important. Programmers coming from an environment in which the tradition is to "roll your own" for everything may not understand at once. In our experience, programmers who do not come from a Visual Basic background often find it hard to believe that Visual Basic is one of the most successful examples of reusable object technology. One reason for the popularity of Visual Basic becomes clear if you consider how you build a Visual Basic application. For those who have never worked with Visual Basic, here, in a nutshell, is how you do it:
For example, in Volume 1, Chapter 2, we wrote a program that displays an image in a frame. It took over a page of code. Here's what you would do in Visual Basic to create a program with pretty much the same functionality:
Now, we need to write the four lines of Visual Basic code that will be activated when the project first starts running. The following code pops up the file dialog boxbut only files with the right extension are shown because of how we set the filter property. After the user selects an image file, the code then tells the Image control to display it. All the code you need for this sequence looks like this: Private Sub Form_Load() CommonDialog1.ShowOpen Image1.Picture = LoadPicture(CommonDialog1.FileName) End Sub That's it. The layout activity, combined with these statements, gives essentially the same functionality as a page of Java code. Clearly, it is a lot easier to learn how to drop down components and set properties than it is to write a page of code. We do not want to imply that Visual Basic is a good solution for every problem. It is clearly optimized for a particular kind of problemUI-intensive Windows programs. The JavaBeans technology was invented to make Java technology competitive in this arena. It enables vendors to create Visual Basic-style environments for developing Java user interfaces with a minimum of programming. |
|