java swt 文件选择,java swt选择文件对话框

package com.fh.zhuanhuan;

import java.awt.FlowLayout;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.File;

import java.io.FileReader;

import javax.swing.Box; import javax.swing.JButton;

import javax.swing.JFileChooser; import javax.swing.JFrame;

import javax.swing.JOptionPane; import javax.swing.JPanel;

import com.fh.readfile.FileRead;

public class ZhuanHuanMain extends JFrame { /** * @param args * @author 王辉 */ private JButton bt,bt2; private Box box; private JFileChooser jc; private String filepath=\ public ZhuanHuanMain(){ this.setTitle(\经纬度转换小程序\ this.setLayout(new FlowLayout()); box=Box.createVerticalBox(); // bt2=new JButton(\选择文件名称\ box.add(bt2); bt=new JButton(\转换\ box.add(bt); bt.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) {

// // // // // // // // // // //开始转化 if(filepath==null||filepath.equals(\ show(\没有选择文件\ }else{ new FileRead().readerfile(filepath); } } }); bt2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { jc=new JFileChooser(); jc.showSaveDialog(null); if(jc.getSelectedFile()!=null){ filepath=jc.getSelectedFile().getAbsolutePath(); bt2.setText(\文件名称:\ }else{ show(\没有选择文件\ } } }); this.add(box); this.setResizable(false); this.setVisible(true); this.setSize(400, 120); }

public static void main(String[] args) { // TODO Auto-generated method stub File file=new File(\ try { FileReader fr=new FileReader(file); BufferedReader br=new BufferedReader(fr); String filepath=br.readLine(); System.out.println(filepath); new FileRead().readerfile(filepath); } catch (Exception e) { e.printStackTrace(); } new ZhuanHuanMain(); }

public static void show(String msg){ JOptionPane.showMessageDialog(null,msg);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值