simple question about swing

Respected Members,

I am making a very simple program in Java swing using jdk1.4.2, the program simply contains a JFrame and nothing else,what it is simply doing that I have binded an event to this frame and which is that every time the user presses Ctrl-F3(control and F3 key) so a message is displayed stating for example that "you pressed right key", but my program is not working, the probelm is that the event dont get fired,if I test it indivisually for Ctrl or F3 than the event is fiered and every thing works fine, the code is:

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

publicclass SwingEventTest

{

publicstaticvoid main(String [] args)

{

JFrame f =new JFrame("This is a test");

f.setSize(400, 300);

f.setTitle("Test Frame....");

f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);

Container contentPane = f.getContentPane();

contentPane.setBackground(Color.white);

contentPane.setFocusable(true);

contentPane.setLayout(null);

contentPane.addKeyListener(new MyKeyListener());

f.setVisible(true);

}

}

class MyKeyListenerextends KeyAdapter

{

publicvoid keyPressed(KeyEvent evt)

{

int iCode = evt.getKeyCode();

if (iCode == KeyEvent.VK_CONTROL && iCode == KeyEvent.VK_F3)

{

JOptionPane.showMessageDialog(null,"You pressed Ctrl+F3 so this event has been fiered and trapped");

}

}

}

Please tell me the error in this code, I would be waiting for your reply so please reply as soon as possible.

Thanking You,

Taqi Raza.

[2647 byte] By [taqi10a] at [2007-11-27 11:31:04]
# 1

try this?

if (iCode == KeyEvent.VK_F3 && evt.isControlDown())

cheeriea at 2007-7-29 16:37:34 > top of Java-index,Desktop,Core GUI APIs...
# 2

> Please tell me the error in this code,

As I suggested in your original posting you should be using Key Bindings not a KeyListener. Spend your time learning the correct way to write an application.

camickra at 2007-7-29 16:37:34 > top of Java-index,Desktop,Core GUI APIs...