A
apchar
Consider the following 2 applets. The first one works. The second
doesnt. It apparently cant get focus. The only difference is the use
of contentPanes. Do I need to do something special for JContainers
within contentPanes?
I'm using Java 1.4.2_02-b03 for linux. Incidently, both work fine on
Mac OSX.
/* <applet code="KeyTest2" width="500" height="300"></applet> */
// this one works
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class KeyTest2 extends JApplet implements KeyListener
{
public void init() { addKeyListener(this); }
public boolean isFocusable() { return true; }
public void keyPressed(KeyEvent e) {}
public void keyReleased(KeyEvent e) {}
public void keyTyped(KeyEvent e) {
System.out.println("ding!"); }
}
/* <applet code="KeyTest" width="500" height="300"></applet> */
// this one does not work in Linux.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class KeyTest extends JApplet
{
public void init()
{
Container contentPane = getContentPane();
contentPane.add(new KeyTestPanel());
}
}
class KeyTestPanel extends JPanel implements KeyListener
{
public KeyTestPanel() { addKeyListener(this); }
public boolean isFocusable() { return true; }
public void keyTyped(KeyEvent e) { System.out.println("ding");
}
public void keyPressed(KeyEvent e) {}
public void keyReleased(KeyEvent e) {}
}
doesnt. It apparently cant get focus. The only difference is the use
of contentPanes. Do I need to do something special for JContainers
within contentPanes?
I'm using Java 1.4.2_02-b03 for linux. Incidently, both work fine on
Mac OSX.
/* <applet code="KeyTest2" width="500" height="300"></applet> */
// this one works
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class KeyTest2 extends JApplet implements KeyListener
{
public void init() { addKeyListener(this); }
public boolean isFocusable() { return true; }
public void keyPressed(KeyEvent e) {}
public void keyReleased(KeyEvent e) {}
public void keyTyped(KeyEvent e) {
System.out.println("ding!"); }
}
/* <applet code="KeyTest" width="500" height="300"></applet> */
// this one does not work in Linux.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class KeyTest extends JApplet
{
public void init()
{
Container contentPane = getContentPane();
contentPane.add(new KeyTestPanel());
}
}
class KeyTestPanel extends JPanel implements KeyListener
{
public KeyTestPanel() { addKeyListener(this); }
public boolean isFocusable() { return true; }
public void keyTyped(KeyEvent e) { System.out.println("ding");
}
public void keyPressed(KeyEvent e) {}
public void keyReleased(KeyEvent e) {}
}