⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demofilechooserdialog.java

📁 java绘图 java awt 经典绘图的例子,对于初学awt模块的人非常有帮助.
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package swing;import java.awt.Container;import java.awt.FlowLayout;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.filechooser.FileFilter;/** * * @author zhaolin */public class DemoFileChooserDialog extends JFrame{    private JFileChooser jfc;    public DemoFileChooserDialog(){        jfc = new JFileChooser();        jfc.setFileFilter(new FileFilter(){            @Override            public boolean accept(File f) {                if(f.isDirectory())                    return true;                if(f.getName().endsWith(".jpg")){                    return true;                }                return false;            }            @Override            public String getDescription() {                return "jpg";            }                    });        jfc.setAcceptAllFileFilterUsed(false);        Container c = this.getContentPane();        c.setLayout(new FlowLayout());        JButton open = new JButton("打开");        JButton save = new JButton("保存");        c.add(open );        c.add(save);                open.addActionListener(new ActionListener(){            public void actionPerformed(ActionEvent e) {                int status = jfc.showOpenDialog(DemoFileChooserDialog.this);                if(status == JFileChooser.APPROVE_OPTION){                    File file = jfc.getSelectedFile();                    System.out.println("Open file "+file.getName());                }            }                });        save.addActionListener(new ActionListener(){            public void actionPerformed(ActionEvent e) {                int status = jfc.showSaveDialog(DemoFileChooserDialog.this);                if(status == JFileChooser.APPROVE_OPTION){                    File file = jfc.getSelectedFile();                    System.out.println("Open file "+file.getName());                }            }                });        this.pack();        this.setVisible(true);    }        public static void main(String[] args) {        new DemoFileChooserDialog();    }        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -