InstallAnyWhere中,自定义面板的一个事例
InstallAnyWhere中,自定义面板的一个例子
自定义面板需要依赖于InstallAnyWhere的主jar包IAClasses.zip。
编写完成后,将编译好的代码打为一个zip包。然后在installanywhere的工程里添加一个Custom Code的panel,然后在这个panel里选择刚才打出的zip包,并指定类名即可。
另,界面的设计可以使用Eclipse Visual Editor或者其他支持Swing图形界面设置的工具来设计。
自定义面板需要依赖于InstallAnyWhere的主jar包IAClasses.zip。
package com.cvicse.inforguard.install; import java.awt.Color; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JTextPane; import javax.swing.SwingConstants; import com.zerog.ia.api.pub.CustomCodePanel; import com.zerog.ia.api.pub.CustomCodePanelProxy; public class EnCompentPanel extends CustomCodePanel implements ActionListener { private static final long serialVersionUID = 1222L; private boolean inited = false; private JLabel jLabelInfor = null; private JLabel jLabelError = null; private JCheckBox jCheckBoxMC = null; private JCheckBox jCheckBoxConsole = null; private JTextPane jTextPaneInfor = null; //资源类,存放了所有的文字提示信息 public iRes res = null; public EnCompentPanel() { //得到一个英文的资源类 res = new ResEnglish(); } public boolean setupUI(CustomCodePanelProxy customCodePanelProxy) { if (inited == true) return true; inited = true; //在面板下方,显示错误提示信息的label jLabelError = new JLabel(); jLabelError.setBounds(new Rectangle(15, 185, 300, 18)); jLabelError.setText(""); //jLabelInfor是面板最上方的信息提示框 jLabelInfor = new JLabel(); jLabelInfor.setBounds(new Rectangle(5, 5, 377, 110)); jLabelInfor.setVerticalTextPosition(SwingConstants.TOP); jLabelInfor.setVerticalAlignment(SwingConstants.TOP); jLabelInfor.setText(""); jLabelInfor.setBorder(BorderFactory.createLineBorder(Color.GRAY)); //面板的默认宽、高 this.setSize(404, 310); this.setLayout(null); //将用到的控件都添加到面板中去 this.add(jLabelInfor, null); this.add(jLabelError, null); this.add(getJCheckBoxMC(), null); this.add(getJCheckBoxConsole(), null); this.add(getJTextPaneInfor(), null); return true; } public void panelIsDisplayed() { } //点击下一步按钮时触发的事件,返回true时可以进入下一步,返回false时停留在本页面 public boolean okToContinue() { if (!jCheckBoxMC.isSelected()) { if (!jCheckBoxConsole.isSelected()) { jLabelError.setText(res.getComponentjLabelErrorText()); return false; } } else { jLabelError.setText(""); } //以下一段设置InstallAnyWhere中的环境变量 if (jCheckBoxMC.isSelected()) { customCodePanelProxy.setVariable("mc", "mcSelect"); } else { customCodePanelProxy.setVariable("mc", "mcNotSelect"); } if (jCheckBoxConsole.isSelected()) { customCodePanelProxy.setVariable("console", "consoleSelect"); } else { customCodePanelProxy.setVariable("console", "consoleNotSelect"); } return true; } //点击上一步按钮时触发的事件,返回true时可以进入下一步,返回false时停留在本页面 public boolean okToGoPrevious() { jLabelError.setText(""); return true; } //此面板显示在右上角的标题 public String getTitle() { return res.getComponentPanelTitle(); } public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub } private JCheckBox getJCheckBoxMC() { if (jCheckBoxMC == null) { jCheckBoxMC = new JCheckBox(); jCheckBoxMC.setBounds(new Rectangle(10, 128, 147, 21)); jCheckBoxMC.setText("InforGuard MC"); jCheckBoxMC.setBackground(Color.white); jCheckBoxMC.setSelected(true); } return jCheckBoxMC; } private JCheckBox getJCheckBoxConsole() { if (jCheckBoxConsole == null) { jCheckBoxConsole = new JCheckBox(); jCheckBoxConsole.setBounds(new Rectangle(10, 148, 163, 26)); jCheckBoxConsole.setText("InforGuard Console"); jCheckBoxConsole.setBackground(Color.white); jCheckBoxConsole.setSelected(true); } return jCheckBoxConsole; } private JTextPane getJTextPaneInfor() { if (jTextPaneInfor == null) { jTextPaneInfor = new JTextPane(); jTextPaneInfor.setBounds(new Rectangle(8, 8, 362, 100)); jTextPaneInfor.setText(res.getComponentjTextPaneInfor()); jTextPaneInfor.setEditable(false); } return jTextPaneInfor; } }
编写完成后,将编译好的代码打为一个zip包。然后在installanywhere的工程里添加一个Custom Code的panel,然后在这个panel里选择刚才打出的zip包,并指定类名即可。
另,界面的设计可以使用Eclipse Visual Editor或者其他支持Swing图形界面设置的工具来设计。
1 楼
simusuishi
2012-09-19
你的意思是说:必须要做一个图形界面,才能在installanywhere安装的过程中出现这个自定义panel?
我就是用你的这个方法,做的一个panel,现在就是显示不出来这个界面。正在晕眩中。。。
请房主指教,先谢谢了!
我就是用你的这个方法,做的一个panel,现在就是显示不出来这个界面。正在晕眩中。。。
请房主指教,先谢谢了!