Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ActionListener  RSS feed

 
Lucky Singh
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • 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?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • 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
  • 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: 42972
73
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!