Window
Here's an example that includes 2 Java files and a mf file:
File 1:frame1.java
Package Testjar;
Import java.awt.*;
Import java.awt.event.*;
Import javax.swing.*;
public class Frame1 extends JFrame {
JPanel ContentPane;
BorderLayout borderLayout1 = new BorderLayout ();
Construct the Frame
Public Frame1 () {
EnableEvents (Awtevent.window_event_mask);
try {
Jbinit ();
}
catch (Exception e) {
E.printstacktrace ();
}
}
Component initialization
private void Jbinit () throws Exception {
ContentPane = (JPanel) this.getcontentpane ();
Contentpane.setlayout (BORDERLAYOUT1);
This.setsize (New Dimension (400, 300));
This.settitle ("Frame Title");
}
Overridden so we can exit as window is closed
protected void processWindowEvent (WindowEvent e) {
Super.processwindowevent (e);
if (e.getid () = = windowevent.window_closing) {
System.exit (0);
}
}
}
File 2:app.java
Package Testjar;
Import Javax.swing.UIManager;
Import java.awt.*;
public class App {
Boolean packframe = false;
Construct the application
Public App () {
Frame1 frame = new Frame1 ();
Validate frames that have preset sizes
Pack frames that have useful preferred size info, e.g. from their layout
if (packframe) {
Frame.pack ();
}
else {
Frame.validate ();
}
Center the window
Dimension screensize = Toolkit.getdefaulttoolkit (). Getscreensize ();
Dimension framesize = Frame.getsize ();
if (Framesize.height > Screensize.height) {
Framesize.height = Screensize.height;
}
if (Framesize.width > Screensize.width) {
Framesize.width = Screensize.width;
}
Frame.setlocation ((screensize.width-framesize.width)/2, (Screensize.height-framesize.height)/2);
Frame.setvisible (TRUE);
}
Main method
public static void Main (string[] args) {
try {
Uimanager.setlookandfeel (Uimanager.getsystemlookandfeelclassname ());
}
catch (Exception e) {
E.printstacktrace ();
}
New App ();
}
}
File 3:MANIF.MF
Main-class:testjar. App
Copy the above three files into a directory and use the command line to enter the directory and execute javac-d. *.java, this time will be compiled to generate class files, and then execute JAR-CVFM te.jar manif.mf Testjar, should be turned into a jar file named Te.jar, double-click it, you can see the effect!