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

📄 factualgui.java

📁 一个用Java编写的问答程序
💻 JAVA
字号:
package qa;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class FactualGUI extends JFrame implements ActionListener
{
	private JPanel controlPanel;
	private JPanel answerPanel;
	private JLabel questionLabel;
	private JButton hintButton;
	private JButton summitButton;
	private JTextArea answerArea;
	private FactualQuestion q;
	private FactualAnswer a;
	
	public FactualGUI()
	{
				
		Container container = getContentPane();
		
		//set Layout
		container.setLayout(new BorderLayout());
		
		//Control Panel setup
		controlPanel = new JPanel();
		controlPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
		
		hintButton = new JButton("help");
		hintButton.addActionListener(this);
		summitButton = new JButton("summit answer");
		summitButton.addActionListener(this);
		
		controlPanel.add(hintButton);
		controlPanel.add(summitButton);
		
		//Question setup
		questionLabel = new JLabel(q.ask());
		
		//set answer area
		answerArea = new JTextArea(3, 10);
		
		container.add(controlPanel, BorderLayout.SOUTH);
		container.add(questionLabel, BorderLayout.NORTH);
		container.add(answerArea, BorderLayout.CENTER);
	}
	
	public void actionPerformed(ActionEvent e)
	{
		if (e.getSource() == hintButton)
		{
			JOptionPane.showMessageDialog(null, q.getHint(), "Hint", JOptionPane.INFORMATION_MESSAGE);
		}
		
		else if (e.getSource() == summitButton)
		{
			answerArea.setEditable(false);
			if (a.checkAnswer(answerArea.getText()) == true)
			{
				JOptionPane.showMessageDialog(null, "Great!", "Hint", JOptionPane.INFORMATION_MESSAGE);
				
			}
		}
	}

}

⌨️ 快捷键说明

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