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

📄 objectivefunctionchooser.java

📁 模拟退火是一种启发式算法
💻 JAVA
字号:
package org.theblueplanet.annealing.ui;import java.awt.GridLayout;import javax.swing.BorderFactory;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.border.EtchedBorder;import javax.swing.event.DocumentEvent;import javax.swing.event.DocumentListener;import org.apache.log4j.Logger;import org.theblueplanet.annealing.AnnealingScheme;/** *  JPanel displaying JTextFields to select the class and the method to be minimized. * * @author     Charles M間nin * @since    November 3, 2001 * @version    1.0 */public class ObjectiveFunctionChooser extends JPanel {    private static Logger logger = Logger.getLogger("org.theblueplanet.annealing");    private JTextField methodField;    private JTextField classField;    private AnnealingScheme scheme;    private String className            = null;    private String methodName           = null;    private final static String TITLE   = "Objective Function Selector";    private final static int labelSize  = 13;    private final static int fieldSize  = 30;    /**     *  Constructor for the ObjectiveFunctionChooser object     *     * @param  scheme                     The Object that encapsulates the annealing parameters     * @exception  ClassNotFoundException  Description of Exception     * @exception  InstantiationException  Description of Exception     * @exception  IllegalAccessException  Description of Exception     */    public ObjectiveFunctionChooser(AnnealingScheme scheme)        throws ClassNotFoundException, InstantiationException,            IllegalAccessException {        super();        this.scheme = scheme;        init();    }    /**     *  Sets up layout and initial parameters     *     * @exception  ClassNotFoundException  Description of Exception     * @exception  InstantiationException  Description of Exception     * @exception  IllegalAccessException  Description of Exception     */    private void init()        throws ClassNotFoundException, InstantiationException,            IllegalAccessException {        logger.debug("Instantiating " + this.getClass().getName());        this.setLayout(new GridLayout(3, 1));        this.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));        this.add(createTitlePanel());        this.add(createClassPanel());        this.add(createMethodPanel());    }    /**     *  Calls the setter for the className field in the AnnealingScheme     *     * @param  className  name of the class     */    protected void updateClass(String className) {        scheme.setClassName(className);    }    /**     *  Calls the setter for the methodName field in the AnnealingScheme     *     * @param  methodName  name of the method     */    protected void updateMethod(String methodName) {        scheme.setMethodName(methodName);    }    /**     *  Creates a JPanel holding the title of the Chooser     *     * @return    Description of the Returned Value     */    private JPanel createTitlePanel() {        JPanel titlePanel  = new JPanel();        titlePanel.add(new JLabel(TITLE));        return titlePanel;    }    /**     * Instantiates the method JPanel.     *     * @return    The method JPanel;     */    private JPanel createMethodPanel() {        JPanel methodPanel      = new JPanel();        JTextField methodLabel  = new JTextField("Enter the method name:", labelSize);        methodLabel.setEditable(false);        methodField = new JTextField(scheme.getMethod().getName(), fieldSize);        methodField.getDocument().addDocumentListener(            new DocumentListener() {                public void insertUpdate(DocumentEvent e) {                    updateMethod(methodField.getText());                }                public void removeUpdate(DocumentEvent e) {                    updateMethod(methodField.getText());                }                public void changedUpdate(DocumentEvent e) {                    updateMethod(methodField.getText());                }            }                );        methodPanel.add(methodLabel);        methodPanel.add(methodField);        return methodPanel;    }    /**     *  Instantiates the class JPanel.     *     * @return    The class JPanel.     */    private JPanel createClassPanel() {        JPanel classPanel      = new JPanel();        JTextField classLabel  = new JTextField("Enter the classpath:", labelSize);        classLabel.setEditable(false);        classField = new JTextField(scheme.getOfClass().getName(), fieldSize);        classField.getDocument().addDocumentListener(            new DocumentListener() {                public void insertUpdate(DocumentEvent e) {                    updateClass(classField.getText());                }                public void removeUpdate(DocumentEvent e) {                    updateClass(classField.getText());                }                public void changedUpdate(DocumentEvent e) {                    updateClass(classField.getText());                }            }                );        classPanel.add(classLabel);        classPanel.add(classField);        return classPanel;    }}

⌨️ 快捷键说明

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