Other | Other |
---|---|
1.1.8 1.1.8Fixed | 1.2.2Fixed |
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
Name: mf23781 Date: 09/17/98 *Symptoms: Upon testing the supplied code I found that the problem occurs on Solaris with JDK1.1.6 and AIX JDK1.1.6 but works OK on WinNT with JDK 1.1.6 The keyEvent methods e.g. isAltDown, isControlDown, isShiftDown do not work, except on Windows platforms. Applet and html provided below, I've also created an Application version. *Test case: //------------------------------------------------------------------------------------------------------------------------------------ // html file keyTest.html follows: // <APPLET CODE=keyTest.class WIDTH=350 HEIGHT=350> </APPLET> //------------------------------------------------------------------------------------------------------------------------------------ // applet code keyTest.java follows: // import java.awt.*; import java.applet.*; import java.awt.event.ActionListener; import java.awt.event.*; public class keyTest extends Applet implements KeyListener{ TextArea ta; TextField tf; String theText; public void init(){ setFont(new Font("Dialog",Font.PLAIN,12)); ta = new TextArea(8,30); tf = new TextField(30); tf.addKeyListener(this); ta.addKeyListener(this); // ta.setText("Hello"); // tf.setText("abcThere4567"); add(ta); add(tf); setBackground(Color.white); } public void keyTyped(KeyEvent e) { } public void keyReleased(KeyEvent e) { } public void keyPressed(KeyEvent evt) { char keyChar = evt.getKeyChar(); System.out.println("Key typed = " + keyChar); if ( evt.isShiftDown() ) { System.out.println("Modifier: Shift key is down"); } if ( evt.isControlDown()) { System.out.println("Modifier: Control key is down"); } if ( evt.isAltDown() ) { System.out.println("Modifier: Alt key is down"); } if ( evt.isMetaDown() ) { System.out.println("Modifier: Meta key is down"); } } private void handleEnter() { System.out.println("Enter key pressed!!"); } public void paint(Graphics g) { g.drawString("Use the alt or shift or ctrl modifier key when typing.",10,200); g.drawString("Modifier only works with some keys (backspace is one)", 10,220); } public void start() { } } //------------------------------------------------------------------------------------------------------------------------------------ // Application version keyTest2.java follows: // import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.*; public class keyTest2 extends Frame implements KeyListener{ TextArea ta; TextField tf; String theText; public void init(){ setLayout(new GridLayout(0,1)); setFont(new Font("Dialog",Font.PLAIN,12)); ta = new TextArea(8,30); tf = new TextField(30); tf.addKeyListener(this); ta.addKeyListener(this); // ta.setText("Hello"); // tf.setText("abcThere4567"); add(ta); add(tf); setBackground(Color.white); setSize(400,200); } public static void main(String[] args) { keyTest2 kt2 = new keyTest2(); kt2.init(); kt2.show(); } public void keyTyped(KeyEvent e) { } public void keyReleased(KeyEvent e) { } public void keyPressed(KeyEvent evt) { char keyChar = evt.getKeyChar(); System.out.println("Key typed = " + keyChar); if ( evt.isShiftDown() ) { System.out.println("Modifier: Shift key is down"); } if ( evt.isControlDown()) { System.out.println("Modifier: Control key is down"); } if ( evt.isAltDown() ) { System.out.println("Modifier: Alt key is down"); } if ( evt.isMetaDown() ) { System.out.println("Modifier: Meta key is down"); } if ( (keyChar == 'X') || (keyChar == 'x')) { System.exit(0); } } } ======================================================================
|