Why doesn't dispatchEvent(KeyEvent e) work in applets but does in applications?

John Zukowski

This is actually the result of differences in Java runtime implementations between browser vendor. Microsoft seems to have implemented their event dispatching mechanism differently than the rest of the world. Sun's and Netscape's versions will use dispatchEvent() properly from an applet. You can try out the following test case and see for yourself:

// <applet code=TestCase width=500 height=200>
// </applet>

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class TestCase extends Applet {

  TextField t1 = new TextField(50);
  TextField t2 = new TextField(50);

  public void init() {
    t1.addKeyListener(new KeyAdapter() {
      public void keyTyped(KeyEvent e) {
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact