File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Android Security Essentials Live Lessons this week in the Android 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: 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: 38087
    
  22
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: 18541
    
    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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Using MouseListeners to create a calculator
 
Similar Threads
Silly but interesting question...
Just passed SCWCD - 88%
scjp 1.4 exam query
Sierra's scjp book. Chapter#9 notifyAll() example
Beta for Sun Certified EJB Developer Java EE 6 Exam