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

📄 guioutput.java

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

/**	This class is used to display a small window that has a specific title and contents.
	When new text is to be displayed in the window, the normal execution of the calling program
	is halted until the button on the interface is clicked. */
public class GuiOutput extends JFrame implements ActionListener
{
	JTextArea textArea;
	JButton continueBtn;

	/**	The constructor that is used to initialize the graphical components, and place them
		in the correct locations on the interface. */
	public GuiOutput()
	{
		textArea = new JTextArea(8, 30);
		JScrollPane scrollPane = new JScrollPane(textArea,
				JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
				JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		JPanel panel = new JPanel();
		continueBtn = new JButton("Continue Executing Program");

		continueBtn.addActionListener(this);
		setResizable(false); // window is a fixed size
		textArea.setEditable(false); // can't edit output area

		panel.setLayout(new FlowLayout(FlowLayout.CENTER));
		panel.add(continueBtn);
		getContentPane().setLayout(new BorderLayout());
		getContentPane().add(scrollPane, BorderLayout.CENTER);
		getContentPane().add(panel, BorderLayout.SOUTH);
		setLocation(150, 150); // display window to the right and down
		setSize(328, 220);
	}

	/**	Used to display messages on the output window.  This method is synchronized so normal
		flow of the application is suspended until the button on the interface is clicked. */
	public synchronized void displayOutput(String output, String windowTitle)
	{
		setTitle(windowTitle);
		textArea.setText(output);
		setVisible(true); // display window
		try
		{
			wait();
		} catch (InterruptedException e) {} // do nothing
	}

	/**	This method is called when the button is clicked.  It causes the normal flow of
		execution for the program to resume. */
	public synchronized void actionPerformed(ActionEvent ae)
	{
		notify(); // resume execution
		setVisible(false); // hide window
	}
}

⌨️ 快捷键说明

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