FileDialog的一个疑问 打开一个保存文件的FileDialog,怎么判断鼠标点击的是保存还是取消? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 建议你使用JFileChooser类更方便简单 如果点击的是cancel,那么getFile()方法返回类型就是null你可以更具这一点来识别 import java.io.*; import java.awt.*; public class FileDialog1{ String path; Frame f = new Frame("test for filedialog"); public FileDialog1(){ FileDialog file = new FileDialog(f,"new",1); file.setVisible(true); path = file.getDirectory() + file.getFile(); System.out.println(path); try{ FileInputStream fin = new FileInputStream("d:/100x30_Logo.gif"); FileOutputStream fout = new FileOutputStream(path); int c; while((c=fin.read())!=-1){ fout.write(c); } fin.close(); fout.close(); }catch(FileNotFoundException e){ System.out.println("File Copy1:" + e); }catch(IOException e){ System.out.println("File Copy2:" + e); } } public static void main(String args[]){ new FileDialog1(); } } 那些东西不用判断的,你用JFileChooser,就不用这么判断。jfc2.setDialogTitle("还原数据库"); int returnVal=jfc2.showOpenDialog(LoginSys.mymain); if(returnVal==jfc2.APPROVE_OPTION){ int s=JOptionPane.showConfirmDialog(LoginSys.mymain, "你确实要还原数据库么?", "系统提示", JOptionPane.YES_NO_CANCEL_OPTION); if(s==JOptionPane.YES_OPTION){ String s1=jfc2.getSelectedFile().getPath(); BckResData.ResData(s1); }else if(s==JOptionPane.NO_OPTION){ return; }else if(s==JOptionPane.CANCEL_OPTION){ return; } } 我现在对GUI应该说是比较熟吧,以前参与开发过两个基于J2SE的项目 虽然JFileChooser可以不用那么判断,但在性能方面,我觉得还是用FileDialog好,JFileChooser对中文支持不够好,很难看,速度慢,但FileDialog就克服了这个问题 应用程序打包后读取当前目录下的配置文件问题 请问一下各位有谁碰见过这样的奇怪问题? 在线等,关于MD5加密中文不一致问题 jsp页面中调用applet的问题 一个程序问题 这个算法怎么做? 如何在一中文字符串得到第一汉字的拼音首字母.如何成为服务器? 请看看这个程序,我有疑惑 哪里有VisualAge下载。。 【一道面试题】新手求教 myeclipse6.0和eclipse3.2无法并存吗?? 窗口重绘的问题,急
更方便简单
你可以更具这一点来识别
import java.awt.*;
public class FileDialog1{
String path;
Frame f = new Frame("test for filedialog");
public FileDialog1(){
FileDialog file = new FileDialog(f,"new",1);
file.setVisible(true);
path = file.getDirectory() + file.getFile();
System.out.println(path);
try{
FileInputStream fin = new FileInputStream("d:/100x30_Logo.gif");
FileOutputStream fout = new FileOutputStream(path);
int c;
while((c=fin.read())!=-1){
fout.write(c);
}
fin.close();
fout.close();
}catch(FileNotFoundException e){
System.out.println("File Copy1:" + e);
}catch(IOException e){
System.out.println("File Copy2:" + e);
}
}
public static void main(String args[]){
new FileDialog1();
}
}
int returnVal=jfc2.showOpenDialog(LoginSys.mymain);
if(returnVal==jfc2.APPROVE_OPTION){
int s=JOptionPane.showConfirmDialog(LoginSys.mymain, "你确实要还原数据库么?", "系统提示", JOptionPane.YES_NO_CANCEL_OPTION);
if(s==JOptionPane.YES_OPTION){
String s1=jfc2.getSelectedFile().getPath();
BckResData.ResData(s1);
}else if(s==JOptionPane.NO_OPTION){
return;
}else if(s==JOptionPane.CANCEL_OPTION){
return;
}
}