File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes A little problem.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A little problem.." Watch "A little problem.." New topic
Author

A little problem..

Ben Jones
Greenhorn

Joined: Oct 04, 2007
Posts: 16
Hello there! I'm new to this any trying to get a GUI sorted out. I've been trying to do Event Handlers but for some reason, I keep getting an error saying the variable can't be found. My code is below:



Dan Brownlow
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36514
    
  16
Welcome to the Ranch.

You would have been better to post on the Swing Forum, but the problem is that the JButton you are calling the action on is declared as a local variable, so it is out of scope when you get to the actionPerformed method.
Ben Jones
Greenhorn

Joined: Oct 04, 2007
Posts: 16
Campbell Richie, thank you. I've realised (Apparently my spelling of 'realized' isn't right =]) the error of my ways. I declared the button globally. Sorry about posting in wrong section, first post so forgive me please =].
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36514
    
  16
Originally posted by Dan Brownlow:
'realized' isn't right
If only I could get my browser to mark "realised" as correct and "realized" as wrong.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36514
    
  16
. . . and I trust you have got it working now?
Ben Jones
Greenhorn

Joined: Oct 04, 2007
Posts: 16
Oops.. Sorry about spelling your name wrong also. Yea', all is working now, declared all the 'JButtons' globally so that all my methods can use them. I really should of noticed that =]

Thanks for the help.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36514
    
  16
Everybody declares things as local variables from time to time. Don't call them "global" however. That is a C/C++ concept; a C "global" is "visible" to any code in the application. In OO programming you want to declare your fields as "private" so they are only visible within your class.

And no problem about the other things you mentioned!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A little problem..
 
Similar Threads
Help with a simple gui
Doubt in GUI
warhammer 40k game(some bartender please move this to game forum)
Error in "Headfirst Java"
code error