Double-click the jar file in Windows to run the spelling

Source: Internet
Author: User
Tags exit command line pack window
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!



Related Article

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.