June 2017
Beginner
1296 pages
69h 23m
English
... 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 }
KeyDemoFrame.
1 // Fig. 26.37: KeyDemo.java
2 // Testing KeyDemoFrame.
3 import javax.swing.JFrame;
4
5Read now
Unlock full access