RCP development experience using netbeans Platform

Source: Internet
Author: User
Tags netbeans java se

I developed RCP in the last month. I used netbeans platform and encountered many unexpected problems during the development process. So I summarized it and shared it with you.

The main content of the project is to port an application developed by Java se to the netbeans platform. Select netbeans5.5 for development ide and netbeans6 for platform.

There is a demo for developing CD player on the netbeans website. It develops an application from the ground up for use with Web Services, and then migrates the application to the netbeans platform. during the migration process, since its layout is very simple, you can directly put the main panel-generated swing component into the component, however, if a large multi-page project is implemented, it is a bit complicated because the initialization process is complicated. You can refer to the module development demo on the netbeans website. Follow the anw.game tutorial and rewrite the main class code of the original application. Therefore, it is recommended that you do not put everything in a frame during application development. You should preferably write it as a panel so that it can be embedded in the frame or in the topcomponent.

During the process from panel to topcomponent, the biggest problem I encountered was the initialization problem. The original application is a three-tab page. Now, we need to create three new window top component for porting to platform, with one tab page for each window. Since the original application will have an entry, the resources required by the program will be initialized at the entrance. After being transplanted to the platform, the initialization sequence of each window top component is uncertain, therefore, you need to initialize resources in each window, and ensure that the global variables are not affected. If you put the Resource Initialization in a window, the nullpoint exception occurs when other windows are started.

Once a null pointer exception occurs, the program cannot run normally, and the running program cannot be stopped through Build-> stop build/run in the menu. If we click "run" again, an empty frame with only the title bar will appear in the upper left corner of the screen. This shows that the program has not actually stopped. The logging manager will see that there are two java.exe instances, one of which is the Java enabled by netbeans, occupying more than 200 MB, and the other is the Java started by the program we wrote, ranging from several MB to dozens of MB. We only need to manually end java.exe with a relatively small amount of memory. Then we can see that the output console of netbeans displays build success, indicating that the program has stopped.

After the code is modified, it must be cleared and re-compiled before the code can be started normally. However, before re-compilation, you must stop the program that has just failed to run according to the previous steps. After it is stopped, clean and build all can be re-compiled. If an error occurs when "project name. xml" is displayed, delete the build directory and compile it.

If you have prepared the corresponding panel, pay attention to layout when manually adding the panel to the window top component in the code. Because Matisse is used for group layout during GUI development in netbeans, the code of group layout is automatically generated. If you want to add the Panel1 we designed on the panel with the Matisse layout, you cannot use the Panel. Add (Panel1. Nothing can be seen during running. Before writing add, we need to reset the layout of the Panel. Therefore, if you want to implement the previous function, you need to write the following code:

Jpanel1.setlayout (New borderlayout ());

Jpanel1.add (Panel1 );

Then run the command to view the added Panel1. I have not studied the content of group layout and other related layout.

During plug-in development and rcp development, relevant parameters are set in the Wizard. For example, you can set the name and position of action and topcomponent. What if we want to change the name and related parameters in the future? These parameters are stored in some XML files. The parameters of classes in the newly created module category are stored in the bundle. properties file. This file is in the same folder as the created class. For example, open a bundle. properties file and you can see:

Ctl_aboutaction = & about

Ctl_newaction = & New

Ctl_simapptopcomponent = Application config window

Ctl_simtopcomponent = grid config window

Ctl_simulationtopcomponent = simulation window

Hint_simapptopcomponent = This is a application configuration window

Hint_simtopcomponent = This is a grid configuration window

Hint_simulationtopcomponent = This is a simulation window

The name of the class displayed in the window starts with CTL. For example, action is the name displayed in the menu, and topcomponent is the name of the title displayed by the window creation. The hint starts with the Toolkit hint function. When you move the cursor to the desktop title, a prompt is displayed. Modify the preceding parameters.

The parameter settings of the entire project are in the layer. xml file, which contains a lot of important layout information. You can directly edit the layout to change a lot of content. However, if you are not familiar with it, you are not recommended to modify it. However, we may often need to change the menu order so that we can click important files in the project. The first item is the XML layer. After expansion, we can see this layer and this layer in context. Expand the first one to see actions, menu, and windows2. You can drag the menu to change the sequence.

If you do not want to use the original menu of platform, you need to select the core-UI module in platform6 in the library of the Project property. If you do not select the menu, there will be the simplest Goto, view and windows. You can create other menus by yourself. Generally, multiple Windows menus are required. If you do not want to display Goto and view, you can add the following two lines in layer. xml:

<File name = "goto_hidden"/>

<File name = "view_hidden"/>

Of course, each topcomponent component will have a corresponding XML file to specify parameters, but these do not need to be concerned.

Netbeans platform is very convenient to use. Many functions have been implemented by platform's built-in modules. You only need to add or delete them as needed. It seems that we are using MFC to develop GUI applications. We don't need to worry about various complicated functions, but just need to focus on the most important part. Get twice the result with half the effort.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.