Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with Jbuttons JText Lotto

 
Alan Green
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am doing homework writting a lotto program my number text fields must be an array of text fields, and there must be an array of integers to hold the user's numbers as numbers. I am trying to set my JButtons for play and reset using Action Performed. When I compile I continue to get the error
cannot resolve symbol method addActionListener. Can someone help me with this problem.
 
Srivani Nallan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to check for the action command and then have your play method or clear the fields.
For Example:
public void actionPerformed (ActionEvent event){
if(event.getActionCommand().equals("Play")){
//do something
}
if(event.getActionCommand().equals("Reset")){
//clear the fields
}
}
 
Eddie Vanda
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Isa

You have an array of textfields, in numberField array. You can't add an ActionListener to an array, they would have to be added to each textfield in turn, assuming you really want to have action listeners on your textfields. So change scope of for statement you could have:

What you had should not have compiled, so maybe you've already fixed it?
 
Alan Green
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
should i be able to see the play and reset buttons on the applet before i right the perform method... because i don't see it when executing..
 
Alan Green
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still getting the Assmt4 should be declared abstract it does not define action Performed..

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Swing forum.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isa,
We don't have too many rules around here, but we do have a Naming Policy. Please adjust your display name accordingly.
You can change your display name here.
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic