📄 navigationpanel.java
字号:
package org.theblueplanet.annealing.ui;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;import javax.swing.JButton;import javax.swing.JPanel;import javax.swing.BorderFactory;import javax.swing.border.EtchedBorder;import org.theblueplanet.annealing.AnnealingScheme;/** * The Navigation panel at the bottom of the JFrames * * @author Charles M間nin * @since October 29, 2001 * @version 1.0 */public class NavigationPanel extends JPanel implements ActionListener { private JButton continueButton = new JButton("Continue >>"); private JButton backButton = new JButton("<< Back"); private JButton launchButton = new JButton("Launch"); private JButton exitButton = new JButton("Exit"); private AnnealingSchemeFrame parent; /** * Constructor for the NavigationPanel object * * @param parent Description of Parameter */ public NavigationPanel(AnnealingSchemeFrame parent) { super(); this.parent = parent; init(); display(parent); } /** * Sets layout and initial parameters */ private void init() { this.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED)); addButton(exitButton, "Terminate program", KeyEvent.VK_X); addButton(continueButton, "Next page", KeyEvent.VK_C); addButton(backButton, "Previous page", KeyEvent.VK_B); addButton(launchButton, "Start simulated annealing algorithm", KeyEvent.VK_L); } /** * Adds a JButton to the NavigationPanel object * * @param button The feature to be added to the Button attribute * @param tooltip The feature to be added to the Button attribute * @param key The feature to be added to the Button attribute */ private void addButton(JButton button, String tooltip, int key) { button.setMnemonic(key); button.setToolTipText(tooltip); button.addActionListener(this); } protected void refresh(AnnealingSchemeFrame parent) { removeAll(); display(parent); } /** * Displays the Buttons */ private void display(AnnealingSchemeFrame parent) { enableButtons(parent); this.add(exitButton); this.add(backButton); this.add(continueButton); this.add(launchButton); } /** * Logic to decide which JButtons are enable and which are disabled */ private void enableButtons(AnnealingSchemeFrame parent) { if (parent.getView() == 1) { exitButton.setEnabled(true); backButton.setEnabled(false); continueButton.setEnabled(true); launchButton.setEnabled(false); } else if (parent.getView() == 2) { exitButton.setEnabled(true); backButton.setEnabled(true); continueButton.setEnabled(false); launchButton.setEnabled(true); } } private void disableButtons() { exitButton.setEnabled(false); backButton.setEnabled(false); continueButton.setEnabled(false); launchButton.setEnabled(false); } /** * Handles page switching as a result of the event triggered by * the continueButton or the backButton */ private void nextPage() { if (parent.getView() == 1) { parent.setView(2); } else if (parent.getView() == 2) { parent.setView(1); } parent.display(); this.refresh(parent); } /** * Calls on the JFrame to launch the Simulated Annealing algorithm */ private void launch() { parent.launchAnnealing(); } /** * Kills the window and terminate the program */ private void kill() { parent.dispose(); System.exit(0); } /** * ActionListener listening to the JButtons on the NavigationPanel * * @param e Action event */ public void actionPerformed(ActionEvent e) { if (e.getSource() == launchButton) { launch(); } else if (e.getSource() == exitButton) { kill(); } else if (e.getSource() == backButton || e.getSource() == continueButton) { nextPage(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -