日期:2014-05-20 浏览次数:21041 次
public class PreviewDialog extends JDialog {
private static final long serialVersionUID = "PREVIEWDIALOG".hashCode();
private static PreviewDialog instancePreview = null;
public PreviewDialog() {
super.setBackground(Color.WHITE);
int width = Toolkit.getDefaultToolkit().getScreenSize().width - 300;
int height = Toolkit.getDefaultToolkit().getScreenSize().height - 300;
int wPoint = (Toolkit.getDefaultToolkit().getScreenSize().width - width) / 2;
int hPoint = (Toolkit.getDefaultToolkit().getScreenSize().height - height) / 2;
setSize(width, height);
setBounds(wPoint, hPoint, width, height);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setTitle("压缩文件比对");
}
/**
* 主面板
*/
public void mainPanel() {
Container contentPane = this.getContentPane();
JPanel title = new JPanel();
JLabel lblTitle = new JLabel("图片压缩前后效果比对", JLabel.CENTER);
title.setBackground(Color.WHITE);
title.add(lblTitle);
contentPane.add(title, BorderLayout.NORTH);
// 主面板
JPanel main = new JPanel();
main.setBackground(Color.WHITE);
main.setLayout(new BoxLayout(main, BoxLayout.X_AXIS));
main.setVisible(true);
contentPane.add(main);
// 左边面板
JPanel pnlLeft = new JPanel();
JScrollPane scrollLeftPane = new JScrollPane();
pnlLeft.add(scrollLeftPane, BorderLayout.CENTER);
pnlLeft.setSize(300, 200);
scrollLeftPane.setVisible(true);
main.add(pnlLeft);
// 左边原始图片
JLabel lblSource = new JLabel();
lblSource.setIcon(getIcon("F:\\MyDocument\\RainBoy\\Desktop\\122.jpg"));
pnlLeft.add(lblSource);
// 右侧面板
JPanel pnlRight = new JPanel();
JScrollPane scrollRightPane = new JScrollPane();
pnlRight.add(scrollRightPane, BorderLayout.CENTER);
main.add(pnlRight);
// 右边处理图片
JLabel lblTaget = new JLabel();
lblTaget.setIcon(getIcon("F:\\MyDocument\\RainBoy\\Desktop\\122.jpg"));
pnlRight.add(lblTaget);
}
private Icon getIcon(String url) {
ImageIcon icon = new ImageIcon(url);
return icon;
}