📄 inputpanel.java
字号:
package com.dbhunter.ga;
import java.awt.*;
import javax.swing.*;
/**
*author dbhunter
*Email dbhunter@126.com
*/
public class InputPanel extends JPanel {
private static final long serialVersionUID = 1L;
private static final int MAXHEIGHT = 200,MAXWIDTH = 800;
private JLabel instructionLabel;
private JComboBox cbFun;
private JLabel labPopulationNum,labCrossP,labGenovariationP,labPrecision,labIterateNum;
private JSpinner spinPopulationNum,spinCrossP,spinGenovariationP,spinPrecision,spinIterateNum;
private JLabel funIconShow;
private JPanel upPanel,centerPanel,downPanel;
private static String strInitIcon = "images/0.jpg";
public InputPanel() {
this.setSize(MAXWIDTH, MAXHEIGHT);
this.setLayout(new BorderLayout(10,0));
this.upPanel = new JPanel();
this.centerPanel = new JPanel();
this.centerPanel.setSize(800,500);
this.downPanel = new JPanel();
this.upPanel.setLayout(new BorderLayout());
//create leftpart begin
this.instructionLabel = new JLabel("提示: 专家建议种群规模 20~200;交叉概率:0.6~1.0;变异概率:0.005~0.01;精度位数:1~8.目前为迭代次数结束");
this.cbFun = new JComboBox();
cbFun.addItem("选择函数");
cbFun.addItem("函数 1");
cbFun.addItem("函数 2");
cbFun.addItem("函数 3");
cbFun.addItem("函数 4");
cbFun.addItem("函数 5");
cbFun.addItem("函数 6");
cbFun.addItem("函数 7");
cbFun.addItem("函数 8");
this.funIconShow = new JLabel(new ImageIcon(strInitIcon));
upPanel.add(this.instructionLabel,BorderLayout.NORTH);
upPanel.add(this.funIconShow,BorderLayout.CENTER);
centerPanel.add(cbFun);
centerPanel.add(funIconShow);
labPopulationNum =new JLabel("种群规模:");
SpinnerNumberModel modelPN = new SpinnerNumberModel(20,20,200,1);
spinPopulationNum = new JSpinner(modelPN);
spinPopulationNum.setSize(5,5);
labCrossP=new JLabel("交叉概率:");
SpinnerNumberModel modelCP = new SpinnerNumberModel(0.8,0.6,1.0,0.1);
spinCrossP= new JSpinner(modelCP);
labGenovariationP=new JLabel("变异概率:");
SpinnerNumberModel modelGP = new SpinnerNumberModel(0.005,0.005,0.01,0.001);
spinGenovariationP= new JSpinner(modelGP);
labPrecision = new JLabel("要求精度位数:");
SpinnerNumberModel modelP = new SpinnerNumberModel(2,1,8,1);
spinPrecision = new JSpinner(modelP);
labIterateNum = new JLabel("迭代次数:");
SpinnerNumberModel modelIN = new SpinnerNumberModel(40,1,10000,1);
spinIterateNum = new JSpinner(modelIN);
//this.exeButton = new JButton("计算");
downPanel.add(this.labPopulationNum);
downPanel.add(this.spinPopulationNum);
downPanel.add(this.labCrossP);
downPanel.add(this.spinCrossP);
downPanel.add(this.labGenovariationP);
downPanel.add(this.spinGenovariationP);
downPanel.add(this.labPrecision);
downPanel.add(this.spinPrecision);
downPanel.add(this.labIterateNum);
downPanel.add(this.spinIterateNum);
//create rightpart end;
this.add(upPanel,BorderLayout.NORTH);
this.add(centerPanel,BorderLayout.CENTER);
this.add(downPanel,BorderLayout.SOUTH);
}
//set getmethod to buttons
// set getmethod to buttons end
public JComboBox getCbFun() {
return cbFun;
}
public void setCbFun(JComboBox cbFun) {
this.cbFun = cbFun;
}
public JLabel getFunIconShow() {
return funIconShow;
}
public void setFunIconShow(String str) {
this.funIconShow.setIcon(new ImageIcon(str));
}
public JLabel getInstructionLabel() {
return instructionLabel;
}
public void setInstructionLabel(JLabel instructionLabel) {
this.instructionLabel = instructionLabel;
}
public JSpinner getSpinCrossP() {
return spinCrossP;
}
public void setSpinCrossP(JSpinner spinCrossP) {
this.spinCrossP = spinCrossP;
}
public JSpinner getSpinGenovariationP() {
return spinGenovariationP;
}
public void setSpinGenovariationP(JSpinner spinGenovariationP) {
this.spinGenovariationP = spinGenovariationP;
}
public JSpinner getSpinIterateNum() {
return spinIterateNum;
}
public void setSpinIterateNum(JSpinner spinIterateNum) {
this.spinIterateNum = spinIterateNum;
}
public JSpinner getSpinPopulationNum() {
return spinPopulationNum;
}
public void setSpinPopulationNum(JSpinner spinPopulationNum) {
this.spinPopulationNum = spinPopulationNum;
}
public JSpinner getSpinPrecision() {
return spinPrecision;
}
public void setSpinPrecision(JSpinner spinPrecision) {
this.spinPrecision = spinPrecision;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -