Question:

Java Program that will perform simple operations!???

by  |  earlier

0 LIKES UnLike

Can someone give me the code that when i press A it will add, when i press S it will subtract, when i press D it will divide and when i press M it will multiply.......

 Tags:

   Report

1 ANSWERS


  1. I don't feel like typing up a whole program, but I can give you a concept.  

    Using Swing, create 3 text fields.  Use the default layout manager and maybe throw in a few JLabel's.  

    You'll need an ActionListener for this, and if you don't know what that is you can find more information by following this link:

    http://java.sun.com/docs/books/tutorial/...

    Upon each key press, test which key it is.  If it's A, S, M, or D then call a method to add, subtract, multiply, or divide respectively.  These methods should extract the text from the first two fields, perform the necessary operation, and print it in the third one.  Here's what the add one would look like:

    public void add() {

    thirdTextField.setText(parseInt(firstT... + parseInt(secondTextField.getText()));

    }

    Good luck!

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.