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

📄 prepanel.java

📁 编译原理中的LR[0]算法
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.*;

import javax.swing.*;

public class PREPanel extends JPanel implements ActionListener{
	String inter;
	String s="";
	JTextArea textarea;
	JTextField textfield;
	String temp="";
	Vector<String> vector;
	public PREPanel(PREFrame f){
		setLayout(new FlowLayout());
		textfield=new JTextField(50);
		vector=new Vector<String>();
		JButton fcfs=new JButton("LR(0)分析");
		JButton earser=new JButton("清除");
		Font font=new Font("DialogInput",Font.BOLD+Font.ITALIC,17);
		textfield.setFont(font);
		add(textfield);
		add(fcfs);
		add(earser);
		fcfs.setForeground(Color.PINK);
		earser.setForeground(Color.RED);
		fcfs.addActionListener(this);
		earser.addActionListener(this);
		textarea=f.textarea;
	}

	public void actionPerformed(ActionEvent arg0) {
		if(arg0.getActionCommand().equals("LR(0)分析")){
			try{
				temp=textfield.getText();
				for(int i=0;i<temp.length();i++){
					vector.add(temp.substring(i,i+1));
				}
				Function t=new Function();
				t.function(vector);
				FileReader fr=new FileReader("Result.txt");
				BufferedReader br=new BufferedReader(fr);
				while((inter=br.readLine())!=null){
					s+=inter+"\n";
				}
				textarea.setForeground(Color.BLACK);
				textarea.setFont(new Font("DialogInput",Font.BOLD+Font.ITALIC,17));
				textarea.setText(s);
				fr.close();
				vector.removeAllElements();
				s="";
			}catch(Exception e){
				e.printStackTrace();
			}
		}

		if(arg0.getActionCommand().equals("清除")){
			try{
				textarea.setText("");
				textfield.setText("");
			}catch(Exception e){
				e.printStackTrace();
			}
		}
	}
}

⌨️ 快捷键说明

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