The Artima Developer Community
Sponsored Link

Java Answers Forum
Help!About hotKey!

3 replies on 1 page. Most recent reply: Aug 13, 2002 10:17 AM by Kishori Sharan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
jungil

Posts: 5
Nickname: jungil
Registered: Aug, 2002

Help!About hotKey! Posted: Aug 12, 2002 8:05 PM
Reply to this message Reply
Advertisement
I need help!!
Now, i want to make an application with several hotKeys in JFrame.My source like this:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.util.*;
public class Demo extends JFrame {
public Demo () {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.enableEvents(AWTEvent.KEY_EVENT_MASK);
getContentPane().setLayout(null);
closeBtt.setBounds(new Rectangle(0, 13, 19, 40));
closeBtt.setBorder(new TitledBorder(""));
closeBtt.setHorizontalAlignment(SwingConstants.LEFT);
closeB tt.setHorizontalTextPosition(SwingConstants.LEFT);
closeBtt.setMargin(new Insets(0, 0, 0, 0));
closeBtt.setMnemonic('0');
closeBtt.setText("X");
closeBtt.setVerticalAlig nment(SwingConstants.TOP);
closeBtt.setVerticalTextPosition(SwingConstants.TOP);

this.setEnabled(true);

templateLab.setText("template");
templateLab.setBounds (new Rectangle(23, 25, 80, 17));
templateCB.setBounds(new Rectangle(103, 23, 109, 21));

codeLab.setText("name");
codeLab.setBounds(new Rectangle(225, 26, 33, 17));

codeTxt.setBounds(new Rectangle(266, 23, 63, 21));

setBtt.setBounds(new Rectangle(340, 20, 79, 27));
setBtt.setBorder(new TitledBorder(""));
setBtt.setText("set");

getContentPane().add(templateCB, null);
getContentPane().add(codeTxt, null);
getContentPane().add(setBtt, null);
getContentPane().add(closeBtt, null);
getContentPane().add(templateLab, null);
this.getContentPane().add(codeLab, null);
}

protected void processKeyEvent(KeyEvent evt) {
super.processKeyEvent(evt);
if(evt.getKeyCode() == KeyEvent.VK_F4){
System.out.println("AAAA");
}
}

public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception e) {
;
}

Demo demo = new Demo();
demo.setBounds(50,50,479, 80);
demo.show();
}

private JButton closeBtt = new JButton();
private JLabel templateLab = new JLabel();
private JComboBox templateCB = new JComboBox();
private JLabel codeLab = new JLabel();
private JTextField codeTxt = new JTextField();
private JButton setBtt = new JButton();
}

when i clicked the F4 button, i can not catch the KeyEvent. "AAAA" is not printed.
What problem with my program?
help me, plz
thank u


BTW, if i remove all the components from JFrame except label, "AAAA" will be printed.

if possible, give me a demo.


Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: Help!About hotKey! Posted: Aug 12, 2002 9:20 PM
Reply to this message Reply
YOur code works in JDK1.3.1 and JDK1.4. I don't know what version of JDK you are using. It prints AAA.. when I pressed F4.

Thanks
Kishori

jungil

Posts: 5
Nickname: jungil
Registered: Aug, 2002

Re: Help!About hotKey! Posted: Aug 12, 2002 11:16 PM
Reply to this message Reply
i use jdk1.4.01

just now, i downloaded the jdk1.4.1beta and runned my demo, but it is also no response.
why?!
help~~~~~~~~~~~~~~~

Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: Help!About hotKey! Posted: Aug 13, 2002 10:17 AM
Reply to this message Reply
Maybe your frame doesn't have focus when you press F4. So, just click anywhere in the frame and then press F4.

Thanks
Kishori

Flat View: This topic has 3 replies on 1 page
Topic: ORA-1461 Previous Topic   Next Topic Topic: Redirect question - Jay Candy

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use