资源简介
Myeclipse 实现的自上而下算法,生成的界面简单易于运行
代码片段和文件信息
package 编译原理实验;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Stack;
import java.util.StringTokenizer;
public class Testh extends Jframe implements ActionListener {
private static final long serialVersionUID = 1L;
private JButton beginButton = new JButton(“运行“);
private JButton cleanButton = new JButton(“清空“);
private JLabel inLabel = new JLabel(“输入代码“);
private JLabel beginButton6 = new JLabel(“分析结果“);
Font fon = new Font(“Dialog“ Font.PLAIN 18);
private static TextArea inTextArea = new TextArea(17 30);
private static TextArea outTextArea = new TextArea(17 30);
private JPanel pane = new JPanel();
private static String s1 = new String();
static String input=““;
// 布局管理器
void buildConstraints(GridBagConstraints gbc int gx int gy int gw
int gh int wx int wy) {
gbc.gridx = gx;
gbc.gridy = gy;
gbc.gridwidth = gw;
gbc.gridheight = gh;
gbc.weightx = wx;
gbc.weighty = wy;
}
// 布局键面
private void setMyPane() {
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
pane.setLayout(gridbag);
buildConstraints(constraints 0 0 1 1 25 5);
constraints.fill = GridBagConstraints.VERTICAL;
gridbag.setConstraints(inLabel constraints);
pane.add(inLabel);
buildConstraints(constraints 1 0 1 1 25 0);
gridbag.setConstraints(beginButton constraints);
pane.add(beginButton);
buildConstraints(constraints 0 1 2 3 25 90);
gridbag.setConstraints(inTextArea constraints);
inTextArea.setFont(fon);
pane.add(inTextArea);
buildConstraints(constraints 2 1 2 3 0 0);
gridbag.setConstraints(outTextArea constraints);
outTextArea.setFont(fon);
pane.add(outTextArea);
buildConstraints(constraints 2 0 1 1 25 0);
gridbag.setConstraints(cleanButton constraints);
pane.add(cleanButton);
buildConstraints(constraints 3 0 1 1 25 0);
gridbag.setConstraints(beginButton6 constraints);
pane.add(beginButton6);
setLocation(200 80);
setContentPane(pane);
}
// 添加事件监听器
private void initListener() {
ActListener actListener = new ActListener();
beginButton.addActionListener(actListener);
cleanButton.addActionListener(actListener);
}
// 构建事件监听器
class ActListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == beginButton) {
porRun();
}
if (e.getSource() == cleanButton) {
inTextArea.setText(““);
outTextArea.setText(““);
}
}
}
private void porRun() // 分析过程
{
String inText = inTextArea.getText();
int j = 1;
StringTokenizer str1 = new StringTokenizer(inText
“ \n\t\r;+=-\“\‘)(}{][<>!“ true);
int n = str1.countTokens();
String[] intext = new String[str1.countTokens()];
for (int a = 0; a < n; a++) {
intext[a] = str1.nextToken();
}
outTextArea.setSize(1000 1000);
outTextArea.appen
评论
共有 条评论