舞台系统 后台图片改变但是 前台出现图片不正确问题以及解决方法

 

public class ImageDialog extends JDialog implements ActionListener,
        MouseListener {

    private MainFrame mainFrame;
    private QuestionPanel questionPanel;
    ImageIcon icon, icon2, icon3;
    JLabel lab, lab2, lab3;
    JButton bt;
    JScrollPane scroll;

    private boolean isMaxSize = false;

    public ImageDialog(MainFrame mainFrame, QuestionPanel questionPanel,
            String path) {

        super(mainFrame, "双击图片最大化" + "", true);
        // path = path.substring(0, path.indexOf("&&time"));
        this.validate();
        this.repaint();
        this.mainFrame = mainFrame;
        this.questionPanel = questionPanel;
        this.setSize(600, 500);
        this.setLayout(new BorderLayout());
        this.setLocation(450, 200);
        // 默认不可见;

        // Image myImage = Toolkit.getDefaultToolkit().getImage(path);
        // new DynLabelThread(myImage);

        File file = new File(path);

        int index = path.lastIndexOf("\\");
        String picName = path.substring(index + 1);
        if (file.exists()) {
            // icon = new ImageIcon(file.getPath());
            icon = new ImageIcon();
            Image image = null;
            try {
                FileInputStream fis = new FileInputStream(file);
                image = ImageIO.read(fis);
                fis.close();
                icon.setImage(image);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            System.out.println(",,,,,,,,,,,,,,,,,,,,,,,,,," + file.getPath());
 
        } else {
            // id_a.jpg 不存在;
            File dir = new File(PropertyUtil.getLocalValue("PIC_PATH"));

            File[] list = dir.listFiles();
            if (list != null && list.length > 0) {
                for (int i = 0; i < list.length; i++) {
                    File f = list[i];
                    String name = f.getName();
                    String subStr = name.substring(name.indexOf("____") + 4);
                    System.out.println(subStr);
                    System.out.println("----------***********-------picname="
                            + picName + "sbstr=" + subStr);
                    if (picName.equals(subStr)) {
                        // f.delete();
                        file = f;
                        break;
                    }
                }
            }
            ImageIcon icon;

            icon = new ImageIcon(file.getPath());
            icon.getImage().flush();
            icon = new ImageIcon(file.getPath());
这里 解决了后台图片改变但是 前台出现图片不正确的问题 ;
    
        }

        lab = new JLabel(icon);

        lab.setBounds(300, 500, 800, 800);
        scroll = new JScrollPane(lab, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

        bt = new JButton("确定");
        bt.addActionListener(this);

        lab.addMouseListener(this);
        // this.add(scroll, BorderLayout.NORTH);
        this.add(scroll, BorderLayout.CENTER);
        this.add(bt, BorderLayout.SOUTH);
        // this.add(bt, BorderLayout.SOUTH);
        // this.setIconImage(myImage);
        this.setVisible(true);

    }

 
    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub

        if (e.getSource() == this.bt) {
            this.dispose();
        }
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        // TODO Auto-generated method stub
        if (e.getClickCount() == 2 && e.getSource() == lab) {
            if (!isMaxSize) {
                this.setLocation(0, 0);
                this.setSize(Toolkit.getDefaultToolkit().getScreenSize());
                isMaxSize = !isMaxSize;
            } else {
                this.setSize(600, 500);
                this.setLocation(450, 200);
                isMaxSize = !isMaxSize;
            }
        }

    }

 

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值