⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 controlpanel.java

📁 拥有图形界面的
💻 JAVA
字号:
/* * ControlPanel.java * * WARNING: This class has been generated by NetBeans (www.netbeans.org) * PLEASE use the Form Editor of NetBeans to modify its layout. * PLEASE see all Warnings in the code. * * Created on 17 may 2001, 23.31 */package org.joone.edit;import org.joone.engine.*;import org.joone.net.NeuralNet;import org.joone.net.NetChecker;import javax.swing.*;import java.awt.*;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;public class ControlPanel extends javax.swing.JPanel implements NeuralNetListener {        private Monitor monitor;    private NeuralNet nNet;    private PropertySheet parent;    private NetChecker netChecker;    private boolean printCycle = false;        /** Creates new form ControlPanel */    public ControlPanel(NeuralNet nn, PropertySheet ps) {        setMonitor(nn.getMonitor());        parent = ps;        nNet = nn;        netChecker = new NetChecker(nNet);        initComponents();    }        public void setMonitor(Monitor m) {        monitor = m;        /* We register this ControlPanel to the Monitor - not to the NeuralNet - object         * because the listeners list of the Monitor is transient, so we         * avoid to serialize this ControlPanel when we 'export' the neural net         */        monitor.addNeuralNetListener(this);    }        /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    private void initComponents() {//GEN-BEGIN:initComponents        jPanel1 = new javax.swing.JPanel();        runButton = new javax.swing.JButton();        continueButton = new javax.swing.JButton();        stopButton = new javax.swing.JButton();        jPanel2 = new javax.swing.JPanel();        cicleLabel = new javax.swing.JLabel();        cicleValue = new javax.swing.JLabel();        rmsLabel = new javax.swing.JLabel();        rmsValue = new javax.swing.JLabel();        setLayout(new java.awt.GridLayout(2, 1, 0, 10));        setBorder(new javax.swing.border.TitledBorder("Controls"));        jPanel1.setLayout(new java.awt.GridLayout(1, 3));        runButton.setForeground(java.awt.Color.green);        runButton.setText("Run");        runButton.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                runButtonActionPerformed(evt);            }        });        jPanel1.add(runButton);        continueButton.setForeground(new java.awt.Color(0, 51, 255));        continueButton.setText("Continue");        continueButton.setEnabled(false);        continueButton.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                continueButtonActionPerformed(evt);            }        });        jPanel1.add(continueButton);        stopButton.setForeground(java.awt.Color.red);        stopButton.setText("Pause");        stopButton.setEnabled(false);        stopButton.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                stopButtonActionPerformed(evt);            }        });        jPanel1.add(stopButton);        add(jPanel1);        jPanel2.setLayout(new java.awt.GridLayout(2, 2, 0, 8));        cicleLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);        cicleLabel.setText("Epochs :  ");        cicleLabel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);        jPanel2.add(cicleLabel);        cicleValue.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);        cicleValue.setText("0");        jPanel2.add(cicleValue);        rmsLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);        rmsLabel.setText("RMSE :  ");        jPanel2.add(rmsLabel);        rmsValue.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);        rmsValue.setText("0.0");        jPanel2.add(rmsValue);        add(jPanel2);    }//GEN-END:initComponents        private void continueButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_continueButtonActionPerformed        // Add your handling code here:                // Make sure the network checks out before cotinuing.        if (netChecker.hasErrors()) {            displayNogo("Network could not be run.", "See 'To Do List' to check all the errors.");        } else {            setLearners();            nNet.restore();            setState(false);        }    }//GEN-LAST:event_continueButtonActionPerformed        private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopButtonActionPerformed        // Add your handling code here:        nNet.stop();    }//GEN-LAST:event_stopButtonActionPerformed        private void runButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_runButtonActionPerformed        // Add your handling code here:                // Make sure the network checks out before running.        if (netChecker.hasErrors()) {            displayNogo("Network could not be run.", "See 'To Do List' to check all the errors.");        } else {            setLearners();            nNet.go();        }    }//GEN-LAST:event_runButtonActionPerformed        public void netStopped(NeuralNetEvent e) {        setState(true);        printCycle = true;        parent.update();    }        public void cicleTerminated(NeuralNetEvent e) {        int currentCycle = monitor.getTotCicles() - monitor.getCurrentCicle() + 1;        int cl = currentCycle / parameters.getRefreshingRate();        /* We want to print the results only every refreshing_rate cycles and the last cycle*/        if ((cl * parameters.getRefreshingRate()) == currentCycle || monitor.getCurrentCicle() == 1) {            cicleValue.setText(Integer.toString(currentCycle));            printCycle = true;        }    }        /** Setter for property parameters.     * @param parameters New value of property parameters.     */    public void setParameters(EditorParameters parameters) {        this.parameters = parameters;    }        // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JButton continueButton;    private javax.swing.JLabel cicleLabel;    private javax.swing.JButton stopButton;    private javax.swing.JPanel jPanel2;    private javax.swing.JLabel cicleValue;    private javax.swing.JButton runButton;    private javax.swing.JLabel rmsLabel;    private javax.swing.JPanel jPanel1;    private javax.swing.JLabel rmsValue;    // End of variables declaration//GEN-END:variables        private static final long serialVersionUID = 1310288899683080017L;        private EditorParameters parameters;        private void setState(boolean state) {        runButton.setEnabled(state);        continueButton.setEnabled(state);        stopButton.setEnabled(!state);        parent.setControlsEnabled(state);    }        public void netStarted(NeuralNetEvent e) {        setState(false);    }        public void errorChanged(NeuralNetEvent e) {        if ((printCycle) || (monitor.getTotCicles() < parameters.getRefreshingRate())) {            rmsValue.setText(Double.toString(monitor.getGlobalError()));            printCycle = false;        }    }        /**     * Pops up a dialog window with no-go messages displayed.     */    private void displayNogo(String message1, String message2) {        final JDialog dialog = new JDialog(parent, "Critical Network Error", true);        dialog.getContentPane().setLayout(new BorderLayout(10, 10));                // Add ok button.        Button ok = new Button("  OK  ");        ok.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                dialog.dispose();            }        });        Panel p = new Panel();        p.setLayout(new FlowLayout(FlowLayout.CENTER));        p.add(ok);        dialog.getContentPane().add(p, BorderLayout.SOUTH);                // Add banner.        JLabel label = new JLabel(message1);        label.setHorizontalAlignment(SwingConstants.CENTER);        dialog.getContentPane().add(label, BorderLayout.NORTH);                // Add banner.        label = new JLabel(message2);        label.setHorizontalAlignment(SwingConstants.CENTER);        dialog.getContentPane().add(label, BorderLayout.CENTER);                // Center location on parent.        dialog.pack();        Point center = new Point(parent.getX() + parent.getWidth() / 2,        parent.getY() + parent.getHeight() / 2);        dialog.setLocation((int) (center.getX() - dialog.getWidth() / 2),        (int) (center.getY() - dialog.getHeight() / 2));        dialog.setVisible(true);    }        public void netStoppedError(NeuralNetEvent e,String error) {                setState(true);        printCycle = true;        parent.update();        this.displayNogo("Runtime Error!", error);        //JOptionPane.showMessageDialog(parent,error, "Critical Network Error!", JOptionPane.ERROR_MESSAGE);    }        /** Initialization of the available learners     */    public void setLearners() {        // TODO: Implement the reading of the Learners from the XML parameters file        monitor.addLearner(0, "org.joone.engine.BasicLearner");        monitor.addLearner(1, "org.joone.engine.BatchLearner");        monitor.addLearner(2, "org.joone.engine.RpropLearner");        //monitor.addLearner(3, "org.joone.engine.SwarmLearner");    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -