文档详情

图片浏览器代码.doc

发布:2017-03-23约6.35千字共5页下载文档
文本预览下载声明
//picture explorer 作者:武镖 2012/7/20 import java.awt.*; import javax.swing.*; import java.io.*; import java.awt.event.*; public class PictureExplorer extends JFrame implements ActionListener { private JLabel imagelabel; private JPanel panel; private int i=0;String filename; File file; private ImageIcon image; private JButton startbutton,stopbutton,previousbutton,nextbutton; private JMenuBar menubar; private JMenu menu; private JMenuItem menuitemopen,menuitemexit; private JFileChooser chooser; public PictureExplorer(){ imagelabel=new JLabel(); panel=new JPanel(); image=new ImageIcon(); startbutton=new JButton(放大); stopbutton=new JButton(缩小); previousbutton=new JButton(上一张); nextbutton=new JButton(下一张); menubar=new JMenuBar(); menu=new JMenu(文件); menuitemopen=new JMenuItem(打开文件); menuitemexit=new JMenuItem(退出); chooser=new JFileChooser(); } public void launchPictureExplorerTest(){ Container c=getContentPane(); startbutton.addActionListener(this); stopbutton.addActionListener(this); previousbutton.addActionListener(this); nextbutton.addActionListener(this); menuitemopen.addActionListener(this); menuitemexit.addActionListener(this); menubar.add(menu); menu.add(menuitemopen); menu.add(menuitemexit); imagelabel.setIcon(image); imagelabel.setHorizontalAlignment(SwingConstants.CENTER); c.add(imagelabel,Center); panel.add(previousbutton); panel.add(nextbutton); panel.add(startbutton); panel.add(stopbutton); c.add(panel,South); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); chooser.setCurrentDirectory(new File(.)); //设置文件选择器当前目录 chooser.setFileFilter(new javax.swing.filechooser.FileFilter() { public boolean accept(File file) { //可接受的文件类型 String name = file.getName().toLowerCase(); //获取文件名 return name.endsWith(.gif) || name.endsWith(.jpg) || name.endsWith(.jpeg) || file.isDirectory(); } public String getDescription() { return 图像文件; } }); setJMenuBar(
显示全部
相似文档