• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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: 43027
76
  • 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: 43027
76
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic