点击(此处)折叠或打开
- // 给按钮添加1个事件
- bu.addActionListener(new ActionListener() {
-
- public void actionPerformed(ActionEvent e) {
- String msg;
- fDialog = new JFileChooser("./");//设默认打开路径为当前路径
- FileNameExtensionFilter filter = new FileNameExtensionFilter(
- "JPG & GIF Images", "jpg", "gif");
- fDialog.setFileFilter(filter);
- int result=fDialog.showOpenDialog(null);
- if(result==JFileChooser.APPROVE_OPTION){
- // path = fDialog.getSelectedFile().getAbsolutePath().replace('\', '/');
- // System.out.println(path);
- // Image image2 = new ImageIcon("path").getImage();
- // 获取打开的图片
- File file = fDialog.getSelectedFile();
- ImageIcon img =new ImageIcon(file.getPath());
- jl2.setIcon(img); //jl2是一个JLabel
- msg="成功打开图像";
- }else {
- msg="取消打开图像";
- }
- JOptionPane.showMessageDialog(frame,msg); //提示框
- }
- });
相关热门文章
给主人留下些什么吧!~~
评论热议