This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Button Problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Button Problems" Watch "Button Problems" New topic
Author

Button Problems

james wilson
Greenhorn

Joined: Nov 17, 2001
Posts: 15
Hope someone can help.
I have a program that invokes a method in a seperate class, but when I do so the button doesn't work. Am I doing something stupid?!
Any help appreciated.
Michael Fitzmaurice
Ranch Hand

Joined: Aug 22, 2001
Posts: 168
Originally posted by james wilson:
Hope someone can help.
I have a program that invokes a method in a seperate class, but when I do so the button doesn't work. Am I doing something stupid?!
Any help appreciated.


"One good thing about music - when it hits, you feel no pain" <P>Bob Marley
Michael Fitzmaurice
Ranch Hand

Joined: Aug 22, 2001
Posts: 168
James
Can you provide more details and/or some code ? The problem you need to solve is not clear from your posting. Which class contains the button? What is the button supposed to do? What are the symptoms of it 'not working'?
Make sure you have added a valid action listener object to the button - this could be your problem. Buttons simply fire off events when they get clicked, it is up to the programmer to decide what to do in response to this event.
Michael
------------------
"One good thing about music - when it hits, you feel no pain"
Bob Marley
james wilson
Greenhorn

Joined: Nov 17, 2001
Posts: 15
Right ok sorry.
Here goes.
Class One (Main) invokes two methods in class two (LoggedIn) this done as follows;
loggedin=new LoggedIn();
loggedin.minidisplay();
loggedin.timer(time);
the minidisplay method creates a small gui with a textarea and a button(the button). The timer method just counts down from whatever number has been passed into it.
In class two (LoggedIn) the minidisplay method creates the button as follows;
logout=new Button("LOG OUT");
fr.add(logout);
logout.addActionListener(new ActionListener()
{
public void actionperformed(ActionEvent ae)
{
System.out.print(time);
}
});
when i test the second class with a public static void main it works fine, but when i invoke it from another class i cannot even depress the button.
I hope this is enough and isn't to ambiguous, it's the first time i've left a message so don't know how much info to give.
Cheers James
Rowan Brownlee
Ranch Hand

Joined: Aug 07, 2000
Posts: 97
Hi James,
Your description of being unable to press the button makes me wonder if maybe there's a thread problem. I was recently looking at "Java thread programming" by Paul Hyde. He works through an example of a graphical timer - ie press a button to watch a sweeping minute hand clock display count off the passage of time. Anyway, he demonstrates how things can freeze up if you have the one thread looking after event handling as well as running the timer.
Essentially, the program required that the timer happen in one process while event handling happened in another. This way, both threads could get something like 'equal time'. The event handling thread would get a chance to listen for button pressing, and the timer thread would also get a chance to do it's processing.
I don't know if this is what's happening in your program, but it maybe something to consider, or at least cross off the list of possible problems
cheerio
rowan
~~~~~~~~~~~~~
when i test the second class with a public static void main it works fine, but when i invoke it from another class i cannot even depress the button.
~~~~~~~~~~~~~
james wilson
Greenhorn

Joined: Nov 17, 2001
Posts: 15
Rowan,
Thanks for your suggestion, I created a thread fro my timer method in the LoggedIn Class and now everything works fine .
Cheers
James
 
Don't get me started about those stupid light bulbs.
 
subject: Button Problems
 
Similar Threads
How to add the image in Button(Awt component)
button trigger
java script
how one class Action Listener (button) call another class actionlister button
i have a jfarame. i want to call a existing from when i click close button[default close button]