InstallAnyWhere中,自定义面板的一个例子
自定义面板需要依赖于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;//在面板下方,显示错误提示信息的labeljLabelError = 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; }}