/** 1 Add comments to the lines below indicating what each does 1a. add( textArea ); // adds ?? to ??? 1b. The codes '+event.getKeyText( event.getKeyCode() )' appears several times below. Add a comment at the first one explaining what it does. 2 2a. Comment out the line with the call to setDisabledTextColor() as one way to figure out what it does (or change the value of the parameter you send it), then add a comment explaining why it's called setDisabledTextColor? 2b. What other set..Color() method is there available for 3 Go to the java.awt.KeyListener documentation and look at all the methods that must be implemented by any class that 'implements' this interface. Does our class do this? What is the name of this class? 4 Go to the KeyEvent documentation and find out what else you can do with an instance of one. Experiment with this by adding code that uses what you found; add appropriate comment(s). */ import java.awt.Color; import java.awt.event.KeyListener; import java.awt.event.KeyEvent; import javax.swing.JFrame; import javax.swing.JTextArea; public class KeyDemo { public static void main(String args[]) { JFrame jf = new KeyDemoFrame(); jf.setSize(300,200); jf.setVisible(true); } } class KeyDemoFrame extends JFrame { private String line1,line2, line3; private JTextArea textArea; public KeyDemoFrame() { super( "Demonstrating Keystroke Events" ); textArea = new JTextArea( 10, 15 ); textArea.setText( "Press any key on the keyboard..." ); textArea.setEnabled( false ); textArea.setDisabledTextColor( Color.BLACK ); add( textArea ); //1a addKeyListener( new DemoKeyListener() ); } private class DemoKeyListener implements KeyListener { public void keyPressed( KeyEvent event ) { line1 = "Key pressed: " +event.getKeyText( event.getKeyCode() ); setLines2and3( event ); } public void keyReleased( KeyEvent event ) { line1 = "Key released: " +event.getKeyText( event.getKeyCode() ); setLines2and3( event ); } public void keyTyped( KeyEvent event ) { line1 = "Key typed: " +event.getKeyChar(); setLines2and3( event ); } private void setLines2and3( KeyEvent event ) { line2 = "This key is "; line2 += ( event.isActionKey() ? "" : "not " ); line2 += "an action key"; line3 = "Modifier keys pressed: "; String temp = event.getKeyModifiersText( event.getModifiers() ); line3 += ( temp.equals( "" ) ? "none" : temp ); textArea.setText( line1 +'\n' +line2 +'\n' +line3 ); } } }