• Post Reply 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ActionListener problem

 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 4 java files:

MainFrame.java
MainFrameListener.java
ArenaPanel.java
ArenaListener.java

MainFrame extends JFrame and is the main window of my application. ArenaPanel is one of the several panels I have. MainFrame has a menu bar which has menu buttons to go to different panels. The arenaPanel has a SAVE button, actions for which have been defined in arenaListener. Actions for MainFrame menu have been defined in MainFrameListener. Here are my codes. I have removed the irrelavent parts at places as the codes are very long.

/**************** ArenaPanel.java *************/
 
Swapnil Sonawane
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
/************* ArenaListener.java *******************/

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;


/**
* @author Swapnil Sonawane
*/

public class ArenaListener implements ActionListener {

ArenaPanel arenaPanel;

public ArenaListener(ArenaPanel panel) {
arenaPanel = panel;
}

public void actionPerformed(ActionEvent evt) {

String actionCommand = evt.getActionCommand();
if(actionCommand.equals("SAVE")) {
arenaPanel.validate();
}

else if(actionCommand.equals("RESET")) {
arenaPanel.clear();
}

else if(actionCommand.equals("ACT")) {
int selectedIndex = arenaPanel.getActivityIndex();
if((selectedIndex==1) || (selectedIndex==2)) {
arenaPanel.enableDescription(false);
arenaPanel.enableExplanation(false);
arenaPanel.enableTimeFields(false);
}
else {
arenaPanel.enableDescription(true);
arenaPanel.enableExplanation(true);
arenaPanel.enableTimeFields(true);
}

}

}
}
 
Swapnil Sonawane
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



/***************** MainFrameListener.java *************/


The problem is that once I visit ArenaPanel, I mean click on that menu and then move to other panels, clicking on any other menu options in the MainFrame menu bar activates that button and it listens to ArenaListener. I tried to debug but didn't get it. It's strange.
I am trying to say that even if I remove the save button from the arenapanel the job that should be done after clicking on save button is done without clicking on it and clicking somewhere else in the menu bar. And this happens after I visit arenapanel once and not before that. Strange enough for me



Thanks.
[ October 14, 2008: Message edited by: Swapnil Sonawane ]
 
Swapnil Sonawane
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
got it solved after renaming validate() to validateIt()
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done and it saves us reading all that code.

The validate() method is a standard API method in Container which checks the alignment and location of all the added Components before displaying them.
 
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic