具体生成工具如图:
(1)
(2)
(3)
(4)
源码 :
example.java
- 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;
-
-
-
-
-
-
- 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();
- 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);
- }
-
-
-
- public void actionPerformed(ActionEvent e) {
-
- if (e.getSource().equals(button1)) {
- jfc.setFileSelectionMode(1);
- int state = jfc.showOpenDialog(null);
- if (state == 1) {
- return;
- } else {
- File f = jfc.getSelectedFile();
- 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();
- 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相信大家都会用吧 不会用的话 可以去谷歌。
Swing实现文件选择(目录选择)附导出,布布扣,bubuko.com
Swing实现文件选择(目录选择)附导出
原文:http://www.cnblogs.com/Mr-Rocker/p/3755153.html