Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ActionCommand with JButtons, Help  RSS feed

 
allen huang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simple program and i want to use ActionCommand with my JButtons to print text. This is the code i have so far, can anyone tell me why this isn't working?

----------------------------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------------------
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Allen, welcome to the Ranch!

Could you start by explaining why you think the code isn't working? Does it not compile? Does it not do what you expected? (And what exactly did you expect anyway?) Does it make smoke come out of your computer? Details would be useful.
 
allen huang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Hi Allen, welcome to the Ranch!

Could you start by explaining why you think the code isn't working? Does it not compile? Does it not do what you expected? (And what exactly did you expect anyway?) Does it make smoke come out of your computer? Details would be useful.


Hi Paul,

What i want this program to do is to print text when i press a JButton, for example when i press the Start button, i want it to print "start". Right now i am using eclipse, and eclipse doesn't say there are any errors in the code. Everything compiles fine aswell with no error messages. What is puzzling me is why the ActionCommand isn't working when i press the JButtons. This piece of code is a class that is part of my bigger game that i am creating for a school project.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I notice that the class you posted is named "instructions". (It should be named "Instructions" so as to follow Java programming standards, but let's leave that aside for now.) And the main() method creates an object of a class named "titlePage" (which should be named TitlePage). In other words, you're not creating a new "instructions" object, so you aren't using any of the code you posted. You're using that other class, "titlePage", whose code you didn't post, and so there's no reason to expect anything in the code you posted to happen.

By the way the only reason to use System.out.println in a Swing GUI program is for debugging, but I assume that's what you are trying to do at the moment.
 
allen huang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I notice that the class you posted is named "instructions". (It should be named "Instructions" so as to follow Java programming standards, but let's leave that aside for now.) And the main() method creates an object of a class named "titlePage" (which should be named TitlePage). In other words, you're not creating a new "instructions" object, so you aren't using any of the code you posted. You're using that other class, "titlePage", whose code you didn't post, and so there's no reason to expect anything in the code you posted to happen.

By the way the only reason to use System.out.println in a Swing GUI program is for debugging, but I assume that's what you are trying to do at the moment.

Whoops >.< thanks I didn't even notice. Thank you so much.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!