wood burning stoves 2.0*
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
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: 4523
    
    5

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: 4523
    
    5

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

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

Joined: May 03, 2008
Posts: 4523
    
    5

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: 18136
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using MouseListeners to create a calculator
 
Similar Threads
Just passed SCWCD - 88%
Silly but interesting question...
Sierra's scjp book. Chapter#9 notifyAll() example
scjp 1.4 exam query
Beta for Sun Certified EJB Developer Java EE 6 Exam