Results 1 to 5 of 5
  1. #1
    Matty3z is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default what is the best way to make a calcualter like this one > .. ?

    how to make a calcualter Like this one >
    what is the best way to make a calcualter like this one > .. ?-java_calculater.png
    Where .. >
    The button C clears the last digit or symbol entered.
    The button CE clears the last line.
    The button Clear clears all the TextArea.

    i know how to make the Look .. the buttons
    and also the Clear Button is easy to set the TextArea to an empty String ..
    I just want to know how to make the ActionListener for the C Button and the CE Button ? and also the equal Button, how to make it take the last inputs and do Operations ?

  2. #2
    Matty3z is offline Member
    Join Date
    Dec 2011
    Posts
    7
    Rep Power
    0

    Default Re: what is the best way to make a calcualter like this one > .. ?

    i don't want the best way anymore .. i just want a way to make it .. -__- ?
    specially how to make it does the Operations ? (+,-,,) ? and take the inputs ?

  3. #3
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    356
    Rep Power
    5

    Default Re: what is the best way to make a calcualter like this one > .. ?

    It shouldn't be too hard. If you are familiar with Swing, you can draw out the dimensions for each button on paper, and then use that to create your GUI. Then maybe use 3 variables, one for firstNumber, one for operator, and another one for secondNumber, and perform the math operation on them when the = key is pressed. You will just have to setup a few listeners, and think through the logic, shouldn't be too difficult.

  4. #4
    Pluto is offline Member
    Join Date
    Mar 2012
    Posts
    6
    Rep Power
    0

    Default Re: what is the best way to make a calcualter like this one > .. ?

    Insert this at the beginning:
    Java Code:
            cButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    cButtonActionPerformed(evt);
                }
            });
    And in your class delete the last character, and keep deleting until you find a character from the range possible that could be inputted by the user:
    Java Code:
    cButtonActionPerformed(java.awt.event.ActionEvent evt)
    {
        char last='e';
        do {
            calc.setText(calc.getText().substring(0,calc.length()-2));
            last=calc.getText().charAt(calc.getText().length()-1;
        } while (last != '+' && last != '-' && last != '' && last != '' && (last < '0' || last > '9')));
    }
    Same type of thing could be done with the CE button, but it would look for the last '\n' and then after the do loop delete that character too.

    For figuring out what it equals, do what sehudson said, but I recommend just making sure that there can be no two operators can be inputted right after another. You may want to have a special button for negative numbers. Also you'll want to make sure of the Integer.getInteger(STRINGgoesHERE) function. Create smaller strings containing just the numbers you want to use, and then get an integer with that function.
    Last edited by Pluto; 03-24-2012 at 10:51 AM.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,196
    Rep Power
    19

    Default Re: what is the best way to make a calcualter like this one > .. ?

    Quote Originally Posted by sehudson View Post
    It shouldn't be too hard. If you are familiar with Swing, you can draw out the dimensions for each button on paper, and then use that to create your GUI.
    Please don't directly or indirectly encourage the use of a null layout. That's bad.

    The layout pictured can very well be created using the standard layout managers.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 4
    Last Post: 07-23-2011, 08:08 PM
  2. how to make .exe
    By vibaviattigala in forum New To Java
    Replies: 4
    Last Post: 07-22-2011, 10:07 PM
  3. how do i make a jar to an exe?
    By jack13580 in forum New To Java
    Replies: 23
    Last Post: 12-19-2010, 04:15 AM
  4. Trying to make a bot
    By ighor10 in forum New To Java
    Replies: 4
    Last Post: 04-10-2010, 03:29 AM
  5. Make it just A, Help me please
    By yuuchan in forum New To Java
    Replies: 3
    Last Post: 04-25-2009, 02:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •