This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JButton question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JButton question" Watch "JButton question" New topic

JButton question

Mike Brown

Joined: Oct 19, 2003
Posts: 25
I must be the greenest guy in here but since nobody can see me I will go ahead and ask another lame newbie question. Is it possible to use a JButton to cause an event and then use the same button to trigger another event. For instance if I had a picture and I wanted it to get bigger each time I clicked the JButton kind of like a zoom effect. Or If I wanted to use the same JButton to change the background to something different everytime I clicked it. Thanks for your time
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

Hi Phil,
Welcome to JavaRanch!
Yes, indeed, what you're describing is easy enough to do. The way to accomplish it is to make the code in an ActionListener dependent on the value of some member variable, and for it to change that variable each time it's called. So you'd want to do something like

[ October 19, 2003: Message edited by: Ernest Friedman-Hill ]

[Jess in Action][AskingGoodQuestions]
jQuery in Action, 2nd edition
subject: JButton question
Similar Threads
How to setPreferredSize of JPanel
Understanding Events
Help me ,immediately !!!!
GUI Code Placement
Java Minesweeper Help