標籤:style c class blog java tar
具體產生工具
(1)
(2)
(3)
(4)
源碼 :
example.java
[java] view plaincopyprint?
- package org.qiailin.jframe;
- import java.awt.Container;
- import java.awt.Point;
- import java.awt.Toolkit;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.File;
- import javax.swing.JButton;
- import javax.swing.JFileChooser;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JTabbedPane;
- import javax.swing.JTextField;
- /**
- * 因為看很多朋友在問試用臨時抽時間寫了個簡單的案例 源碼放上去,需要的可以看看,由於時間匆忙做得很粗糙 2011年1月4日23:22:31
- *
- * @author 漆艾林 QQ 172794299 郵箱 [email protected]
- *
- */
- public class Jexample implements ActionListener {
- JFrame frame = new JFrame("漆艾林-Example");// 架構布局
- JTabbedPane tabPane = new JTabbedPane();// 選項卡布局
- Container con = new Container();//
- JLabel label1 = new JLabel("檔案目錄");
- JLabel label2 = new JLabel("選擇檔案");
- JTextField text1 = new JTextField();// TextField 目錄的路徑
- JTextField text2 = new JTextField();// 檔案的路徑
- JButton button1 = new JButton("...");// 選擇
- JButton button2 = new JButton("...");// 選擇
- JFileChooser jfc = new JFileChooser();// 檔案選取器
- JButton button3 = new JButton("確定");//
-
- Jexample() {
- jfc.setCurrentDirectory(new File("d://"));// 檔案選取器的初始目錄定為d盤
-
- double lx = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
-
- double ly = Toolkit.getDefaultToolkit().getScreenSize().getHeight();
-
- frame.setLocation(new Point((int) (lx / 2) - 150, (int) (ly / 2) - 150));// 設定視窗出現位置
- frame.setSize(280, 200);// 設定視窗大小
- frame.setContentPane(tabPane);// 設定布局
- label1.setBounds(10, 10, 70, 20);
- text1.setBounds(75, 10, 120, 20);
- button1.setBounds(210, 10, 50, 20);
- label2.setBounds(10, 35, 70, 20);
- text2.setBounds(75, 35, 120, 20);
- button2.setBounds(210, 35, 50, 20);
- button3.setBounds(30, 60, 60, 20);
- button1.addActionListener(this); // 添加事件處理
- button2.addActionListener(this); // 添加事件處理
- button3.addActionListener(this); // 添加事件處理
- con.add(label1);
- con.add(text1);
- con.add(button1);
- con.add(label2);
- con.add(text2);
- con.add(button2);
- con.add(button3);
- frame.setVisible(true);// 視窗可見
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 使能關閉視窗,結束程式
- tabPane.add("1面板", con);// 添加布局1
- }
- /**
- * 時間監聽的方法
- */
- public void actionPerformed(ActionEvent e) {
- // TODO Auto-generated method stub
- if (e.getSource().equals(button1)) {// 判斷觸發方法的按鈕是哪個
- jfc.setFileSelectionMode(1);// 設定只能選擇到檔案夾
- int state = jfc.showOpenDialog(null);// 此句是開啟檔案選取器介面的觸發語句
- if (state == 1) {
- return;
- } else {
- File f = jfc.getSelectedFile();// f為選擇到的目錄
- text1.setText(f.getAbsolutePath());
- }
- }
- // 綁定到選擇檔案,先擇檔案事件
- if (e.getSource().equals(button2)) {
- jfc.setFileSelectionMode(0);// 設定只能選擇到檔案
- int state = jfc.showOpenDialog(null);// 此句是開啟檔案選取器介面的觸發語句
- if (state == 1) {
- return;// 撤銷則返回
- } else {
- File f = jfc.getSelectedFile();// f為選擇到的檔案
- text2.setText(f.getAbsolutePath());
- }
- }
- if (e.getSource().equals(button3)) {
- // 彈出對話方塊可以改變裡面的參數具體得靠大家自己去看,時間很短
- JOptionPane.showMessageDialog(null, "彈出對話方塊的執行個體,歡迎您-漆艾琳!", "提示", 2);
- }
- }
- public static void main(String[] args) {
- new Jexample();
- }
- }
這一步注意選擇main方法的類
簡單的匯出就OK了,打包可以用ant 以及maven ,當然這裡就不介紹了 有興趣的可以去看看
有興趣的可以去下載
當然如果還有朋友想讓你的jar檔案脫離Java的壞境,可以產生exe的檔案在這裡可以使用exe4j
當然這裡exe4j相信大家都會用吧 不會用的話 可以去Google。