⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cifamainframe.java

📁 pl/0语言的词法分析器 cifaCifaMainFrame.java 主类 cifaCifaProcess.java 处理程序
💻 JAVA
字号:
package cifa;

import javax.swing.*;
import javax.swing.table.*;
import com.borland.jbcl.layout.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class CifaMainFrame
    extends JFrame {
  JButton jButton1 = new JButton();
  JTextField jTextField1 = new JTextField();
  JButton jButton2 = new JButton();
  JScrollPane jScrollPane1 = new JScrollPane();
  Object[][] rowData = new Object[100][3];
  Object[] colNames = {
      "SYM", "ID", "NUM"};
  JTable jTable1 = new JTable(rowData, colNames);
  JScrollPane jScrollPane2 = new JScrollPane();
  JTextArea jTextArea1 = new JTextArea();

  public CifaMainFrame() {
    try {
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    jButton1.setBounds(new Rectangle(23, 15, 157, 42));    jButton1.setToolTipText("Choose your source file");
    jButton1.setText("Choose Source File");
    jButton1.addActionListener(new CifaMainFrame_jButton1_actionAdapter(this));
    this.getContentPane().setLayout(null);
    jTextField1.setToolTipText("Here is your source file\'s path");
    jTextField1.setEditable(false);
    jTextField1.setText("Source File Path");    jTextField1.setBounds(new Rectangle(23, 62, 349, 29));
    jButton2.setBounds(new Rectangle(205, 15, 160, 41));    jButton2.setToolTipText("Analyse the source file");
    jButton2.setText("Process");
    jButton2.setVerticalAlignment(SwingConstants.CENTER);
    jButton2.addActionListener(new CifaMainFrame_jButton2_actionAdapter(this));
    this.addWindowListener(new CifaMainFrame_this_windowAdapter(this));
    this.setTitle("词法分析");
    jTextArea1.setText("Error Messages");
    jScrollPane2.setBounds(new Rectangle(8, 305, 383, 108));    jScrollPane1.setBounds(new Rectangle(8, 95, 381, 198));    this.getContentPane().add(jTextField1, null);
    this.getContentPane().add(jButton1, null);
    this.getContentPane().add(jButton2, null);
    this.getContentPane().add(jScrollPane1, null);
    this.getContentPane().add(jScrollPane2, null);
    jScrollPane2.getViewport().add(jTextArea1, null);
    jScrollPane1.getViewport().add(jTable1, null);
  }

  public static void main(String args[]) {
    CifaMainFrame frameInstance = new CifaMainFrame();
    frameInstance.setSize(400, 450);
    frameInstance.show();
  }

  void jButton1_actionPerformed(ActionEvent e) {
    FileDialog fd = new FileDialog(this, "Choose Source File");
    fd.show();
    String filePath = "";
    filePath = fd.getDirectory() + fd.getFile();
    jTextField1.setText(filePath);
  }

  void jButton2_actionPerformed(ActionEvent e) {
    for(int m=0;m<100;m++){
      jTable1.setValueAt("",m,0);
      jTable1.setValueAt("",m,1);
      jTable1.setValueAt("",m,2);
    }
    String filePath = "";
    filePath = jTextField1.getText();
    File sourceFile = new File(filePath);
    BufferedReader br;
    CifaProcess process = new CifaProcess();
    String inputString = "";
    boolean fileEnd = false;
    try {
      FileReader fr = new FileReader(sourceFile);
      br = new BufferedReader(fr);
      while (fileEnd == false) {
        inputString = br.readLine();
        if (inputString == null) {
          fileEnd = true;
          break;
        }
        process.getSYM(inputString);
      }
    }
    catch (Exception e1) {
      System.out.println("Exception Here:" + e);
    }
    //jTable1.setAutoResizeMode(1);
    int o=0,p=0;
    for (int i = 0; i < process.SYM.size(); i++) {
      jTable1.setValueAt(process.SYM.get(i), i, 0);
      if(process.SYM.get(i).equals("IDENT")){
        jTable1.setValueAt(process.ID.get(o), i, 1);
        o++;
      }
      if(process.SYM.get(i).equals("NUMBER")){
        jTable1.setValueAt(process.NUM.get(p), i, 2);
        p++;
      }
    }
    jTextArea1.setText("");
    for (int i = 0; i < process.errMessage.size(); i++) {
      jTextArea1.append(process.errMessage.get(i) + "\n");
    }
  }

  void this_windowClosing(WindowEvent e) {
    System.exit(0);
  }
}

class CifaMainFrame_jButton1_actionAdapter
    implements java.awt.event.ActionListener {
  CifaMainFrame adaptee;

  CifaMainFrame_jButton1_actionAdapter(CifaMainFrame adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
  }
}

class CifaMainFrame_jButton2_actionAdapter
    implements java.awt.event.ActionListener {
  CifaMainFrame adaptee;

  CifaMainFrame_jButton2_actionAdapter(CifaMainFrame adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButton2_actionPerformed(e);
  }
}

class CifaMainFrame_this_windowAdapter
    extends java.awt.event.WindowAdapter {
  CifaMainFrame adaptee;

  CifaMainFrame_this_windowAdapter(CifaMainFrame adaptee) {
    this.adaptee = adaptee;
  }

  public void windowClosing(WindowEvent e) {
    adaptee.this_windowClosing(e);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -