搜档网
当前位置:搜档网 › java桌面应用程序开发

java桌面应用程序开发

java桌面应用程序开发
java桌面应用程序开发

Java for servers, personal computers and mobile devices is a great technology. As a result of the need to Java cross-platform features, so the Java on the server and the application of mobile device is a great success. But Java in the case of personal computer applications and on the server and the application of mobile devices is different, but it will soon change, at least, sooner than you think. In this article, I will analyze the Java application in the desktop environment will be how to get promoted, and specifically the Java GUI (graphical user interface) of the three main tools: the AWT and Swing, and SWT. In the following paragraphs, I will develop a complete Java desktop applications.

The Java and the desktop

Now, the popular desktop platform for Windows, Mac, and Linux. But they are not perfect, Windows dominated the desktop operating system market, its application and development has a huge population, but it is expensive and there are many security vulnerabilities. Linux has a solid foundation, it is open source software, more reliable than Windows. Macs is very easy to operate and not the target of the hacker, but compared with Windows and Linux, Mac hardware and software of the optional scope is very limited. Companies and individuals choose their operating system based on many factors. Less cost and high safety factor is preferred, this leads to some organizations from the Windows and choose Linux. For many users, availability and support for the original application is a very important factor, which means that the Windows will continue to enjoy the huge market. Mac has its own loyal users, which makes the Mac can still live, and the popularity of Linux on the desktop and the success of the Mac created diversity, this diversity is the Java need, this diversity makes Java on the desktop has a pivotal position.

Cross-platform support

Java running on all relevant operating systems, including Windows, Mac and Linux. For any organization, he wants to existing applications from one operating system transplant to another operating system without having to do too much change, so the Java it is their first choice of desktop development platform. May use visual tools of Microsoft, it is easy to https://www.sodocs.net/doc/c11780659.html, applications, but it will make you be binding on the Windows platform. Many people may want to use Linux instead of Windows at once to avoid problems caused by

a Microsoft operating system vulnerability. The user cannot tolerate is one of the problems when brought from Windows to Linux huge cost. If your application USES Java build, you don't have these problems, the Java graphical user interface will look like the operating system are you using, and does not need to do any changes. If one day have a desktop operating system appears, Java is a safe bet, because it is now able to run on Windows and Linux, then presumably it can run in the future may appear on the operating system of the operating system by Microsoft may sooner or later, or the open source community, or other people developed.

The characteristics of the rich

Initially, Java is only very limited some characteristics to build graphical user interface. Idea is to use the platform independent Java application program interface package different local graphical user interface of the operating system, called the abstract

window tool. Only common components such as file realm, the text area, checkbox, radio button, list box, and button supported by AWT, graphics and image features of support is very limited, that is to say, only enough to build simple applet program. Recognize the need for more advanced graphical user interface components and graphics capabilities, Sun has developed the Swing and Java 2 d, Java 3 d, input/output of images and Java (JAI) and many other senior images. Some form of these components are now part of the Java 2 standard edition (J2SE), and other extension must be packaged together with your application. Such as Swing, Java 2 d, input/output image is the core of the Java API, as the Java development kit (JDK) and the Java runtime environment. Let's not forget the J2EE platform. If you develop applications on the server and need rich graphical user interface, so there is no doubt that you should choose the Java. This allows you to move some code on the server to the client, and vice versa. For example: may begin a project is based on WEB and graphic interface, in some cases, the user may be required to graphic elements cannot be implemented in HTML, and if you do choose the Java client application, so you can reuse these originally used for the server-side code. If you use a remote call, some classes will actually Shared server and client. By the page server, Java desktop applications can also and other Java or Java application communications, such as CORBA, TCP/IP, and HTTP.

Java graphical interface tools

Java graphical interface has three main tools: the AWT and Swing and SWT. The Swing is to build the Java graphical interface standard API (application programming interface), and some AWT classes by Swing basis. SWT is a very promising new form tool, supported by IBM. But in fact, the three complement each other, they meet different needs.

AWT

Abstract window tool to define a simple applet programming, it is not suitable for building rich desktop graphical interface. But was introduced from the beginning, it has at least one good idea is layout management, it is responsible for find a place for the component location, this mechanism is necessary, because the GUI components in different operating systems have different size. Now, expanded the AWT component model and event handling mechanism (defined by the JavaBeans specification), a new graphics apis (called Java 2 d), support the clipboard and drag operation, printing, access, and the new GUI tool Swing, all of which belong to the Java foundation classes (JFC). Swing Swing is one of the most complex GUI ever developed. It has a set of complete components from button to file a domain to the table, the tree and file editor. These components is not dependent on the operating system of local parts, but with the original graphics like a straight line, rectangle, draw the text. This painting represents the sensory plug-in, it can imitate the local senses. The appearance of the Swing is platform independent called "Metal". The Swing structure was inspired by the MVC pattern, here on the screen visual GUI components and support data model objects, there is a clear separation between the GUI layer and the data communication between based on events. There are many mistakes in the first Swing version and execution problems, this slow down the speed of accept it. Swing the biggest problem is that be engaged in and many people believe that

