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

📄 simpleframe.java

📁 国外的数据结构与算法分析用书
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;

/** A class to display a window on the console that requests user input.
    After the user has input a value, normal execution will continue. */
public class SimpleFrame extends Frame implements ActionListener
{
	private TextField myfield;
	private Label mylabel;

	/**	Constructor to create an object for an input window. */
	public SimpleFrame()
	{
		super("Basic input");
		setSize(200, 100);
		setLocation(150, 150);

		mylabel = new Label("Input a value");
		add("North", mylabel);

		myfield = new TextField();
		add("South", myfield);
		myfield.addActionListener(this);
	}

	/**	Continue execution after the user has entered a value into the
		window and hit return. */
	public synchronized void actionPerformed(ActionEvent e)
	{
		notify();
	}

	/**	Used to read an int value from the window. */
	public int readInt(String label)
	{
		return Integer.parseInt(readString(label));
	}

	/**	Used to read a double from the window. */
	public double readDouble(String label)
	{
		return Double.parseDouble(readString(label));
	}

	/**	Used to read a string from the window. */
	public synchronized String readString(String label)
	{
		mylabel.setText(label);
		myfield.setText("");
		setVisible(true);
		try
		{
			wait();
		} catch (InterruptedException e) {} // do nothing
		setVisible(false);
		return myfield.getText();
	}
}

⌨️ 快捷键说明

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