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

📄 myframe.java

📁 该程序可将一个四则混合运算分解成一组四元式指令。
💻 JAVA
字号:
/**
 * 该类构造一个输入输出界面
 * 
 */
package ex2;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.util.LinkedList;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

/**
 * @author 阿赞
 *
 */
public class MyFrame {

	private JPanel jPanel = null;  //  @jve:decl-index=0:visual-constraint="104,14"
	private JPanel jPanel1 = null;
	private JPanel jPanel2 = null;
	private JLabel jLabel = null;
	private JTextField jTextField = null;
	private JButton jButton = null;
	private JLabel jLabel1 = null;
	private JScrollPane jScrollPane = null;
	private JTextArea jTextArea = null;
	private JButton jButton1 = null;
	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	public JPanel getJPanel() {
		if (jPanel == null) {
			jPanel = new JPanel();
			jPanel.setLayout(new BorderLayout());
			jPanel.setSize(new Dimension(473, 324));
			jPanel.add(getJPanel1(), BorderLayout.NORTH);
			jPanel.add(getJPanel2(), BorderLayout.CENTER);
		}
		return jPanel;
	}

	/**
	 * This method initializes jPanel1	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
			gridBagConstraints2.fill = GridBagConstraints.BOTH;
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.fill = GridBagConstraints.BOTH;
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.fill = GridBagConstraints.BOTH;
			gridBagConstraints.weightx = 1.0;
			jLabel = new JLabel();
			jLabel.setText("表达式:");
			jLabel.setHorizontalAlignment(SwingConstants.CENTER);
			jLabel.setHorizontalTextPosition(SwingConstants.CENTER);
			jLabel.setBackground(Color.yellow);
			jLabel.setOpaque(true);
			jLabel.setPreferredSize(new Dimension(80, 30));
			jPanel1 = new JPanel();
			jPanel1.setLayout(new GridBagLayout());
			jPanel1.add(jLabel, gridBagConstraints1);
			jPanel1.add(getJTextField(), gridBagConstraints);
			jPanel1.add(getJButton(), gridBagConstraints2);
			jPanel1.add(getJButton1(), new GridBagConstraints());
		}
		return jPanel1;
	}

	/**
	 * This method initializes jPanel2	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel2() {
		if (jPanel2 == null) {
			jLabel1 = new JLabel();
			jLabel1.setText("    四元式如下所示:");
			jLabel1.setBackground(Color.yellow);
			jLabel1.setOpaque(true);
			jLabel1.setPreferredSize(new Dimension(60, 30));
			jPanel2 = new JPanel();
			jPanel2.setLayout(new BorderLayout());
			jPanel2.add(jLabel1, BorderLayout.NORTH);
			jPanel2.add(getJScrollPane(), BorderLayout.CENTER);
		}
		return jPanel2;
	}

	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setPreferredSize(new Dimension(4, 30));
			jTextField.setFont(new Font("\u65b0\u5b8b\u4f53", Font.BOLD, 24));
			jTextField.setColumns(40);
		}
		return jTextField;
	}

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setAction(new AbstractAction(){

	public void actionPerformed(ActionEvent arg0) {//确定按钮jButton的事件响应处理
		Object obj = arg0.getSource();
		if(obj == jButton) {
			jTextArea.setText("");//清空文本域jTextArea
			String str = GetText();//获取表达式
			EX2 ex2 = new EX2(str);//创建EX2类对象,表达式作为实参
			LinkedList list = new LinkedList();//创建LinkedList类对象,用于存放表达式生成的所有四元式
			list = ex2.Get_list();//获取表达式生成的四元式
			for(int i = 0;i < list.size();i++) {//显示表达式对应的所有四元式
				String string = (String)list.get(i);//获取第i个四元式
				SetText(string);//在文本域jTextArea中显示第i个四元式
			}
		}
	}});
			jButton.setText("确定");
			jButton.setPreferredSize(new Dimension(60, 30));
		}
		return jButton;
	}

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			//jScrollPane.setEnabled(false);
			jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
			jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
			jScrollPane.setViewportView(getJTextArea());
			jScrollPane.setBorder(null);
		}
		return jScrollPane;
	}

	/**
	 * This method initializes jTextArea	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	private JTextArea getJTextArea() 
		{
			if (jTextArea == null) 
			{
				jTextArea = new JTextArea();
				jTextArea.setColumns(0);
				jTextArea.setEditable(false);
				jTextArea.setEnabled(true);
				jTextArea.setLineWrap(false);
				jTextArea.setWrapStyleWord(false);
				jTextArea.setFont(new Font("\u65b0\u5b8b\u4f53", Font.BOLD, 36));
				jTextArea.setRows(10);
			}
			return jTextArea;
	}
	

	/**
	 * This method initializes jButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setAction(new AbstractAction(){

	public void actionPerformed(ActionEvent arg0) {//清空按钮jButton1的事件响应处理
		Object obj = arg0.getSource();
		if(obj == jButton1) {
			jTextField.setText("");//清空文本框jTextField
			jTextArea.setText("");//清空文本域jTextArea
		}
	}});
			jButton1.setActionCommand("");
			jButton1.setPreferredSize(new Dimension(60, 30));
			jButton1.setText("清空");
		}
		return jButton1;
	}
	

	public String GetText() {//获取文本框jTextField中的表达式
		return jTextField.getText();
	}
	public void SetText(String str) {//将四元式输出到文本域jTextArea中
		jTextArea.append(str+"\n");
	}

}

⌨️ 快捷键说明

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