package com.vci.client.logon.base; import java.awt.Color; import java.awt.Cursor; import java.awt.Frame; import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.io.IOException; import java.io.UnsupportedEncodingException; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextArea; import com.vci.client.common.ConfigUtils; import com.vci.client.ui.image.BundleImage; /** * 关于窗口 */ public class AboutDialog extends JDialog { /** * 所属窗口 */ private Frame owner; /** * 图片标签 */ private JLabel imageLabel; /** * 文本标签 */ private JTextArea txtArea; /** * 访问链接 */ private JLabel visitLabel; /** * 关闭按钮 */ private JButton ok_btn; /** * 图片名称 */ private String imageName = "about.png"; /** * 标题 */ private String title = "关于"; /** * 软件名称 */ private String softName = "Innovation 开发平台"; /** * 版本 */ private String version = "8.0.7600.16385"; /** * 网址 */ private String visit = "http://www.vci-tech.com"; /** * 产品 */ private String softNameProduct = "宏博远达 Innovation 2023"; /** * 版权_中文 */ private String softNameCopyrightC = "北京宏博远达科技有限公司 ©版权所有"; /** * 版权_英文 */ private String softNameCopyrightE = "VCI Copyright(C) 2011-2023 Contributors. All rights reserved."; /** * */ /** * 构造器 */ public AboutDialog(Frame owner, boolean modal){ super(owner, modal); this.owner = owner; try { //获得配置信息 String conTitle = ConfigUtils.getConfigValue("system.about.title"); if(conTitle != null && !conTitle.equals("")){ conTitle = new String(conTitle.getBytes("iso-8859-1"),"utf-8"); title = conTitle; } String conImageName = ConfigUtils.getConfigValue("system.about.imageName"); if(conImageName != null && !conImageName.equals("")){ conImageName = new String(conImageName.getBytes("iso-8859-1"),"utf-8"); imageName = conImageName; } String conSoftName = ConfigUtils.getConfigValue("system.about.softName"); if(conSoftName != null && !conSoftName.equals("")){ conSoftName = new String(conSoftName.getBytes("iso-8859-1"),"utf-8"); softName = conSoftName; } String conVersion = ConfigUtils.getConfigValue("system.about.version"); if(conVersion != null && !conVersion.equals("")){ conVersion = new String(conVersion.getBytes("iso-8859-1"),"utf-8"); version = conVersion; } String conVisit = ConfigUtils.getConfigValue("system.about.visit"); if(conVisit != null && !conVisit.equals("")){ conVisit = new String(conVisit.getBytes("iso-8859-1"),"utf-8"); visit = conVisit; } String conSoftNameProduct = ConfigUtils.getConfigValue("system.about.softNameProduct"); if(conSoftNameProduct != null && !conSoftNameProduct.equals("")){ conSoftNameProduct = new String(conSoftNameProduct.getBytes("iso-8859-1"),"utf-8"); softNameProduct = conSoftNameProduct; } String conSoftNameCopyrightC = ConfigUtils.getConfigValue("system.about.softNameCopyrightC"); if(conSoftNameCopyrightC != null && !conSoftNameCopyrightC.equals("")){ conSoftNameCopyrightC = new String(conSoftNameCopyrightC.getBytes("iso-8859-1"),"utf-8"); softNameCopyrightC = conSoftNameCopyrightC; } String conSoftNameCopyrightE = ConfigUtils.getConfigValue("system.about.softNameCopyrightE"); if(conSoftNameCopyrightE != null && !conSoftNameCopyrightE.equals("")){ conSoftNameCopyrightE = new String(conSoftNameCopyrightE.getBytes("iso-8859-1"),"utf-8"); softNameCopyrightE = conSoftNameCopyrightE; } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } this.setTitle(title); init(); } /** * 绘制窗口 */ private void init(){ Color bg = this.getContentPane().getBackground(); setLayout(null); setSize(400, 300); imageLabel = new JLabel(); BundleImage bi = new BundleImage(); bi.setPath("/resource/icons/"); imageLabel.setIcon(bi.createImageIcon(imageName)); imageLabel.setBounds(new Rectangle(0, 0, 400, 90)); txtArea = new JTextArea(); txtArea.setBackground(bg); StringBuffer sb = new StringBuffer(); sb.append(softName).append("\n") .append("\n") .append("产品:").append(softNameProduct).append("\n") .append("版本:").append(version).append("\n") .append("版权:").append(softNameCopyrightC).append("\n") .append(" ").append(softNameCopyrightE).append("\n"); txtArea.setText(sb.toString()); txtArea.setEditable(false); txtArea.setBounds(new Rectangle(10, 95, 370, 105)); visitLabel = new JLabel("" + visit + ""); visitLabel.setBounds(new Rectangle(15, 200, 150, 25)); visitLabel.addMouseListener(new MouseAdapter() { public void mouseExited(MouseEvent e) { visitLabel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } public void mouseEntered(MouseEvent e) { visitLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); } public void mouseClicked(MouseEvent e) { try { Runtime.getRuntime().exec("cmd.exe /c start " + visit); } catch (IOException e1) { e1.printStackTrace(); } } }); ok_btn = new JButton("确定"); ok_btn.setBounds(new Rectangle(280, 230, 75, 25)); ok_btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okBtn(); } }); this.getContentPane().add(imageLabel); this.getContentPane().add(txtArea); this.getContentPane().add(visitLabel); this.getContentPane().add(ok_btn); setResizable(false); setWindowLocation(this); validate(); setVisible(true); } /** * 关闭事件 */ private void okBtn(){ this.dispose(); } /** * 设置窗体居中 * @param window */ private void setWindowLocation(Window window){ //屏幕大小 int width = Toolkit.getDefaultToolkit().getScreenSize().width; int height = Toolkit.getDefaultToolkit().getScreenSize().height - 20; //窗口大小 int windowWidth = window.getSize().width; int windowHeight = window.getSize().height; //窗口定点位置 int left = (width - windowWidth) / 2; int top = (height - windowHeight) / 2; window.setBounds(left, top, windowWidth, windowHeight); } public static void main(String[] args){ Frame f = new JFrame(); f.setSize(200, 300); new AboutDialog(f, true); } }