windows中双击jar文件即可运行写法_JSP技巧_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

windows中双击jar文件即可运行写法

作者:黑客防线网安JSP教程基地 来源:黑客防线网安JSP教程基地 浏览次数:0

本篇关键词:运行即可文件 
黑客防线网安网讯:  下面通过一个例子来说明,这个例子包括2个java文件和一个mf文件:  文件1:Frame1.java  package testjar;  import java.awt.*;  import java.awt.event.*;  import javax.swi...

  下面通过一个例子来说明这个例子包括2个java文件和一个mf文件:

  文件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 processWindowEvent(WindowEvent e) {
      super.processWindowEvent(e);
      if (e.getID() == WindowEvent.WINDOW_CLOSING) {
        System.exit(0);
      }
    }
  }

  文件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();
    }
  }

  文件3:manif.mf

  Main-Class: testjar.App

  复制上述的三个文件到一个目录中用命令行进入这个目录并执行 javac -d . *.java,此时会编译生成class文件,然后执行 jar -cvfm te.jar manif.mf  testjar,应该回生成一个名为te.jar的jar文件,双击它,就可以看到效果了!

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-16409-1.html
网站维护教程更新时间:2012-04-07 00:21:34  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer