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;
}
}
}
}