1. Javabean and EJB (1) JavaBean and EJB specification have a common goal in the following areas: promotion Java program code through standard design mode, enhances the repetitive useability of development process and development tools
. But the original problem of these two specifications is to solve different problems. Defined in the standard specification in the JavaBean component model, designed to generate repeatable components, and these components are often used for IDE development tools, and is usually visualization components, of course
It is not necessarily a visual component. (2) EJB specification defined component model, just the Java program used to develop the server, because EJB may execute on different server platforms, including large hosts without graphics, so EJB no
Method uses a graphical library similar to AWT or SWING. 2. JavaBean and class library Differences: (1) Not all useful modules must be converted to bean. Bean is mainly to be used to visualize the operation to complete some effects. (2) Class library is a valid operation for providing function operations to the programmer, but does not benefit from visualization operations. (3) For example, provide an API of JDBC database access as a class library than A bean is better, because the core of JDBC is to use a programmable API, it is not able to show directly
Visualization operation. However, writing a log library Access bean is still meaningful in the top of the JDBC. For example, you can write a custom "SELECT" bean to help users make
Query statements, and the program runs with JDBC to run this query statement and display the result set. 3. Javabean and Visual Programming 3.1 Visual Programming (1) Turning the components from the component board to the form by visual programming tools such as VB, Delphi, etc., when you are dragging, the program development tool begins to write code for you, these Code makes this group
The item is generated when the program is executed. (2) Just drag the component to the form, usually not enough to complete the program, usually you have to change the nature of the component such as color, text, connection database. During the design, you can modify Nature called "attribute
", 佻 You can modify the properties of the component in the program development tool, which is built, and its configuration will be stored. When the program is executed, these settings can reply. (3) During the design, a total of visual components Sub-events, means that these things can occur on this component. (4) The program development tool uses the reflex mechanism ("Reflection") mechanism dynamically query component, and finds the properties supported by the component (Properties) , And events, know
Once this information, it can display its properties and allow you to change, and display the available events. 3.2javabean can be seen in the above visual programming programming programming program, the component is a program code, by being stored as Class, the key in the program How to find the properties and events of the assembly. VB and Delphi are
This is achieved by a mechanism, while Java will bring the visual components into a higher realm through Javabeans, because a bean is a class. For the above
Rong, JavaBean has the following rules (1) For an attribute called xxx, you usually have to write two functions, getxxx () and setxxx (). (2) You can use Get / SET mode to handle Boolean, you can use IS instead of GET. (3) The general function of bean does not need to comply with the above naming rules, but need to be public. (4) For events, you can use Swing listener to handle. 3.3javabean key technology (1) Part of the most critical part of the Bean architecture occurs when dragging the bean from the component disk Palette, the program development tool can generate beans (if there is a Default constructor, do
Get it), then all the necessary information "generating the properties work" and the event handler in the absence of the Bean source code. (2) Java's Reflection allows us to find any unknown class All functions, Reflection mechanisms are used to solve the problem of Bean, very perfect, no need to be a visual language
Make the extra language keyword. ** In fact, the Reflection mechanism will be added to Java's main reasons to support Beans (of course, REFLECTION is also serialization and remote method calls (Remote Method) Invocation provides the necessary skills). So you may expect that the designer of the program development tool should be in each
BEAN is using the reflection mechanism, finds its function, finds Bean's properties and events. (3) Java designer wants to provide a standard tool, not only make BEAN more easy to use, but also provide standard ways to produce more complex beans. This tool. Introspector Class
The important thing is static getBeanInfo (). You can pass a Class Reference to this function, it will check the Class and return to the beanfo object. Then you can
To dissect it, obtain its properties, a function (Methods), event (event). 3.4 bean packaging to put Bean in the standard Bean container before you support the Bean visual development tool. The so-called standard Bean container is a JAR file, with all Beans
Classes and a list of list 5. JavaBean's Architecture JavaBean architecture is one of the first comprehensive component-based standard models. In integrated IDE, make JavaBeans can be operated in design. (Metrics model As shown below:)
JavaBean's component model provides developers with a standard way to define a Java class so that its components are operated in the JavaBean container environment, and the JavaBean component is defined according to various attributes.
The type provides its properties, events, and inner view information, which allows design tools to achieve the purpose of bean itself during design. 6. JavaBean programming basic requirements: If you want to create a product class bean, remember the following things: (1) make the BEAN, better, but pay attention to whether the current browser supports small bean beans may result in tool lag Continue to lead the browser to lag, eventually leading to the JDK itself lag. If you have to use the classes of the Tie, or the nature of Bean requires a larger, then
You should consider using your bean as a plugin and send it in a self-contained JAR, or if possible, make it your own small installation process. You will lose some small beans
Advantages: Web administrators must perform more steps: Remind users to download and install your JAR or installer online surfers before browseing the web page: Download and install you before browsing the web page JAR or installer. (2) Separate all translation text, including a short description and characteristics of Name and beans, including name and beans, are divided into .properties files. JAR wizards do this for you. You need to remember that both you have done is: Features Editor and customizers. Tactors, dialog feature editor, or select all terms in the feature editor, such as high, medium, low, and also
It must be separated for translation. Ideally, you can also actually translate beans and provide a .properties file in a variety of languages in Bean's JAR. However, if you provide at least the local language
.properties file, third parties can translate beans for you. (3) Specifying Depends-ON in the file list: Tagging to identify all files in Bean's JAR as "Running requires VS. only when editing". All files needed at runtime will be listed on the JAR inventory file dependent on: label
Rear. The JAR wizard release label makes this operation very simple and gives you a list of files. If you don't specify dependencies: labels, the tool will assume that all files are required at runtime. This is not good for downloading performance (eg, unnecessary download features editor and other files needed only when editing). (4) Give your bean a clear preferred size bean will implement the getPreferredSize method so that it is good when it is first constructed in a keyword characteristic that may not be defined. BEAN is 0 x 0 when placed in the first time
Pixels, then users may confuse. When changing keyword features, the preferred size should work normally. For example, if the bean has a characteristic of conversion between vertical and horizontal orientation,
The selection should be written to adjust itself accordingly. (5) Specify the default feature of the BEAN to use the default characteristic part of the JavaBean specification, which will make your bean are easy to use in some tools. JAR will make this operation simple and get BeanInfo right. (6) Specify a brief non-technical name and short description for Bean and its characteristics to find brief non-technical names instead of lengthy technical terms. For example, use SUM Interval instead of AccumulatorInterval. Please note that the preference of the character name is indicated by lowercase
There is a space between the word and the word, which will be more friendly for the user. (7) Reduce the user-visible characteristics range to beans provide a clear beanfo to not display each instance variable as a BEAN, and do not display each method as a bean operation. JAR wandering
The operation is simple and gets BeanInfo right for you. (8) Specify a large icon and small icon for the bean, providing BEAN to provide large (32x32) and small (16x16) color icons for BEAN. Moreover, make sure the icon has a transparent background different from gray. Despite rassing, you should also develop
Habits for black and white icons. JAR wizard's palette tag makes this operation simple and enables you to get BeanInfo
?
?
?