The following example shows two java files and one 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 when window is closed
Protected void processincluwevent (incluwevent e ){
Super. processreceivwevent (e );
If (e. getID () = javaswevent. 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. getdefatooltoolkit (). 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 to a directory, use the command line to enter this directory and execute javac-d. *. java, the class file will be compiled and then executed jar-cvfm te. jar manif. mf testjar, which is named te. jar, double-click it to see the effect!