This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Using MouseListeners to create a calculator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Using MouseListeners to create a calculator" Watch "Using MouseListeners to create a calculator" New topic
Author

Using MouseListeners to create a calculator

Isuru Buddhika
Greenhorn

Joined: Nov 04, 2012
Posts: 11

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

Joined: May 03, 2008
Posts: 4759
    
    6

Isuru Buddhika wrote:... set the text of the TextField ...

Swing, AWT or JavaFX2?


luck, db
There are no new questions, but there may be new answers.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
http://stackoverflow.com/questions/14332354/using-mouselisteners-to-create-a-calculator
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4759
    
    6

Thank you, Michael. Isuru, please BeForthrightWhenCrossPostingToOtherSites <-click the link.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 41091
    
  29
Whoever it was on SO who told you to use ActionListeners and not MouseListeners was correct.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4759
    
    6

Always provided this is about Swing or AWT.
Isuru Buddhika
Greenhorn

Joined: Nov 04, 2012
Posts: 11

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
Bartender

Joined: Oct 14, 2005
Posts: 19351
    
  10

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Using MouseListeners to create a calculator