• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ActionListener problem

 
Swapnil Sonawane
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
got it solved after renaming validate() to validateIt()
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic