《Java程序设计》第16周周四:GUI编程及文件对话框的使用(项目1)
2015-06-25 10:39
405 查看
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; public class FileChooser extends JFrame implements ActionListener{ JButton open=null; public static void main(String[] args) { new FileChooser(); } public FileChooser(){ open=new JButton("open"); this.add(open); this.setBounds(400, 200, 100, 100); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); open.addActionListener(this); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub JFileChooser jfc=new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES ); jfc.showDialog(new JLabel(), "选择"); File file=jfc.getSelectedFile(); if(file.isDirectory()){ System.out.println("文件夹:"+file.getAbsolutePath()); }else if(file.isFile()){ System.out.println("文件:"+file.getAbsolutePath()); } System.out.println(jfc.getSelectedFile().getName()); } }
相关文章推荐
- UICollectionView
- 第16周周四:GUI编程及文件对话框的使用 项目一:文件及选择
- 第14周实验作业:GUI编程初步
- 《Java程序设计》第14周实验作业:GUI编程初步
- 【easyui开发中整理的笔记】
- UEditor自定义工具栏图标
- iOS 动画Animation详解, UIView动画(UIView属性动画,UIViewTransition动画,UIView Block动画),CALayer动画(CABasicAnima...)
- How to pass string parameters to an TADOQuery?
- 《Java程序设计》第16周周四:GUI编程及文件对话框的使用 项目1
- Epcon Chempro Engineering Suite v6.31-ISO 1CD(包括CHEMPRO 6.31, SINET 6.11,APITech Database v3.0,
- 第14周实验作业:GUI编程初步
- UIPageControl自定义点的颜色,图片
- 经wsgi保证后的request的environ属性
- UIView的frame,bounds,tramsform的简单使用
- NSdata 与 NSString,Byte数组,UIImage 的相互转换-
- spark官方文档之——Spark programming guide spark编程指南
- True bar
- GUI编程及文件对话框的使用
- SortedDictionary<TKey, TValue> 类 表示根据键进行排序的键/值对的集合。
- 第十六周周四GUI编程及文件及选择