This code should increment the variable bCount every time the B key is pressed. Find the error(s) in the following code, assuming that bCount and outputJTextArea are declared as an int and a JTextArea, respectively.

```
1 private void outputJTextAreaKeyPressed( KeyEvent event)
2 {
3 // receive code for key pressed by user
4 switch ( event.KeyCode() )
5 {
6 case VK_B: // B key
7 bCount++;
8 break;
9 }
10
11 } // end event handler outputJTextAreaKeyPressed
```


The switch statement should use method getKeyCode of class KeyEvent as its controlling expression, not KeyCode. The case label should use KeyEvent.VK_B as its test expression, not just VK_B.
```
1 private void outputJTextAreaKeyPressed( KeyEvent event)
2 {
3 // receive code for key pressed by user
4 switch ( event.getKeyCode() )
5 {
6 case KeyEvent.VK_B: // B key
7 bCount++;
8 break;
9 }
10
11 } // end event handler outputJTextAreaKeyPressed
```

Computer Science & Information Technology

You might also like to view...

Why does a shell process terminate when you presses at the beginning of a new line?

What will be an ideal response?

Computer Science & Information Technology

The OS X backup utility is called Time Machine

Indicate whether the statement is true or false

Computer Science & Information Technology

Loops help reduce the size of scripts making them easier to develop and maintain.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

To divide one table cell into two columns, use the ____ command.

A. Divide Cells B. Distribute Columns C. Split Cells D. Insert Cells

Computer Science & Information Technology