📄 algosimulator.java
字号:
import java.awt.BorderLayout;import java.awt.Color;import java.awt.Graphics;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import java.io.FileInputStream;import java.io.ObjectInputStream;import java.text.DecimalFormat;import java.util.Vector;import java.util.zip.GZIPInputStream;import javax.swing.BorderFactory;import javax.swing.DebugGraphics;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JFileChooser;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JSeparator;import javax.swing.JTextField;import javax.swing.SwingConstants;import javax.swing.WindowConstants;import javax.swing.border.TitledBorder;public class AlgoSimulator extends javax.swing.JFrame implements ActionListener{ private JPanel jPanel; private JButton jLoadButton; private JPanel jGridPanel; private JSeparator jSeparator1; private JButton jInitialiseButton; private JButton jStepButton; private JButton jExecuteButton; private JFileChooser fc; private JLabel jLabelSqSize; private JCheckBox jPolicyCheckBox; private JCheckBox jValuesCheckBox; private JButton jUpdateButton; private JButton jRefreshButton; private JLabel jStatusLabel; private JTextField jFileNameTextField; private JTextField jCyclesTextField; private JLabel jCyclesLabel; private JTextField sqSizeTextField; private JTextField pjogTextField; private JLabel JLabelPJOG; private JLabel jConvErrorLabel; private JTextField jConverErrorTextField; private JLabel jDelayLabel; private JTextField jDelayTextField; private int algoType; private Algorithms alg = null; private Maze myMaze = null; private boolean ShowValue = true; private boolean ShowPolicy = true; private DecimalFormat df = new DecimalFormat("0"); private String mazeStatus = "Load Maze First..."; private String basicAlgStatus = ""; private String additionalAlgStatus = ""; private JLabel jLabelVFLimit; private JTextField jVFLimitTextField; private JLabel jLabelIterLimit; private JTextField jIterLimitTextField; { //Set Look & Feel try { javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch(Exception e) { e.printStackTrace(); } } public AlgoSimulator(int _algoType) { super("RL-MDP:Simulation"); algoType = _algoType; initGUI(); } private void initGUI() { try { this.setSize(1000, 800); this.setExtendedState(MAXIMIZED_BOTH); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); { jPanel = new JPanel(); this.getContentPane().add(jPanel, BorderLayout.CENTER); jPanel.setLayout(null); jPanel.setBackground(new java.awt.Color(235, 241, 238)); jPanel.setPreferredSize(new java.awt.Dimension(900, 700)); } { jLoadButton = new JButton(); jPanel.add(jLoadButton); jLoadButton.setText("LoadMaze..."); jLoadButton.setBounds(25, 62, 110, 28); jLoadButton.setActionCommand("LoadMaze"); jLoadButton.addActionListener(this); } if(algoType==Algorithms.PolicyIter) { { jLabelVFLimit = new JLabel(); jPanel.add(jLabelVFLimit); jLabelVFLimit.setText("Value Limit"); jLabelVFLimit.setBounds(25, 115, 53, 21); jLabelVFLimit.setHorizontalAlignment(SwingConstants.RIGHT); } { jVFLimitTextField = new JTextField(); jPanel.add(jVFLimitTextField); jVFLimitTextField.setText("5000"); jVFLimitTextField.setBounds(88, 117, 45, 20); jVFLimitTextField.setHorizontalAlignment(SwingConstants.RIGHT); } { jLabelIterLimit = new JLabel(); jPanel.add(jLabelIterLimit); jLabelIterLimit.setText("Iter. Limit"); jLabelIterLimit.setBounds(25, 136, 53, 21); jLabelIterLimit.setHorizontalAlignment(SwingConstants.RIGHT); } { jIterLimitTextField = new JTextField(); jPanel.add(jIterLimitTextField); jIterLimitTextField.setText("500"); jIterLimitTextField.setBounds(88, 138, 45, 20); jIterLimitTextField.setHorizontalAlignment(SwingConstants.RIGHT); } } { JLabelPJOG = new JLabel(); jPanel.add(JLabelPJOG); JLabelPJOG.setText("PJOG"); JLabelPJOG.setBounds(25, 157, 53, 21); JLabelPJOG.setHorizontalAlignment(SwingConstants.RIGHT); } { pjogTextField = new JTextField(); jPanel.add(pjogTextField); pjogTextField.setText("0.3"); pjogTextField.setBounds(88, 159, 45, 20); pjogTextField.setHorizontalAlignment(SwingConstants.RIGHT); } { jConvErrorLabel = new JLabel(); jPanel.add(jConvErrorLabel); jConvErrorLabel.setText("Precision"); jConvErrorLabel.setBounds(29, 178, 51, 21); jConvErrorLabel.setHorizontalAlignment(SwingConstants.RIGHT); } { jConverErrorTextField = new JTextField(); jPanel.add(jConverErrorTextField); jConverErrorTextField.setText("0.001"); jConverErrorTextField.setBounds(88, 180, 45, 20); jConverErrorTextField.setHorizontalAlignment(SwingConstants.RIGHT); } { jInitialiseButton = new JButton(); jPanel.add(jInitialiseButton); jInitialiseButton.setText("Initialize"); jInitialiseButton.setBounds(25, 210, 110, 28); jInitialiseButton.addActionListener(this); jInitialiseButton.setActionCommand("Initialize"); } { jUpdateButton = new JButton(); jPanel.add(jUpdateButton); jUpdateButton.setText("Update"); jUpdateButton.setBounds(25, 250, 110, 28); jUpdateButton.setActionCommand("Update"); jUpdateButton.addActionListener(this); } { jStepButton = new JButton(); jPanel.add(jStepButton); jStepButton.setText("Step"); jStepButton.setBounds(25, 317, 110, 28); jStepButton.addActionListener(this); jStepButton.setActionCommand("Step"); } { jExecuteButton = new JButton(); jPanel.add(jExecuteButton); jExecuteButton.setText("Execute"); jExecuteButton.setBounds(25, 357, 110, 28); jExecuteButton.addActionListener(this); jExecuteButton.setActionCommand("Execute"); } // {// jCyclesLabel = new JLabel();// jPanel.add(jCyclesLabel);// jCyclesLabel.setText("Cycles");// jCyclesLabel.setBounds(49, 313, 35, 20);// }// {// jCyclesTextField = new JTextField();// jPanel.add(jCyclesTextField);// jCyclesTextField.setText("20");// jCyclesTextField.setBounds(89, 313, 29, 22);// } { jLabelSqSize = new JLabel(); jPanel.add(jLabelSqSize); jLabelSqSize.setText("Square Size"); jLabelSqSize.setBounds(20, 420, 70, 21); jLabelSqSize.setHorizontalAlignment(SwingConstants.RIGHT); } { sqSizeTextField = new JTextField(); jPanel.add(sqSizeTextField); sqSizeTextField.setText("40"); sqSizeTextField.setBounds(96, 421, 40, 20); sqSizeTextField.setHorizontalAlignment(SwingConstants.RIGHT); sqSizeTextField.addActionListener(this); } { jDelayLabel = new JLabel(); jPanel.add(jDelayLabel); jDelayLabel.setText("Delay(in ms)"); jDelayLabel.setBounds(22, 442, 70, 21); jDelayLabel.setHorizontalAlignment(SwingConstants.RIGHT); } { jDelayTextField = new JTextField(); jPanel.add(jDelayTextField); jDelayTextField.setText("0"); jDelayTextField.setBounds(96, 444, 40, 20); jDelayTextField.setHorizontalAlignment(SwingConstants.RIGHT); } { jValuesCheckBox = new JCheckBox(); jPanel.add(jValuesCheckBox); jValuesCheckBox.setText("Show Values"); jValuesCheckBox.setBounds(34, 536, 93, 21); jValuesCheckBox.setOpaque(false); jValuesCheckBox.setSelected(true); jValuesCheckBox.addActionListener(this); } { jPolicyCheckBox = new JCheckBox(); jPanel.add(jPolicyCheckBox); jPolicyCheckBox.setText("Show Policy"); jPolicyCheckBox.setBounds(34, 558, 85, 22); jPolicyCheckBox.setOpaque(false); jPolicyCheckBox.setSelected(true); jPolicyCheckBox.addActionListener(this); } { jRefreshButton = new JButton(); jPanel.add(jRefreshButton); jRefreshButton.setText("Refresh"); jRefreshButton.setBounds(26, 481, 110, 28); jRefreshButton.setActionCommand("Refresh"); jRefreshButton.addActionListener(this); } { jSeparator1 = new JSeparator(); jPanel.add(jSeparator1); jSeparator1.setBounds(161, 2, 4, jPanel.getBounds().height); jSeparator1.setBorder(BorderFactory.createTitledBorder( null, "", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("MS Sans Serif", 0, 11), new java.awt.Color(0, 0, 0))); } { jStatusLabel = new JLabel(); jPanel.add(jStatusLabel); jStatusLabel.setText("Load Maze First..."); jStatusLabel.setBounds(182, 14, 770, 34); jStatusLabel.setBackground(new java.awt.Color(192,192,192)); jStatusLabel.setBorder(BorderFactory.createTitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, new java.awt.Font("MS Sans Serif",0,11), new java.awt.Color(0,0,0))); jStatusLabel.setFont(new java.awt.Font("Georgia",1,12)); jStatusLabel.setDebugGraphicsOptions(DebugGraphics.NONE_OPTION); jStatusLabel.setOpaque(true); jStatusLabel.setHorizontalAlignment(SwingConstants.CENTER); jStatusLabel.setPreferredSize(new java.awt.Dimension(984, 35)); } } catch (Exception e) { e.printStackTrace(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -