... line1 = String.format("Key typed: %s", event.getKeyChar());
53         setLines2and3(event); // set output lines two and three
54      }
55
56      // set second and third lines of output
57      private void setLines2and3(KeyEvent event)
58      {
59         line2 = String.format("This key is %san action key",
60           (event.isActionKey() ? "" : "not "));
61
62         String temp = KeyEvent.getKeyModifiersText(event.getModifiers());
63
64         line3 = String.format("Modifier keys pressed: %s",
65            (temp.equals("") ? "none" : temp)); // output modifiers
66
67         textArea.setText(String.format("%s\n%s\n%s\n",
68            line1, line2, line3)); // output three lines of text
69      }
70   }

Fig. 26.37 Testing KeyDemoFrame.

 1   // Fig. 26.37: KeyDemo.java
 2   // Testing KeyDemoFrame.
 3   import javax.swing.JFrame;
 4
 5

Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.