📄 learnerinterface.java
字号:
package learner;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JDesktopPane;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JScrollPane;
import javax.swing.JCheckBox;
import java.awt.SystemColor;
public class LearnerInterface extends JFrame {
static final long serialVersionUID = 0;
private Classifier learner;
private JDesktopPane desk = null;
private JTextArea console = null;
private JButton validatebutton = null;
private JButton exitbutton = null;
private JComboBox selector = null;
private JLabel selectorL = null;
private JLabel validateL = null;
private JLabel parameterL = null;
private JLabel datafileL = null;
private JLabel dataL = null;
private JLabel labelL = null;
private JTextField validateT = null;
private JTextField parameterT = null;
private JTextField datafileT = null;
private JTextField dataT = null;
private JTextField labelT = null;
private JLabel toclassifyL = null;
private JTextField toclassifyT = null;
private JButton classifybutton = null;
private JScrollPane scrollbars = null;
private JCheckBox datasetcheckbox = null;
private JButton performancebutton = null;
private JButton findbestbutton = null;
private JButton printdatabutton = null;
private JCheckBox jCheckBox = null;
/**
* This is the default constructor
*/
public LearnerInterface(){
super();
initialize();
}
public static void main(String[] args) {
try
{
new LearnerInterface();
}catch(Exception e)
{
e.printStackTrace();
}
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
try{
this.setContentPane(getJDesktopPane());
this.setResizable(false);
this.setLocation(new java.awt.Point(100,100));
this.setSize(new java.awt.Dimension(526,446));
this
.setTitle("Automated Learning & Adaptive Knowledge Systems - 1D Learning");
this.setVisible(true);
this.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(1);
}
});
}catch(Exception e)
{
e.printStackTrace();
}
}
/**
* This method initializes desk
*
* @return javax.swing.JDesktopPane
*/
private JDesktopPane getJDesktopPane() {
if (desk == null) {
labelL = new JLabel();
labelL.setBounds(new java.awt.Rectangle(276, 370, 92, 20));
labelL.setText("Labels column:");
labelL.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
dataL = new JLabel();
dataL.setBounds(new java.awt.Rectangle(165, 370, 81, 20));
dataL.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
dataL.setText("Data column:");
datafileL = new JLabel();
datafileL.setBounds(new java.awt.Rectangle(6, 370, 73, 20));
datafileL.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
datafileL.setText("Dataset file:");
parameterL = new JLabel();
parameterL.setBounds(new java.awt.Rectangle(336, 5, 126, 20));
parameterL.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
parameterL.setText("Boosting Iterations :");
toclassifyL = new JLabel();
toclassifyL.setBounds(new java.awt.Rectangle(14, 55, 121, 20));
toclassifyL
.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
toclassifyL.setText("Element to classify:");
validateL = new JLabel();
validateL.setBounds(new java.awt.Rectangle(4, 32, 132, 20));
validateL.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
validateL.setText("Cross Validation Folds:");
selectorL = new JLabel();
selectorL.setBounds(new java.awt.Rectangle(3, 5, 177, 20));
selectorL.setText("Choose your favorite Classifier");
desk = new JDesktopPane();
desk.setBackground(java.awt.SystemColor.control);
desk.add(getJButton(), null);
desk.add(getJComboBox(), null);
desk.add(getJButton1(), null);
desk.add(toclassifyL, null);
desk.add(getJTextField5(), null);
desk.add(getJButton2(), null);
desk.add(selectorL, null);
desk.add(getJScrollPane(), null);
desk.add(validateL, null);
desk.add(getJTextField(), null);
desk.add(getJTextField1(), null);
desk.add(parameterL, null);
desk.add(datafileL, null);
desk.add(getJTextField2(), null);
desk.add(dataL, null);
desk.add(getJTextField3(), null);
desk.add(labelL, null);
desk.add(getJTextField4(), null);
desk.add(getJCheckBox(), null);
desk.add(getJButton3(), null);
desk.add(getJButton4(), null);
desk.add(getPrintdatabutton(), null);
desk.add(getJCheckBox2(), null);
}
return desk;
}
/**
* This method initializes console
*
* @return javax.swing.JTextArea
*/
private JTextArea getJTextArea() {
if (console == null) {
console = new JTextArea();
console.setEditable(false);
console.setRows(60);
console.setText("");
console.setFont(new java.awt.Font("Courier New",
java.awt.Font.PLAIN, 12));
console.setColumns(50);
}
return console;
}
/**
* This method initializes classifybutton
*
* @return javax.swing.JButton
*/
private JButton getJButton2() {
if (classifybutton == null) {
classifybutton = new JButton();
classifybutton.setBounds(new java.awt.Rectangle(180, 56, 130, 20));
classifybutton.setText("Classify Element");
classifybutton
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
double value;
if (toclassifyT.getText().replaceAll(",", ".")
.matches("\\d+\\.?[\\d+]?"))
value = new Double(toclassifyT.getText()
.replace(",", ".")).doubleValue();
else {
JOptionPane
.showMessageDialog(null,
"Invalid value specified, please insert a number");
return;
}
reinitClassifier();
console
.setText(console.getText()
+ "========================= Classification ============================\n"
+ "Algorithm = "
+ selector.getSelectedItem()
+ " ("
+ parameterT.getText()
+ ")\n"
+ "Value "
+ toclassifyT.getText()
+ " is classified as class "
+ learner.classify(value)
+ "\n"
+ "=====================================================================\n\n");
}
});
}
return classifybutton;
}
/**
* This method initializes validatebutton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (validatebutton == null) {
validatebutton = new JButton();
validatebutton.setBounds(new java.awt.Rectangle(180, 30, 130, 20));
validatebutton.setText("Cross Validate");
validatebutton
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
reinitClassifier();
double[] performance = learner
.crossvalidate(Integer.parseInt(validateT
.getText()));
console
.setText(console.getText()
+ "========================= Cross Validation ==========================\n"
+ "Algorithm = "
+ selector.getSelectedItem()
+ " ("
+ parameterT.getText()
+ ")\n"
+ "Folds = "
+ Integer.parseInt(validateT
.getText())
+ "\n"
+ "Average Performance = "
+ Data.mean(performance)
+ "\nStandard Deviation = "
+ Data.std(performance)
+ "\n"
+ "=====================================================================\n\n");
}
});
}
return validatebutton;
}
/**
* This method initializes selector
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox() {
if (selector == null) {
selector = new JComboBox();
selector.setBounds(new java.awt.Rectangle(180, 5, 129, 20));
selector.addItem("Adaboost");
selector.addItem("Knn");
selector.addItem("DistanceMajority");
selector.addItem("Parzen");
selector.addItem("Linear");
selector.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
switch (selector.getSelectedIndex()) {
case 0:
parameterL.setText("Boosting Iterations:");
findbestbutton.setVisible(false);
parameterL.setVisible(true);
parameterT.setVisible(true);
break;
case 1:
parameterL.setText("Required Neighbors:");
findbestbutton.setVisible(true);
parameterL.setVisible(true);
parameterT.setVisible(true);
findbestbutton.setText("Find Best Neighbors K");
break;
case 2:
parameterL.setText("Distance:");
findbestbutton.setVisible(true);
parameterL.setVisible(true);
parameterT.setVisible(true);
findbestbutton.setText("Find Best Distance");
break;
case 3:
parameterL.setText("Smoothing:");
findbestbutton.setVisible(true);
parameterL.setVisible(true);
parameterT.setVisible(true);
findbestbutton.setText("Estimate Smoothing");
break;
case 4:
findbestbutton.setVisible(false);
parameterL.setVisible(false);
parameterT.setVisible(false);
break;
}
}
});
}
return selector;
}
/**
* This method initializes exitbutton
*
* @return javax.swing.JButton
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -