一点JavaBeans的入门小知识

首先,JavaBeans出现的目的:
Visual Basic is clearly optimized for a particular kind of problem—UI-intensive(UI驱动的) Windows programs. The JavaBeans technology was invented to make Java technology competitive in this arena. It enables vendors to create Visual Basic-style development environments.

这里说一点题外话,NetBeans是sun开发的IDE,从字面意思上可以看出NetBeans对JavaBeans的支持。可见NetBeans在GUI的开发上应该有eclipse不能比的优势(纯属推论,哇哈哈哈)。

Using Beans to Build an Application
To make any bean usable in a builder tool, package into a JAR file all class files that are used by the bean code. Unlike the JAR files for an applet, a JAR file for a bean needs a manifest file that specifies which class files in the archive are beans and should be included in the builder's toolbox. 同时还可以在清单中加入要用的icon图标啥的。
关于如何将Beans导入开发工具,core java中有详细的描述。

The basic rules for designing your own beans
First, we want to stress there is no cosmic beans class that you extend to build your beans. Visual beans directly or indirectly extend the Component class, but nonvisual beans don't have to extend any particular superclass.
请记住, Bean就是一个可以在开发工具中操作的类。开发工具并不会根据它的父类来判断它是否为一个Bean。

The naming pattern for properties is simple: Any pair of methods
public Type getPropertyName(){}
public void setPropertyName(String newValue){}
下面是关于我的一个疑惑:

What do you do if your class has a pair of get and set methods that doesn't correspond to a property that you want users to manipulate in a property inspector? In your own classes, you can of course avoid that situation by renaming your methods. However, if you extend another class, then you inherit the method names from the superclass. This happens, for example, when your bean extends JPanel or JLabel—a large number of uninteresting properties show up in the property inspector. You will see later in this chapter how you can override the automatic property discovery process by supplying bean information. In the bean information, you can specify exactly which properties your bean should expose.

 

For events, the naming patterns are equally simple. A bean builder environment will infer that your bean generates events when you supply methods to add and remove event listeners. All event class names must end in Event, and the classes must extend the EventObject class.

Suppose your bean generates events of type EventNameEvent. The listener interface must be called EventNameListener, and the methods to manage the listeners must be called。

好了!大概了解到此为止~~~

你可能感兴趣的:(一点JavaBeans的入门小知识)