it is prepared for the development of desktop applications. Today, there are many commercial products based on Swing development, including most of the Java integrated development tools, integrated development tool is Jbuilder, I like it very fast.

SWT

SWT is IBM for its Eclipse integrated development environment and the development of the graphical user interface tool. SWT can be used outside the Eclipse environment, and provide direct access to the operating system of the local graphical user interface. Therefore, based on SWT Java applications with the graphical user interface and can be local and other local applications and components are integrated together. If your desktop application to generate HTML report, you want to show it to the user. You can use a Swing to browse simple HTML document, but this is not an ideal solution. Is the best in your application to provide Internet explorer or Mozilla browser engine. SWT community now is designing the browser API, these API allows you to generate HTML based on IE or Mozilla window. SWT can now in AIX, HPUX, Linux, QNX, Solaris, and running under the Windows. Mac OS X is also in progress

Misunderstandings and Bug

For Java/Swing has been misunderstood, such as Java/Swing is too slow, or Java/Swing needs more memory. Swing may only 32 m in the old pentium CPU and memory to run JDK1.2 to run is very slow. But if in PIII level has 256 MB of memory, CPU running JDK1.

4 environment is fast enough. For an application of the mouse in 1 millisecond and reflect the difference in 10 milliseconds, looks for the user, makes no difference. Java in enterprise-class hundreds, thousands of people online at the same time server performance is very good. Java on the performance of the limited resources of mobile devices is also excellent. Why Java cannot become a good desktop application? In my point of view, the Swing bugs than its running speed is slow this problem is still serious. For example, if you are using JDK 1.2, you will not be able to enter in the form (called series) % & '($#! Q, etc. These characters. The eight characters and the arrow keys and the Home, End, Pgup and Pgdn and this several key key values are the same. One of the series made by the kind of call KeyEvent. GetCharCode () method to replace the KeyEvent. GetKeyCode (). This bug the JDK 1.3 has been corrected. You may have already given up Swing, if you Swing from using JDK 1.2, you may be because you can't enter q in the form and angry. Unfortunately you are need to use data to develop a Swing application, you will spend a lot of time to find a solution from the sun's bug database. But didn't find what you need (remember when the Swing is still a new thing), you will spend more time to go to the Swing in the development of the source code and work area, after the experience, few people are in another project in Swing again, your workspace will be like the following:

Import the Java. The awt. *;

Import the Java. The awt. Event. *;

The import javax.mail. Swing. *;

The import javax.mail. Swing. Table. *;

Public class WorkingTable extends this series

{

Public static final Boolean JDK12 = System. GetProperty (" Java. Version "). The startsWith (" 1.2 ");

Public void processKeyEvent KeyEvent (e)

{

If (JDK12)

{

Char ch = um participant etKeyChar ();

If (um participant etID () = = KeyEvent. KEY_TYPED && ((33 < = ch && ch < = 40) | | ch = = 'q'))

{

Int anchorRow = getSelectionModel (.) getAnchorSelectionIndex ();

Int anchorColumn = getColumnModel (.) getSelectionModel () getAnchorSelectionIndex ();

If (anchorRow! = 1 && anchorColumn! = 1)

{

If (! IsEditing ())

EditCellAt (anchorRow anchorColumn);

Component editorComp = getEditorComponent ();

If (isEditing () && editorComp instanceof JTextField)

{

JTextField textField = (JTextField) editorComp;

TextField. SetText (textField. GetText () + ch);

The return;

}

}

}

}

Super. ProcessKeyEvent (e);

}

}

Unfortunately, the Swing has a lot of problems as described above, some problems difficult to solve, need to do a lot of work. Swing open the file and save the file, for example, the dialog box is based on the component is called JfileChooser, it part of the

execution of the JDK 1.2 and JDK 1.3 (always can't use some features, to create a new directory is a challenge for most users). I don't know why the Sun will take several years until the jdk1.4 JfileChooser. Until JDK 1.4, you have two choices: use the tattered JfileChooser or create your own file selection box, Borland company in their JBuilder 4 do a very good file open dialog box. However, most of the developers using standard JfileChooser, give their users a lot of problems. One important thing need to pay attention to: can the to create a working environment as described above, because the Swing of the source code is available. Learn Java source code will also be able to make you a better programmer and let you understand the inner mechanism of work in the Java API. When you develop your own custom GUI components, it is useful.

Conclusion:

Java as a kind of network technology, in order to be able to run in the browser application and release, but it is from the beginning has the ability to run standalone desktop applications. Unfortunately, the AWT does not provide enough the features needed for the program on the desktop. Swing set out to solve these problems, but it has a lot of bugs. Today, Java has the ability to build large desktop client application and fix the bug. Java's unique advantage is "only write once, run anywhere" - in a Windows, Linux, Mac and other operating systems running on the Java code.

相关主题