Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

menu with hotkeys in applet using AWT only

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Report post to moderator
I want to create a menu with hotkeys in applet using AWT only.
I have 2 frames , the top frame contains the applet(menu).I have used PopupMenu passing MenuShortcut in the conmstructor/calling the setShortcut method of MenuItem. Tho' it displays the short cut key in the PopupMenu( ctrl-C) but does nothing when the shortcut key is pressed.
I have added ActionListener to the MenuItem and it responds to mouseClicks properly.The problem is with the shortcut keys only.I want to use AWT only.
Please give me a viable solution preferably with example
The code is as folls.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import netscape.javascript.JSObject;
public class PopupMenuEx extends Applet implements ActionListener{
Button btn1;
Button btn2;

PopupMenu popup;
PopupMenu popup1;
public void init() {
setBackground(Color.white);
MenuItem mi;
popup = new PopupMenu("popup1");

MenuShortcut shortcut = new MenuShortcut(KeyEvent.VK_C,false);
mi = new MenuItem("cut");
mi.setShortcut(shortcut);
popup.add(mi);
mi.addActionListener(this);

mi = new MenuItem("copy");
mi.addActionListener(this);
popup.add(mi);
popup.addSeparator();
mi = new MenuItem("paste");
mi.addActionListener(this);
popup.add(mi);


popup1 = new PopupMenu("popup1");


mi = new MenuItem("view");
mi.addActionListener(this);
popup1.add(mi);

mi = new MenuItem("Update");
mi.addActionListener(this);
popup1.add(mi);
popup1.addSeparator();
mi = new MenuItem("Refresh");
mi.addActionListener(this);
popup1.add(mi);

add(popup); // add popup menu to applet
add(popup1); // add popup menu to applet




btn1 = new Button(" File ");
btn1.addActionListener(this);
btn1.setBackground(Color.decode("#093a80"));
btn1.setForeground(Color.white);
btn1.setFont(new Font("Arial",Font.BOLD,11));
btn2 = new Button(" Edit");
btn2.addActionListener(this);
btn2.setBackground(Color.decode("#093a80"));
btn2.setForeground(Color.white);
btn2.setFont(new Font("Arial",Font.BOLD,11));



add(btn1);
add(new Label(" "));
add(btn2);
add(new Label(" "));


enableEvents(AWTEvent.MOUSE_EVENT_MASK);
enableEvents(AWTEvent.KEY_EVENT_MASK);
resize(200, 200);
}
public void processMouseEvent(MouseEvent e) {
if (e.isPopupTrigger()) {
popup.show(e.getComponent(), e.getX(), e.getY());
//popup.show(button, 20,10);
}
super.processMouseEvent(e);
}
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();

if(e.getSource()==btn1)
popup.show(btn1, 0,20);
else if(e.getSource()==btn2)
popup1.show(btn2, 0,20);

if (command.equals("cut")) {
//openJSWindow("hello.htm");

}
}
}
[ October 07, 2002: Message edited by: Saira Murty ]
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Report post to moderator
Can you show us the code.
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Report post to moderator
Continue the conversation here.
[ October 08, 2002: Message edited by: Cindy Glass ]
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!