5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 test 26 @bug 6190768 6190778 27 @summary Tests that triggering events on AWT list by pressing CTRL + HOME, CTRL + END, PG-UP, PG-DOWN similar Motif behavior 28 @author Dmitry.Cherepanov@SUN.COM area=awt.list 29 @library /test/lib 30 @build jdk.test.lib.Platform 31 @run applet KeyEventsTest.html 32 */ 33 34 /** 35 * KeyEventsTest.html 36 * 37 * summary: 38 */ 39 40 import java.applet.Applet; 41 import java.awt.*; 42 import java.awt.event.*; 43 import java.util.Set; 44 import java.lang.reflect.*; 45 46 import jdk.test.lib.Platform; 47 48 public class KeyEventsTest extends Applet implements ItemListener, FocusListener, KeyListener 49 { 50 TestState currentState; 51 final Object LOCK = new Object(); 52 final int ACTION_TIMEOUT = 500; 53 54 List single = new List(3, false); 55 List multiple = new List(3, true); 56 57 Panel p1 = new Panel (); 58 Panel p2 = new Panel (); 59 60 public void init() 61 { 62 setLayout (new BorderLayout ()); 63 64 single.add("0"); 65 single.add("1"); 66 single.add("2"); 67 single.add("3"); 68 single.add("4"); 69 single.add("5"); 70 single.add("6"); 71 single.add("7"); 72 single.add("8"); 73 74 multiple.add("0"); 75 multiple.add("1"); 76 multiple.add("2"); 77 multiple.add("3"); 78 multiple.add("4"); 79 multiple.add("5"); 83 84 single.addKeyListener(this); 85 single.addItemListener(this); 86 single.addFocusListener(this); 87 p1.add(single); 88 add("North", p1); 89 90 multiple.addKeyListener(this); 91 multiple.addItemListener(this); 92 multiple.addFocusListener(this); 93 p2.add(multiple); 94 add("South", p2); 95 96 }//End init() 97 98 public void start () 99 { 100 101 try{ 102 setSize (200,200); 103 setVisible(true); 104 validate(); 105 106 main(null); 107 108 } catch (Exception e) { 109 e.printStackTrace(); 110 throw new RuntimeException("The test failed."); 111 } 112 113 }// start() 114 115 private void main(String[] args) 116 throws InterruptedException, InvocationTargetException { 117 118 doTest(); 119 120 System.out.println("Test passed."); 121 } 122 123 public void itemStateChanged (ItemEvent ie) { 124 System.out.println("itemStateChanged-"+ie); 125 this.currentState.setAction(true); 126 } 127 128 public void focusGained(FocusEvent e){ 129 130 synchronized (LOCK) { 131 LOCK.notifyAll(); 132 } 133 134 } 135 136 public void focusLost(FocusEvent e){ 137 } 138 139 public void keyPressed(KeyEvent e){ 140 System.out.println("keyPressed-"+e); 141 } 142 | 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 @test 26 @key headful 27 @bug 6190768 6190778 28 @summary Tests that triggering events on AWT list by pressing CTRL + HOME, 29 CTRL + END, PG-UP, PG-DOWN similar Motif behavior 30 @library /test/lib 31 @build jdk.test.lib.Platform 32 @run main KeyEventsTest 33 */ 34 35 import java.awt.*; 36 import java.awt.event.*; 37 import java.lang.reflect.*; 38 39 import jdk.test.lib.Platform; 40 41 public class KeyEventsTest extends Frame implements ItemListener, FocusListener, KeyListener 42 { 43 TestState currentState; 44 final Object LOCK = new Object(); 45 final int ACTION_TIMEOUT = 500; 46 47 List single = new List(3, false); 48 List multiple = new List(3, true); 49 50 Panel p1 = new Panel (); 51 Panel p2 = new Panel (); 52 53 public static void main(final String[] args) { 54 KeyEventsTest app = new KeyEventsTest(); 55 app.init(); 56 app.start(); 57 } 58 59 public void init() 60 { 61 setLayout (new BorderLayout ()); 62 63 single.add("0"); 64 single.add("1"); 65 single.add("2"); 66 single.add("3"); 67 single.add("4"); 68 single.add("5"); 69 single.add("6"); 70 single.add("7"); 71 single.add("8"); 72 73 multiple.add("0"); 74 multiple.add("1"); 75 multiple.add("2"); 76 multiple.add("3"); 77 multiple.add("4"); 78 multiple.add("5"); 82 83 single.addKeyListener(this); 84 single.addItemListener(this); 85 single.addFocusListener(this); 86 p1.add(single); 87 add("North", p1); 88 89 multiple.addKeyListener(this); 90 multiple.addItemListener(this); 91 multiple.addFocusListener(this); 92 p2.add(multiple); 93 add("South", p2); 94 95 }//End init() 96 97 public void start () 98 { 99 100 try{ 101 setSize (200,200); 102 validate(); 103 setUndecorated(true); 104 setLocationRelativeTo(null); 105 setVisible(true); 106 107 doTest(); 108 System.out.println("Test passed."); 109 } catch (Exception e) { 110 e.printStackTrace(); 111 throw new RuntimeException("The test failed."); 112 } 113 114 }// start() 115 116 public void itemStateChanged (ItemEvent ie) { 117 System.out.println("itemStateChanged-"+ie); 118 this.currentState.setAction(true); 119 } 120 121 public void focusGained(FocusEvent e){ 122 123 synchronized (LOCK) { 124 LOCK.notifyAll(); 125 } 126 127 } 128 129 public void focusLost(FocusEvent e){ 130 } 131 132 public void keyPressed(KeyEvent e){ 133 System.out.println("keyPressed-"+e); 134 } 135 |