inputframe.java

来自「一个C语言子集的编译器」· Java 代码 · 共 69 行

JAVA
69
字号
package com.king4solomon.homework.compiler.pvm;

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

import com.king4solomon.homework.compiler.gui.*;

@SuppressWarnings("serial")
public class InputFrame extends JFrame implements ActionListener {
	public InputFrame(String type) {
		super("Input a "+type);
		/**
		 * 用于获取屏幕尺寸以规定默认的显示位置
		 */
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize = kit.getScreenSize();

		setSize(300, 100);
		setLocation(screenSize.width / 3, screenSize.height / 3);

		JPanel pane = new JPanel();
		input.setPreferredSize(new Dimension(260, 20));
		JPanel pane1 = new JPanel();
		pane1.setSize(20, 20);

		JPanel pane2 = new JPanel();
		pane2.setSize(20, 20);
		pane.add(input, BorderLayout.CENTER);
		pane.add(button, BorderLayout.SOUTH);
		pane.add(pane1, BorderLayout.EAST);
		pane.add(pane2, BorderLayout.WEST);
		button.addActionListener(this);
		add(pane);
		setVisible(true);
	}


	@SuppressWarnings("deprecation")
	public void actionPerformed(ActionEvent e) {
		if (e.getSource().equals(button)) {
			buf = input.getText();
			input.setText("");
			if (Interpreter.isDebug)
				HandoutFrame.tb10.setEnabled(true);
			thr.resume();
			dispose();
		}
	}

	public static String getValue() {
		return input.getText();
	}

	public static void setThread(Thread t) {
		thr = t;
	}

	public String buf = new String();

	public static Thread thr;

	public static JTextArea input = new JTextArea();

	public static JButton button = new JButton("Input");

}

⌨️ 快捷键说明

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