DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2004

    Question problems wiith JMenu

    I'm having problems with the ActionEvent on jMenuItems. I want that when you click on the menuitem, a form window opens. The problem with my code is that when you click for the first time it dosen't do anything, for the second time it does open the window. But, then if you click for a third time it opens two instances of the window, and so on.

    For example:
    this is the code for an action performed on a menu item:

    private void MenuAltaEmpleadoActionPerformed(java.awt.event.ActionEvent evt) {
    AltaEmpleadoAction aea = new AltaEmpleadoAction("Alta Empleado",null, new String("Da de alta un empleado en el sistema"),new Integer(3));


    and this is the AltaEmpladoAction class:

    public class AltaEmpleadoAction extends AbstractAction {

    /** Creates a new instance of AltaEmpleadoAction */
    public AltaEmpleadoAction(String text, ImageIcon icon,
    String desc, Integer mnemonic) {
    super(text, icon);
    putValue(SHORT_DESCRIPTION, desc);
    putValue(MNEMONIC_KEY, mnemonic);

    public void actionPerformed(ActionEvent e) {
    AltaEmpleado a = new AltaEmpleado();



    PD: sorry about my english

  2. #2
    Join Date
    Jun 2004
    Quick glance.

    1. It looks like the first time, you add the listener. Instead, add it during initialization.

    2. The second click, the listener had been registered the first time and so the Form appears.

    3. The third click. Well, everytime you click you create an new instance of object so you are gonna get a new window. If this is not desired, then use an instance variable and check it if is null, then create else show or whatever.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.