File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes ActionListener problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ActionListener problem" Watch "ActionListener problem" New topic

ActionListener problem

Swapnil Sonawane
Ranch Hand

Joined: Jan 02, 2008
Posts: 190
I have 4 java files:

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.

/**************** *************/

Swapnil S. Sonawane<br /> <br />B.Tech (Expected May 2009)<br />Computer Science, NIT Durgapur, India<br />SCJA 1.0
Swapnil Sonawane
Ranch Hand

Joined: Jan 02, 2008
Posts: 190
/************* *******************/

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")) {

else if(actionCommand.equals("RESET")) {

else if(actionCommand.equals("ACT")) {
int selectedIndex = arenaPanel.getActivityIndex();
if((selectedIndex==1) || (selectedIndex==2)) {
else {


Swapnil Sonawane
Ranch Hand

Joined: Jan 02, 2008
Posts: 190

/***************** *************/

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

[ October 14, 2008: Message edited by: Swapnil Sonawane ]
Swapnil Sonawane
Ranch Hand

Joined: Jan 02, 2008
Posts: 190
got it solved after renaming validate() to validateIt()
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46412
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.
I agree. Here's the link:
subject: ActionListener problem
It's not a secret anymore!