資源簡(jiǎn)介
設(shè)計(jì)一個(gè)圖靈機(jī)M,用于判定接收符合如下條件的字符串
C={aibjckdx}subject to i× j×k = x&i, j,k,x ≥1
代碼片段和文件信息
import?java.awt.FlowLayout;
import?java.awt.GridBagConstraints;
import?java.awt.GridBagLayout;
import?java.awt.event.MouseAdapter;
import?java.awt.event.MouseEvent;
import?java.util.ArrayList;
import?java.util.Scanner;
import?javax.swing.JButton;
import?javax.swing.Jframe;
import?javax.swing.JPanel;
import?javax.swing.JScrollPane;
import?javax.swing.JTextArea;
import?javax.swing.JTextField;
public?class?TM_abcd?{
public?static?String?NEW_LINE?=?“\n“;
public?static?void?main(String[]?args)?{
TM_abcd?tm?=?new?TM_abcd();
Jframe?frame?=?new?Jframe(“CFGtoCNF“);
frame.setSize(1100?540);
JPanel?panel?=?new?JPanel();
panel.setLayout(new?GridBagLayout());
JTextArea?jTextArea?=?new?JTextArea(20?40);
JTextArea?jTextAreaResult?=?new?JTextArea(20?40);
jTextAreaResult.setEditable(false);
JScrollPane?jScrollPane?=?new?JScrollPane(jTextAreaResult);
jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JTextField?leftField?=?new?JTextField();
leftField.setText(“Input“);
leftField.setHorizontalAlignment(JTextField.CENTER);
leftField.setEditable(false);
JTextField?rightField?=?new?JTextField();
rightField.setText(“Output“);
rightField.setHorizontalAlignment(JTextField.CENTER);
rightField.setEditable(false);
JButton?buttonConvert?=?new?JButton(“Judge“);
JButton?btnClearLeft?=?new?JButton(“Clear“);
buttonConvert.addMouseListener(new?MouseAdapter()?{
@Override
public?void?mouseClicked(MouseEvent?e)?{
//?TODO?Auto-generated?method?stub
String[]?lines?=?jTextArea.getText().split(NEW_LINE);
if?(lines.length?>?0)?{
jTextAreaResult.setText(““);
for?(String?s?:?lines)?{
if?(s.endsWith(“#“))?{
tm.reset();
// int?temp?=?s.indexOf(“a“);
// if?(temp?!=?-1)?{
// s?=?s.replaceFirst(“a“?“W“);
// tm.checkA(s?1);
// }
tm.checkA(s?0);
jTextAreaResult.append(tm.getResult()+NEW_LINE);
}else?{
jTextAreaResult.append(“Miss?#?at?the?end?of?string“+NEW_LINE);
}
}
}
}
});
btnClearLeft.addMouseListener(new?MouseAdapter()?{
@Override
public?void?mouseClicked(MouseEvent?e)?{
//?TODO?Auto-generated?method?stub
super.mouseClicked(e);
jTextAreaResult.setText(““);
jTextArea.setText(““);
}
});
GridBagConstraints?constraints?=?new?GridBagConstraints();
constraints.fill?=?GridBagConstraints.BOTH;
constraints.gridx?=?0;
constraints.gridy?=?0;
constraints.weightx?=?1;
constraints.weighty?=?1;
panel.add(leftField?constraints);
constraints.gridx?=?1;
constraints.gridy?=?0;
constraints.weighty?=?1;
constraints.weightx?=?1;
panel.add(rightField?constraints);
constraints.gridx?=?0;
constraints.gridy?=?1;
constraints.weighty?=?3;
panel.add(jTextArea?constraints);
constraints.gridx?=?1;
constraints.gridy?=?1;
constraints.weighty?=?3;
panel.add(jScrollPane?constraints);
constraints.gridx?=?0;
constraints.gridy?=?2;
con
評(píng)論
共有 條評(píng)論