Double-click the jar file in Windows to run the statement.

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.