《JAVA程序设计》实训第二天——《猜猜看》游戏
2015-07-06 12:29
453 查看
课程实训第二天,我问同学参考同学的代码,如何导入显示图片。
public class laichangqing extends JFrame { /** * */ private static final long serialVersionUID = 1L; private JPanel contentPane; private JTextField tfDir; private JTextField tfClass; File[] fileArray; // 文件夹下所有文件 int NUM_IMG = 0; // 文件总数目 int index = 0; // 当前文件的序号 int i = 0; JLabel jlbImg1 = null; JLabel jlbImg2 = null; JLabel jlbImg3 = null; private Graphics g; /** * Launch the application. */ class myFileFilter implements FileFilter { @Override public boolean accept(File pathname) { String filename = pathname.getName().toLowerCase(); if (filename.contains(".jpg")) { return false; } else { return true; } } } public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { laichangqing frame = new laichangqing(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public laichangqing() { setTitle("\u731C\u731C\u770B\u6E38\u620FV0.1"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 645, 500); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); // 选择目录 按钮的处理程序 JButton btnDir = new JButton("\u9009\u62E9\u76EE\u5F55"); btnDir.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFileChooser jfc = new JFileChooser(); jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); jfc.showDialog(new JLabel(), "选择"); File file = jfc.getSelectedFile(); tfDir.setText(file.getAbsolutePath()); if (file != null && file.isDirectory()) { // 参考: java中File.listFiles(FileFilter) FileFilter的使用 // http://zhouzaibao.iteye.com/blog/347557 ; // 获取文件夹下所有的文件 fileArray = file.listFiles(); NUM_IMG = fileArray.length; } } }); btnDir.setBounds(26, 26, 93, 23); contentPane.add(btnDir);在借鉴同学的代码下加以修改
相关文章推荐
- eclipse错误 Exception raised during rendering:java.lang.System.arraycopy([CI[CII)V
- 下载文档--Struts2中国的文件下载被显示为空间的问题
- eclipse错误 timeout
- [LeetCode][Java] String to Integer (atoi)
- Spring MVC 之Transaction rollback
- 用Java实现AES加密
- EJB到底为何物?
- Java Web验证码
- 关于java final,并非不可更改值
- Power of Two LeetCode Java
- eclipse错误 The connection to adb is down,
- Java中图片压缩处理
- struts2的体系结构
- struts 数据验证
- 《JAVA程序设计》实训第一天——《猜猜看》游戏
- Spring学习(5)---Bean的定义及作用域的注解实现
- Java处理音频波形相关
- Java正则表达式
- Ubuntu14.10 Eclipse菜单栏消失不见
- Spring学习笔记IOC与AOP实例