keyboard applications

hii want to know how to develop a code managing the keyboard like adding special right click command , for example when you highlight a line and you right click you find special command .and like adding a hot key
[233 byte] By [scrolldowna] at [2007-11-26 23:54:46]
# 1
Huh? Are you talking about keyboard accelerators? Popup menus? Please be more descriptive.
hunter9000a at 2007-7-11 15:37:40 > top of Java-index,Java Essentials,New To Java...
# 2
Look up ActionListener, although I don't think right clicks have anythign to do with keyboard apps.For hotkey's look up KeyListener
Vagabona at 2007-7-11 15:37:40 > top of Java-index,Java Essentials,New To Java...
# 3
I think the op is talking about easter eggs in an application, but that's just a thought.
Aknibbsa at 2007-7-11 15:37:40 > top of Java-index,Java Essentials,New To Java...
# 4
Keyboard bindings: http://java.sun.com/products/jfc/tsc/special_report/kestrel/keybindings.htmlTo have a component menu that pops up on a right click, use JComponent's setComponentPopupMenu
DrLaszloJamfa at 2007-7-11 15:37:40 > top of Java-index,Java Essentials,New To Java...
# 5
> Huh? Are you talking about keyboard accelerators?> Popup menus? Please be more descriptive.yes this is exactlu what i am talking about, i want to know how to add my special command to the pop up menu of right click
scrolldowna at 2007-7-11 15:37:40 > top of Java-index,Java Essentials,New To Java...
# 6
Look into JComponent.setComponentPopupMenu like Dr. Jamf said.
hunter9000a at 2007-7-11 15:37:40 > top of Java-index,Java Essentials,New To Java...
# 7

You mean maybe like a JPopupMenu? I think you should go off and read a Swing tutorial before you start asking random questions like this one -- that's assuming you are asking about GUI applications. After you do that you may well find that your questions have been answered. Right now you are just asking from a position of total ignorance, and that doesn't lead to good questions.

DrClapa at 2007-7-11 15:37:40 > top of Java-index,Java Essentials,New To Java...
# 8

Here is a simple demonstration of a JPopupMenu with Shortcut Accelerators:

import javax.swing.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.awt.event.KeyEvent;

import java.awt.Event;

class Test extends JFrame {

private JLabel label;

private JPopupMenu jpm;

private JMenuItem changeTextItem;

private JMenuItem resetTextItem;

public Test() {

initComponents();

}

private void initComponents() {

label = new JLabel("Right-click on me, and select Change Text (or press CTRL+G)");

label.setSize(400, 20);

label.setLocation(5, 5);

jpm = new JPopupMenu();

changeTextItem = new JMenuItem("Change Text");

changeTextItem.setMnemonic((int)'C');

changeTextItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, Event.CTRL_MASK));

resetTextItem = new JMenuItem("Reset Text");

resetTextItem.setMnemonic((int)'R');

resetTextItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK));

label.add(jpm);

jpm.add(changeTextItem);

jpm.add(resetTextItem);

this.getContentPane().setLayout(null);

this.getContentPane().add(label);

this.pack();

this.setSize(500, 300);

this.setLocationRelativeTo(null);

this.setTitle("Test Application");

this.setDefaultCloseOperation(EXIT_ON_CLOSE);

label.addMouseListener(new MouseAdapter() {

public void mouseClicked(MouseEvent evt) {

if( evt.getButton() == MouseEvent.BUTTON3 )

jpm.show(label, evt.getX(), evt.getY());

}

});

changeTextItem.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent evt) {

label.setText("You clicked on the menu-item!");

}

});

resetTextItem.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent evt) {

label.setText("Right-click on me, and select Change Text (or press CTRL+G)");

}

});

}

public static void main(String[] argv) { new Test().setVisible(true); }

}

Navy_Codera at 2007-7-11 15:37:40 > top of Java-index,Java Essentials,New To Java...