package exercise.engine; /** * FeebackModuleUI is class used to display hints and feedbacks. It displays buttons that * the user may manipulate submit answers, get hints, and receive feedback. */ import javax.swing.*; import java.awt.event.*; import java.awt.*; import java.net.*; public class FeedbackModuleUI extends JPanel { /** * This is the Construct Module that places the submit button, hint button, and text * feedback that the user sees. */ final static int SPACE = 10; final static int IMAGE_PANEL_X = 10; final static int IMAGE_PANEL_Y = 30; final static int IMAGE_PANEL_WIDTH = 16; final static int IMAGE_PANEL_HEIGHT = 16; final static int BACKGROUND_RED = 153; final static int BACKGROUND_GREEN = 204; final static int BACKGROUND_BLUE = 153; final static int TEXT_RED = 0; final static int TEXT_GREEN = 102; final static int TEXT_BLUE = 102; final static int TEXT_AREA_X = 40; final static int TEXT_AREA_Y = 15; final static int TEXT_AREA_HEIGHT = 70; final static int TEXT_AREA_WIDTH = 300 ; final static int JBUTTON_X = 350; final static int JBUTTON_Y = 25; final static int PIXEL_GAP = 15; final static int ATTENTION = 0; final static int CORRECT = 1; final static int INCORRECT = 2; protected JTextArea feedbackTextArea; protected JButton hintButton; protected JButton submitButton; protected ImageIcon submitDown; protected ImageIcon submitOff; protected ImageIcon submitRoll; protected ImageIcon submitUp; protected Image attention; protected Image correct; protected Image incorrect; protected ImagePanel imagePanel; FeedbackModuleUI ( JButton submitButton, ImageIcon submitDown, ImageIcon submitOff, ImageIcon submitRoll, ImageIcon submitUp, Image attention, Image correct, Image incorrect ) { this.submitButton = submitButton; this.submitDown = submitDown; this.submitOff = submitOff; this.submitDown = submitRoll; this.submitDown = submitUp; this.attention = attention; this.correct = correct; this.incorrect = incorrect; //Set the size setSize( 432, 100 ); //Set the Background color setBackground( new Color ( BACKGROUND_RED, BACKGROUND_GREEN, BACKGROUND_BLUE ) ); //Set the Layout setLayout ( new BulletinLayout () ); //add Feedback Icons imagePanel = new ImagePanel ( attention ); add ( imagePanel ); imagePanel.setBounds ( IMAGE_PANEL_X, IMAGE_PANEL_Y, IMAGE_PANEL_WIDTH, IMAGE_PANEL_HEIGHT ); //Create the feedback text feedbackTextArea = new JTextArea(); feedbackTextArea.setEditable ( false ); feedbackTextArea.setLineWrap ( true ); feedbackTextArea.setWrapStyleWord ( true ); feedbackTextArea.setText ( "Please enter an answer in the text field above.\nPlease enter an answer in the text field above.\nPlease enter an answer in the text field above." ); feedbackTextArea.setFont ( new Font("SansSerif", Font.PLAIN, 12)); feedbackTextArea.setForeground( new Color ( TEXT_RED, TEXT_GREEN, TEXT_BLUE ) ); feedbackTextArea.setBackground( new Color ( BACKGROUND_RED, BACKGROUND_GREEN, BACKGROUND_BLUE ) ); //Add the feedback text add( feedbackTextArea ); feedbackTextArea.setBounds ( TEXT_AREA_X, TEXT_AREA_Y, TEXT_AREA_WIDTH, TEXT_AREA_HEIGHT); //create the Submit Button submitButton.setRolloverIcon ( submitRoll ); submitButton.setPressedIcon ( submitDown ); submitButton.setDisabledIcon ( submitOff ); submitButton.setIcon( submitUp) ; //submitButton.setSelected ( true ); submitButton.setRolloverEnabled ( true ); //Takes border focus and filled painting for nice clean look. submitButton.setContentAreaFilled( false ); submitButton.setFocusPainted ( false ); submitButton.setBorderPainted (false ); //add the submit button to the display add ( submitButton ); submitButton.setLocation ( JBUTTON_X, JBUTTON_Y ); } public void setSubmitButtonImages ( ImageIcon submitDown, ImageIcon submitOff, ImageIcon submitRoll, ImageIcon submitUp ) { this.submitDown = submitDown; this.submitOff = submitOff; this.submitDown = submitRoll; this.submitDown = submitUp; submitButton.setRolloverIcon ( submitRoll ); submitButton.setPressedIcon ( submitDown ); submitButton.setDisabledIcon ( submitOff ); submitButton.setSelectedIcon ( submitUp ); } /*public void paint ( Graphics g ) { super.paint( g ); g.drawImage ( attention, 0,0,this ); }*/ }