Getting started with jigloo swing Development
URL: http://www.blogjava.net/wangscu/archive/2007/08/21/138468.html
References:
Getting started with SWT development for jigloo
Author:BeanSoft@126.com
Date: 2007.04.30
Reprinted please indicate the sourceHttp://www.blogjava.net/beansoft/
Download the operation video in this article:Jigloo_swing.swf1.86 MB
Some friends often develop a conversion tool algorithm by themselves. They want to encapsulate it for their colleagues in a graphical interface, but they do not know how to do it. this article describes how to use jigloo to develop a simple swing desktop applicationPublic static string doconvert (string input)The method is encapsulated into a graphic interface version. this article is applicable to users who have never had GUI/SWT development experience but are familiar with the basic use of Eclipse IDE and plug-in installation. Readers should also have knowledge and use of the Java language.
This article does not cover SWT/swing and GUI Design Knowledge.
Here, swing is used to design this interface. The steps are simpler than those based on SWT, because swing does not need to be installed (JDK/JRE comes with it ). the author's Tomcat server monitor is to use jigloo to complete most of the interface development work.
Digress: currently, the best interface designer developed by swing interface is the interface designer of netbeans, which basically eliminates the need to consider layout issues.
Readers who want to have a deep understanding of how to use jigloo can readJigloo GUI builder GuideThis section describes more techniques, such as how to use jigloo in large file mode and how to avoid parsing some code, how does jigloo parse interface code and open interface files created by other interface designers. these help documents can be opened through the help-> help contents menu.
1. Build a Development Environment
1. Download and install JDK/JRE
JDK canHttp://java.sun.com/j2se/Download and install the JDK. We will not go into details here. After the JDK is installed, it can be used to develop and run swing.
2. Download and install jigloo
Jigloo
It can identify the GUI created by most formbuilder, such as JBuilder, which runs faster and is better than visual editor. you can edit the AWT and swing/SWT interfaces. for personal use, fees are charged for commercial use.
Note: jigloo is free for non-commercial cial use, but purchase of a professional license is required for commercial cial use (after successfully evaluating jigloo ).
Note: The Eclipse versions tested and run in MySQL 3.95 include 2.1, 3.2, and 3.3. For ease of illustration, the eclipse versions used in this article are 3.3.0, jigloo 3.95, and JDK 1.5.
Eclipse:
3.0. *, 3.1 *, 3.2 *, 3.3
Java:
1.3, 1.4 or 5.0
Platforms:
Windows, Linux (GTK) and Mac OSX. (on a Mac, only SWT guis can be built ).
:Jigloo_395.zip
Ii. simple use of jigloo
1. First knowledge of jigloo
First, we need to create a Java project named jiglooswing as shown above:
Select File-> New-> project..., select Java project in the first category, click Next, enter jiglooswing, and click"FInish "button. Copy the following code to the clipboard, right-click the src directory of myproject, and select" Paste ", so that the conversion class appears in the project:
public class Converter {public static String doConvert(String input) {return input + " is converted.";}}
Choose file-> New-> other... from the menu, open classification GUI forms-> swing in the new dialog box, and select jframe, as shown in:
In the following wizard dialog box, keep the default input value unchanged, and then delete the SRC package name:
Then, the new file is automatically opened with the jigloo interface designer, as shown below:
The Outline (outline) page displays the following content:
(1) click the button to switch whether to display the grid;
(2) click the button to pop up a window to preview the current design interface (not compiled );
(3) click the button to compile and run the generated code;
(4) click the button to start/stop the analysis code changes (the design interface is generated by the Code );
(5) Whether to display inherited components during button switching;
(6) switch the button interface from SWT to swing or reverse conversion (note that there will be code errors, which are not 100% accurate );
(7) list the Component Hierarchy outlines on the interface, and click to select the corresponding components.
The following content is displayed on the editor page:
(8) UI being designed. Click handle and drag to adjust the widget size and position;
(9) Select the SWT/swing component panel, click a component, and click (8) again to place the component on the interface. You can also adjust the size and position of the component;
(12) The Code view is displayed. This is the generated code. You can also modify the code below. After that, the interface in the design will be resolved again;
The GUI properties page displays the following content:
(10) The button switching property list is displayed as a drag Panel (sashform) or a multi-page Panel (tabbedpane );
(11) attribute list, in sequence: properties, layout, and event ).
2. Drag and Drop quick build Interface
Drag and Drop to preview.
First, selectThis-jframe, borderIn (11), select the layout panel, click the tree node layout (*), and select its value as absolute (absolute layout) from the drop-down list box on the right ).
We chose this layout mainly for the rapid development of the relationship, although this is not a good choice. For details, you can view relevant information about swing development on your own.
Okay, select panel components in (9), click the jtextfield control twice, and place it on the design panel. Drag the control so that it does not overlap and place it in the appropriate position, the two components can be jtextfield1 and jtextfield2.
Finally, we add a jbutton and modify the text value to OK in the Add dialog box.
Drag and Drop each component to fit the layout, as shown in:
At this time, you can click the toolbar button (2) or (3) to preview the designed interface. jigloo has helped you write most of the code, so you don't have to worry about the interface being unable to be displayed.
3. Add the Event Response Code
First, click the "OK" button on the interface, select the event panel in (11), expand actionlistener, click the not handled drop-down box on the right of the actionreceivmed node, and then select handler method, this will generate an event call method triggered by clicking OK, as shown in:
Then, the mouse in the editor locates the generated event method. The default generated code is as follows:
private void jButton1ActionPerformed(ActionEvent evt) {System.out.println("jButton1.actionPerformed, event=" + evt);//TODO add your code for jButton1.actionPerformed}
We can add the following code after todo to complete the required functions:
Jtextfield2.settext (converter. doconvert (jtextfield1.gettext ()));
This Code sets the text content in text box 2 as the content processed by the previous conversion code. The input content is the text displayed in jtextfield1, which is equivalent to calling the following code:
String input = jtextfield1.gettext ();
String output = converter. doconvert (input );
Jtextfield2.settext (output );
The settext (string) and gettext () Methods read and write the text displayed by the component.
4. Test
Click (3), run, modify the value in jtextfield1, and click OK. The running result is normal, as shown in:
3. Package and publish applications
1. Directory layout and copy dependent files
Our project does not rely on any third-party packages. The final file directory structure is shown below:
Jiglooswing
Category-classes
└ ── SRC
2. Write the Startup Script
Write and run. bat in the root directory. The content is as follows:
java -cp classes NewJFrame
Double-click the batch file to view the main window.
Iv. FAQs
You are welcome to ask questions and come.WikiMessage exchange.
Some common minor problems.
Q: After I edited the following code, I found that the GUI properties panel and the Component Hierarchy outline disappeared?
A: click the button in the interface designer and the GUI properties panel will appear again.
Q: What should I do if I want to set a title for the window and set the default value to NULL for the two text boxes?
A: Modify the text in the properties attribute. You can select a component in the interface designer and modify the component on the GUI attribute page. the main window is a little more complex. As shown in, you need to select jframe and then modify it:
Q: I want to use a multi-Line Text Editor (textarea). The example in this article is a single-line text box. What should I do?
A: change this operation to "next select panel components in (9), and then click twiceJtextareaControl, put it on the design panel, drag it so that it does not overlap and placed in the appropriate position, the two components according to the default value, respectively, jtextarea1, jtextarea2. if you find that it cannot be added when you put jtextarea2, put it in outline (7)This-jframe, absolute
You can ".
At the same time, the event processing code is changed to the following code based on the variable name:
Jtextarea2.settext (converter. doconvert (jtextarea1.gettext ()));
Q: I found that the jigloo interface designer was not displayed when I disabled eclipse and opened the code just now. How can I open it for editing?
A: Sometimes eclipse cannot remember the editor used when a file was opened last time. Therefore, make sure that this class is not opened by other eclipse editors, right-click the file and choose "open with-> form Editor ". as shown in:
5. Download The jiglooswing source code used in this article.
After the file is downloaded, the project can be compiled by importing it to eclipse.
Jiglooswing.zip5 KB