• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using MouseListeners to create a calculator

 
Isuru Buddhika
Greenhorn
Posts: 11
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im developing a simple calculator and I want to set the text of the TextField to label of the button clicked. Can anyone tell me how to do this?
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isuru Buddhika wrote:... set the text of the TextField ...

Swing, AWT or JavaFX2?
 
Michael Dunn
Ranch Hand
Posts: 4632
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Michael. Isuru, please BeForthrightWhenCrossPostingToOtherSites <-click the link.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whoever it was on SO who told you to use ActionListeners and not MouseListeners was correct.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Always provided this is about Swing or AWT.
 
Isuru Buddhika
Greenhorn
Posts: 11
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everybody who helped me in various ways.. And can some one tell me why it is good to use ActionListeners rather than using MouseListeners?
 
Paul Clapham
Sheriff
Pie
Posts: 20980
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because ActionListener is specifically designed to be called when a button is clicked. You could use a MouseListener but then you have to do extra work if you want to know basic things like which button was clicked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic