JWindow

I trying to add an KeyListener to a JWindow but it doesn't seem to work. Although if I chance the JWindow into a JFrame it works fine. How can I get around this problem?

Also is it possible to get a title bar(The things that sit at on the task bar in windows)?

The code I'm using is

import javax.swing.*;

import java.awt.event.*;

public class Main extends JWindow implements KeyListener{

public Main(){

super();

setBounds(10, 10, 500, 500);

TestPane TP = new TestPane();

add(TP);

setVisible(true);

addKeyListener(this);

}

public static void main(String[] arguments) {

Main win = new Main();

}

public void keyPressed(KeyEvent e) {

dispose();

}

public void keyReleased(KeyEvent e){

}

public void keyTyped(KeyEvent e){

}

}

Any help would be much appreciated, thanks.

Lex Man

[940 byte] By [LexMan82a] at [2007-10-2 10:53:58]
# 1

> I trying to add an KeyListener to a JWindow but it

> doesn't seem to work.

indeed, you should add your KeyListener into the JWindow's listener's list (see addKeyListener method)

> Although if I chance the

> JWindow into a JFrame it works fine. How can I get

> around this problem?

DO use JFrames instead of JWindows, unless you HAVE to use AWT and avoid Swing

>

> Also is it possible to get a title bar(The things

> that sit at on the task bar in windows)?

see setTitle() method

>

> The code I'm using is

>

> import javax.swing.*;

> import java.awt.event.*;

>

> public class Main extends JWindow implements

> KeyListener{

>

>public Main(){

> super();

> setBounds(10, 10, 500, 500);

> TestPane TP = new TestPane();

> add(TP);

> setVisible(true);

> addKeyListener(this);

>

>}

>

>public static void main(String[] arguments) {

> Main win = new Main();

>}

>

>public void keyPressed(KeyEvent e) {

> dispose();

>

>}

>

>public void keyReleased(KeyEvent e){

>

>}

>

>public void keyTyped(KeyEvent e){

>

>}

> }

>

> Any help would be much appreciated, thanks.

>

> Lex Man

[url=http://java.sun.com/j2se/1.5.0/docs/api/]THIS[/url] rocks

Torajiroua at 2007-7-13 3:17:14 > top of Java-index,Java Essentials,New To Java...
# 2
I had a look through the docs. I think the problem is to do with Focus as JWindow can't have focus which might stop the actionlistener working on it.I've had the same problem with JPanel.
LexMan82a at 2007-7-13 3:17:14 > top of Java-index,Java Essentials,New To Java...
# 3
Also JWindow is part of the swing folder not AWT
LexMan82a at 2007-7-13 3:17:14 > top of Java-index,Java Essentials,New To Java...
# 4
> Also JWindow is part of the swing folder not AWTyou're completely right about that :)
Torajiroua at 2007-7-13 3:17:14 > top of Java-index,Java Essentials,New To Java...