learn java
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 The Software Craftsman this week in the Agile 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: 24189

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]
Have you tried LearnNowOnline? http://www.learnnowonline.com/
subject: JButton question