?? mainboard.java
字號:
package ui;
import logic.DFA;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class MainBoard extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
public static JTextArea filePathText;
public static JTextArea checkText;
JTextArea infoText;
JButton fileChooseButton, checkButton;
JFileChooser fc;
JPanel filePanel, checkPanel, infoPanel;
static String arg;
public static String trace;
/*these are the design of my frame*/
public MainBoard() {
Container container = getContentPane();
container.setLayout(null);
fileChooseButton = new JButton("choose");
checkButton = new JButton("check");
filePathText = new JTextArea();
filePathText.setEditable(false);
checkText = new JTextArea();
infoText = new JTextArea();
filePanel = new JPanel();
filePanel.setSize(450, 100);
filePanel.setLocation(10, 10);
filePanel.setBorder(BorderFactory
.createTitledBorder("Please choose a dfa file:"));
filePanel.setLayout(null);
filePanel.add(filePathText);
filePathText.setSize(200, 50);
filePathText.setLocation(20, 30);
filePanel.add(fileChooseButton);
fileChooseButton.setSize(80, 40);
fileChooseButton.setLocation(300, 35);
checkPanel = new JPanel();
checkPanel.setSize(450, 100);
checkPanel.setLocation(10, 130);
checkPanel.setBorder(BorderFactory
.createTitledBorder("Please input a string to check:"));
checkPanel.setLayout(null);
checkPanel.add(checkText);
checkText.setSize(200, 50);
checkText.setLocation(20, 30);
checkPanel.add(checkButton);
checkButton.setSize(80, 40);
checkButton.setLocation(300, 35);
infoPanel = new JPanel();
infoPanel.setSize(450, 200);
infoPanel.setLocation(10, 250);
infoPanel.setBorder(BorderFactory
.createTitledBorder("The trace information:"));
infoPanel.setLayout(null);
infoPanel.add(infoText);
infoText.setSize(400, 150);
infoText.setLocation(20, 30);
infoText.setLineWrap(true);
infoText.setWrapStyleWord(true);
container.add(filePanel);
container.add(checkPanel);
container.add(infoPanel);
fileChooseButton.addActionListener(this);
checkButton.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
//get the file path
if (e.getSource() == fileChooseButton) {
fc = new JFileChooser();
fc.setCurrentDirectory(new File("./src/dfa.dat"));
int intRetVal = fc.showOpenDialog(this);
if (intRetVal == JFileChooser.APPROVE_OPTION) {
filePathText.setText(fc.getSelectedFile().getPath());
}
}
//check the input string
if (e.getSource() == checkButton) {
new DFA();
if (arg.equals("gettrace")) {
infoText.setText(trace);
} else {
infoText
.setText("You have not select to give the trace in the command line!");
}
}
}
public static void main(String args[]) {
//get the command-line argument
if (args.length > 0) {
arg = args[0];
} else {
arg = "";
}
MainBoard mainBoard = new MainBoard();
mainBoard.setDefaultCloseOperation(EXIT_ON_CLOSE);
mainBoard.setSize(500, 500);
mainBoard.setResizable(false);
mainBoard.setLocation(300, 200);
mainBoard.setTitle("FsPro2----The simulation of DFA");
mainBoard.setVisible(true);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -