[Original] Building a desktop application prototype (first part)
Author: Andrei Cioroianu Translation: ODT original: http: //www.onjava.com/pub/a/onjava/2004/04/28/desktop.html
When you read this article, you may decide to design desktop applications with Java. If you don't have this determination, then you can read my previous article, and I talk about some of the advantages provided in Java in the client. In this article, I will start to describe the prototype of a desktop app, I call it Jimageing. I intend to focus on the framework of the application, explain how I do technical decisions and how I solve problems in the development process. If you are a newbie developed by the Java desktop, then you should start from reading the Java Tutorial. You can also find articles you interested in the Swing Connection.
Why build a prototype?
The development of many applications is due to several reasons from one prototype. The first one in these reasons is that you must determine that the existing technology can meet the needs of users. For example, Windows integration cannot be implemented without having to use a local code, which leads to a loss of some Java cross-platform advantages. SWT provides an integration that is restricted and operating system, which allows you to run the same application on many local platforms. In many cases, the J2SE platform provides you need to build a rich performance of complex desktop applications. Before building large Java desktop projects, you should always build a prototype to see if J2SE meets the application needs. On the other hand, you have proved that your idea can be implemented and your technical decision is correct, and a prototype can get feedback from the user as soon as possible during the development process. The prototype can also help you estimate the time and resources you need to complete your project. Spend a lot of work to build a user interface with a menu, dialog, drag characteristic, cutting version support, recovery management, printing, etc. Before starting these work, you should know how difficult it is to build an application core function. If you have to use a third party to customize the component, you should test them to see if you can work with your prototype. If you have to resolve extended and performance issues, you should find solutions through prototype status.
User needs
The Jimageing prototype is a desktop application that allows you to comment for a photo. Email may be the most popular "collaborative tool", but you can improve your comment on the screenshot by image tool, which allows you to draw, painted rectangles, ellipse and write comment information on the picture. If Jimageing users use more than one operating system, such an application Java is a natural choice. When Windows dominate the desktop market, there are some users to choose Mac or Linux. For example, when the Java developer cooperates with a project over the Internet, it is a possibility that they can do not have to use the same operating system. This user interface is very simple, which includes a toolbar and a picture area. It is enough for test applications. The figure below shows the appearance of this interface:
Package and class
The figure below shows the prototype code structure. The top-level package of the application contains only the main class, and this class will be described in detail later. I will describe other classes that may be used in the future article. Frames encapsulates the main PANEL describing the application main framework, based on JDESKTOPPANE, and JinternalFrame text comment class. These three classes are named Mainframe, Mainpanel, and Noteframe. The PAINT package organizes the PaintView component and its data model (named PaintModel), and the Toolbarbuilder class, this class creates the toolbar of the application. Tools package with tool classes drawing image objects. The ResourcesUpport class in the Resources package is a tool class that handles toolbarresources.properties resources and icons from your images directory. The main class
This class implements the application's main method and all classes, resource packages into a JAR file, this JAR file is named JImageing.jar. Package with the following command:
Jar cfm jimaging.jar M.TXT COM
The COM directory contains classes in the package, .properties resource, and .gif icon. The M.TXT file is used with main-class: com.devsphere.Articles.Desktop.main briefly describes the main classes of the application. The JAR tool copy M.TXT file to the Meta-INF / MANIFEST.MF file that is automatically created in jimageing.jar. Below is the main statement description of Main:
package com.devsphere.articles.desktop; import com.devsphere.articles.desktop.frames.MainFrame; import com.devsphere.articles.desktop.frames.MainPanel; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; import java.io.IOException; import java. Util.logging.logger;
Main () method calls the main () constructor, set the appearance, create the main window and display it:
public class Main {private String args []; private MainFrame mainFrame; private MainPanel mainPanel; private Main (String args []) {this.args = args;} public static void main (String args []) {Main main = new Main (args); main.setsystemlookandfeel (); main.createframe (); main.showframe ();} ...}
The command line can contain one or two parameters. Users can specify a picture resource path as the first parameter. Application loads and displays images, allowing users to comment it. If the second parameter exists, the application saves an annotated picture to the file path given by this parameter. Run the app, the following command line launches:
Java -jar Jimaging.jar SourceImage AnnotatedImageJ2SE can load GIF, JPEG, and PNG files, but it only saves images in JPEG and PNG formats. You can save your comments without the GIF format.
The following describes the method in the main class. (Continued)