• 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

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a clss with the following code -
public class ABC extends JFrame implements ActionListener
{
String myAge;
JButton jb;
JTextBox ageInput;

In the constructor,
//Create panels

public void actionPerformed(ActionEvent e)
{
String name = (Strng) ((JButton)e.getSource()).getText();
if(name.equals("submit"))
{
myAge = nameInput.getText();
processMyAge();
}
}

public void processMyAge()
{
System.out.println(myAge); ******NOT PRINTING THE INPUT GOT FROM THE FORM.********
//put it into a vector and return the vector to the calling class.

}
}

How do I correct the above?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some points to investigate:

Is processMyAge ever called?
Is name.equals("submit") ever true when you expect it to?
Is actionPerformed ever called?
Do you have "jb.addActionListener(this)" somewhere?
 
Lucky Singh
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, I have all that.
I just want to know how do I print the age in the method - processFormInput()?
When I do what I've written, I just get a blank, infact control does not even go to that other method.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I'm confused. Your saying that "I have all that" means that "processMyAge" is called, yet later you're saying it is not called?

Go through my questions one by one, and investigate for each one whether the answer is yes or no. That should lead you to an explanation of what's happening.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic