Instances of GCJ SWT under Windows
GCJ can compile the Java program into the local code. The EXE file after compiling is no longer required to run directly, and the program running speed after compiling cost is improved. The disadvantage is that the generated file is large, I tried a Hello World to have more than two megabytes, using WinRAR compressed for more than 600 K.
Installation and configuration
Download mingw. (http://sourceforge.net/projects/mingw)
Website: http://sourceforge.net/project/showfiles.php? Group_id = 2435
Need to download the following files:
MINGW-2.0.0-3.exe (GNU environment under Windows)
MSYS-1.0.8.EXE (a simulated * NIX support shell, etc.)
GCJ-3.2-20021210-1.tar.gz (protagonist GCJ Compile Java is a local code)
2. Install the file
Install MINGW-2.0.0-3.exe in turn, MSYS-1.0.8.exe
There is a prompt to enter the path of MINGW when installing MSYS.
Unzip GCJ-3.2-20021210-1.tar.gz copies the files inside to MINGW, pay attention to the corresponding folder, such as GCJ / BIN, to place the corresponding mingw / bin below.
3. Set the windows's path to add the mingw / bin to the system's path, which is convenient to run GCJ.
Then enter gcj -v in the command line :)
Hellogcj.exe
For convenience, let's build a GCJWORK folder first.
Create a normal Java source file in GCJWORK, Hellogcj.java
Public class hellogcj {
Public static void main (String [] args) {
System.out.println ("Hello GCJ!");
}
}
Under the catalog, a text file Makefile should not be extended.
Target = hellogcj
GCJ = GCJ
All: $ (Target)
$ (Target): $ (Target) .o
$ (Gcj) --main = $ (target) -o $ (target) .o
$ (Target) .o: $ (target) .java
$ (GCJ) -C $ (Target) .java -o $ (target) .o
.Phony: Clean
Clean:
Rm -rf * .o $ (Target)
Then let us open MSYS to use the CD to enter the GCJWORK we create, type make
After that, you can generate a hellogcj.exe, run him, which is a program that is not written with Java with a virtual machine. :)
Compare
Why do you want to code Java in a cost code?
Execution speed is a very important feature that let us do a simpler contrast.
Or the above case hellogcj, we compile to Java's BYTECODE
Note that GCJ can also compile Bytecode,
Use the gcj -c hellogcj.java command.
Then compare two programs, you can obviously feel the hellogcj.class on my machine.
Hellogcj.exe outputs the text directly.
Let's take SWT
I have used Eclipse to know SWT, SWT is the IBM graphical interface development package, because its implementation is related to localization, so there are many controversy, and the public is known to be reasonable, we don't say anything, Directly say how to use it, after all, it is good, it is very bad, you will know! ready
1. SWT.jat (SWT Java package, compiling java)
2. SWT's Windows version corresponds to the DLL (my file name is SWT-WIN32-2133.DLL)
The above two files can download the latest SWT toolkit in Eclipse
Http://download2.eclipse.org/downloads/drops/r-2.1-200303272130/swt-2.1-win32.zip
3. Libswt.a file used to compile EXE (I generated one, download here)
http://www.elvala.com/download/java/libswt.rar
begin
What we use is an example of Eclipse, the source code is as follows:
Import org.eclipse.swt. *;
Import org.eclipse.swt.widgets. *;
Import org.eclipse.swt.layout. *;
Import org.eclipse.swt.events. *;
Import org.eclipse.swt.graphics. *;
Public class complexgridlayoutexample {
Static Display Display;
STATIC shell shell;
Static text Dogname;
STATIC Combo Dogbreed;
Static Canvas DogPhoto;
Static Image Dogimage;
Static List Categories;
Static text Ownername;
Static Text Ownerphone;
Public static void main (String [] args) {
Display = new display ();
Shell = new shell (display);
Shell.Settext ("Dog Show Entry");
GridLayout GridLayout = New GridLayout ();
GridLayout.NumColumns = 3;
Shell.setLayout (GridLayout);
New label (shell, swt.none) .SETTEXT ("Dog's Name:");
Dogname = new text (shell, swt.single | swt.border);
GridData griddata = new griddata (griddata.horizontal_align_fill);
GridData.horizontalspan = 2;
Dogname.setLayOutdata (Griddata);
New label (shell, swt.none) .SETTEXT ("BREED:");
Dogbreed = New Combo (Shell, SWT.NONE);
Dogbreed.SetItems (New String [] {"Collie", "Pitbull", "Poodle", "Scottie"};
Dogbreed.setLayOutdata (New Griddata); label label = new label (shell, swt.none);
Label.setText ("categories");
Label.setLayOutdata (New GridData);
New label (shell, swt.none) .SETTEXT ("Photo:");
DogPhoto = New Canvas (Shell, Swt.Border);
Griddata = new griddata (griddata.fill_both);
Griddata.widthhint = 80;
GridData.heighthint = 80;
GridData.VerticalSpan = 3;
DogPhoto.setLayOutdata (Griddata);
Dogphoto.addpaintlistener (new pointlistener () {
Public void PaintControl (Final Paintevent Event) {
IF (DogImage! = null) {
Event.gc.drawImage (Dogimage, 0, 0);
}
}
});
Categories = new list (shell, swt.multi | swt.border | swt.v_scroll);
Categories.SetItems (New String "(NEW"
"Best of Breed", "Prettyst Male", "Handsomest Male",
"Best Dressed", "Fluffiest Ears", "MOST Colors",
"BEST Performer", "Loudest Bark", "Best Behaved",
"Prettiest eyes", "MOST Hair", "Longeest Tail",
"Cutest trick"});
Griddata = new griddata (griddata.horizontal_align_fill | griddata.vertage_align_fill);
GridData.VerticalSpan = 4;
INT LISTHEIGHT = Categories.getItemHeight () * 12;
Rectangle Trim = Categories.Computetrim (0, 0, 0, ListHeight);
Griddata.heighthint = trim.height;
Categories.setLayOutdata (Griddata);
Button Browse = New Button (Shell, Swt.push);
Browse.Settext ("Browse ...");
Griddata = new griddata (griddata.horizontal_align_fill);
Griddata.horizontalindent = 5;
Browse.setLayOutdata (Griddata);
browse.addselectionListener (New SelectionAdapter () {
Public void widgetSelected (SelectionEvent Event) {string filename = new filedialog (shell) .Open ();
IF (filename! = NULL) {
Dogimage = New Image (Display, FileName);
}
}
});
Button Delete = New Button (shell, swt.push);
Delete.setText ("delete");
Griddata = new griddata (griddata.horizontal_align_fill | griddata.vertage_align_beginning);
Griddata.horizontalindent = 5;
Delete.setLayOutdata (GridData);
delete.addseelectrionListener (New SelectionAdapter () {
Public void widgetSelected (SelectionEvent Event) {
IF (DogImage! = null) {
Dogimage.dispose ();
Dogimage = NULL;
DogPhoto.redraw ();
}
}
});
Group ownerinfo = new group (shell, swt.none);
Ownerinfo.setText ("Owner Info");
GridLayout = new gridlayout ();
GridLayout.NumColumns = 2;
Ownerinfo.setLayout (GridLayout);
Griddata = new griddata (griddata.horizontal_align_fill);
GridData.horizontalspan = 2;
Ownerinfo.setLayOutdata (Griddata);
New label (OwnerInfo, SWT.NONE) .SETTEXT ("Name:");
Ownername = new text (OwnerInfo, SWT.SINGLE | SWT.BORDER);
Ownername.setLayOutdata (New GridData (GridData.Fill_horizontal);
New Label (OwnerInfo, SWT.NONE) .SETTEXT ("Phone:");
Ownerphone = new text (OwnerInfo, SWT.SINGLE | SWT.BORDER);
Ownerphone.setLayOutdata (New GridData (GridData.Fill_horizontal);
Button Enter = New Button (Shell, SWT.PUSH);
ENTER.SETTEXT ("ENTER");
Griddata = new griddata (griddata.horizontal_align_end);
Griddata.horizontalspan = 3;
Enter.setLayOutdata (Griddata);
Enter.addSelectionListener (New SelectionAdapter () {
Public void widgetSelected (SelectionEvent Event) {
System.out.println ("/ NDOG NAME:" DOGNAME.GETTEXT ());
System.out.println ("Dog Breed:" Dogbreed.getText ()); System.out.Println ("Owner Name:" OwnerName.getText ());
System.out.println ("Owner Phone:" OwnerPhone.getText ());
System.out.println ("Categories:");
String cats [] = categories.getSelection ();
For (int i = 0; i System.out.println ("/ t" cats [i]); } } }); Shell.pack (); shell.open (); While (! shell.isdisposed ()) { IF (! Display.readDispatch ()) Display.sleep (); } IF (DogImage! = null) { Dogimage.dispose (); } } } Document is ComplexGridLayOutexample.java Corresponding Makefile file Target = complexgridlayoutexample GCJ = GCJ Jflags = - classpath =. / Swt.jar Lflags = -l. -Lswt All: $ (Target) $ (Target): $ (Target) .o $ (Gcj) --main = $ (target) -o $ (target) .o $ (LFLAGS) $ (Target) .o: $ (target) .java $ (GCJ) $ (JFLAGS) -C $ (Target) .java -o $ (target) .o .Phony: Clean Clean: Rm -rf * .o $ (Target) The above two files and swt.jar, libswt.a, SWT-WIN32-2133.DLL are put together, About path problem attention Jflags = - classpath =. / Swt.jar Lflags = -l. -Lswt Among them, Jflags should correspond to SWT.jar Lflags should correspond to libswt.a Then make! Run the generated complexgridlayoutexample.exe see it? Run this procedure later as long as SWT-Win32-2133.dll is. The entire EXE is about 5 trillings, it seems to be frustrated, too big, but this thing is indeed very wonderful. It is said that C # Editor: SharpStudio will use SWT to make! SWT encapsulates a lot of features, you will find that write applications will be much more convenient than using swings. Download Download Compilation Equation with ComplexGridLayoutExample.exe http://www.elvala.com/download/java/gcj.rar