Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • 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
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

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: 77539
372
  • 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.
 
We begin by testing your absorbancy by exposing you to this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic