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

/**
 * QuestionGUI will demonstrate how to create a pop up window where
 * users enter their name, answer a question, and a response.
 * 
 * GUI -stands for Graphical User Interface
 * 
 * @author Kathryn McKinley
 * @version April, 2007
 * 
 * 1) Input a string, showing how ActionEvent works
 * 2) 
 */
public class QuestionGUI implements ActionListener {
    // constants
    // screen dimensions
    private static final int WINDOW_WIDTH  = 500;  //pixels
    private static final int WINDOW_HEIGHT = 185; //pixels
    private static final int TEXT_WIDTH    = 40; // characters
    
    // specifies how to layout the parts of the GUI (more on this later)
    private static final FlowLayout LAYOUT_STYLE = new FlowLayout();
    
    // instance variables
    // Make a window with a title - just one ever
    private JFrame window = new JFrame("Question GUI");
    
    // user entry area for name
    private JLabel nameTag = new JLabel ("Enter your name:");
    private JTextField nameText = new JTextField(TEXT_WIDTH); 

    
/*    private static final String QUESTION = "Wyatt loves girls. \n True or False?";

    private static final String TRESPONSE = "Correct! ";
    private static final String FRESPONSE = "You need to think about it some more. ";

    // question area
    private JTextArea questionArea = new JTextArea(QUESTION, 2, TEXT_WIDTH);
 
    // user selects one of true or false 
    // with radio buttons, you can only select one
    private JRadioButton trueButton  = new JRadioButton("true");
    private JRadioButton falseButton = new JRadioButton("false");   
    private ButtonGroup trueFalseButtons = new ButtonGroup();

    // Response Text
    private JTextArea responseArea = new JTextArea("", 2, TEXT_WIDTH);
    
    // Enter button
    private JButton enterButton = new JButton("Enter");
*/   

     
    /**
     * Constructor for objects of class QuestionGUI
     *    configures the GUI
     */
    public QuestionGUI()
    {
        // register the listner
        nameText.addActionListener(this);
        
        // window size and exit 
        window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // arrange compoents in GUI
        window.setLayout(LAYOUT_STYLE);
        
        window.add(nameTag);
        window.add(nameText);
        
/*        
        // question area settings
        questionArea.setEditable(false);
        questionArea.setLineWrap(true);
        questionArea.setWrapStyleWord(true);
        questionArea.setBackground(Color.pink); 
  
        // put the buttons in a collection
        trueFalseButtons.add(trueButton);
        trueFalseButtons.add(falseButton);     
        
        window.add(questionArea);
        
        window.add(trueButton);
        window.add(falseButton);        
        window.add(enterButton);       
        window.add(responseArea);
 */      
        window.setVisible(true);
    }
    
    /**
     * event button handler code - this acts once the user selects the enter button
     * 
     * @param  user event
     */
    public void actionPerformed (ActionEvent e) 
    {
        String name = nameText.getText();
        System.out.println("We got an event! You put in: " + name);

/*        
        // Use the response according to the button selection
        if (trueButton.isSelected()) {
            responseArea.setText(TRESPONSE + name);
        } else if (falseButton.isSelected()) {
            responseArea.setText(FRESPONSE + name);
        } else {
            responseArea.setText("Please select true or false");
        }
*/    
    }
    public static void main(String[] args) {
        QuestionGUI question = new QuestionGUI();   
    }
}
