permaculture playing cards*
The moose likes Applets and the fly likes Java Calculator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Java Calculator" Watch "Java Calculator" New topic
Author

Java Calculator

Samuel Muentes
Greenhorn

Joined: Aug 26, 2008
Posts: 3
I have to build a Java calculator, I'm not looking for answers, just tips on how I can put the best foot forward.


I am Sam, Sam I am<br />I do love some Java and a good sandwich.
Patel Chintan
Ranch Hand

Joined: Mar 01, 2007
Posts: 80
Originally posted by Samuel Muentes:
I have to build a Java calculator, I'm not looking for answers, just tips on how I can put the best foot forward.


Hi sam,
You can start with J2SE application for making calculator. For GUI part you can use either AWT/Swing component. Or you can also go with applet. For you logic part you can simply use 'switch' for different operations.


Chintan Patel, SCJP1.5, http://datewithjava.blogspot.com
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

Hi Sam,
Welcome to the Ranch. We are happy to have you here

By calculator, I presume you have something graphical, which the user can interact with. You can choose from applications, applets or even some html stuff.
You also can make it more interesting (from the development point of view) by making it a distributed system (the actual computations will happen on the server side). In such a kind of scenario you can go in for web-services or RMI or something similar for client-server communication.

If you can share more details of what you have in mind, or what the requirement is, people can pool in more efficiently with suggestions and tips. Until then, we will be just shooting in the dark.

PS. We have different forums for different java technologies. If you can let us know what technology you prefer, one of the administrators can move this thread to a more appropriate forum, as you will stand a better chance of getting solutions and tips.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Samuel Muentes
Greenhorn

Joined: Aug 26, 2008
Posts: 3
Thanks for all the great feedback. I'm sure if I had been more specific it would have been more help. I am in a Java class, so this is an assignment, that's why I don't want any help with the code. It will be an applet as well. With that I ask for any tips you may have for me to get started.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

You said applets...moving to the applets forum then.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41600
    
  55
Just thinking out loud here ... I could envision 5 classes:
  • the main class that extends JApplet
  • a class for the display that extends JPanel
  • a class for the keypad that extends JPanel
  • a class for numeric keys that extends JButton
  • a class for operator keys that extends JButton

  • While the first 3 would be instantiated only once, the latter two would have multiple instances.

    Does this help?


    Ping & DNS - my free Android networking tools app
    Samuel Muentes
    Greenhorn

    Joined: Aug 26, 2008
    Posts: 3
    Yes, that does help. Thank you.

    That really made me aware of other methods for building it.

    You all have helped a lot, I am very open to any more tips you may have for me.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 38481
        
      23
    Originally posted by Ulf Dittmer:
    Just thinking out loud here ... I could envision 5 classes:
  • the main class that extends JApplet
  • a class for the display that extends JPanel
  • a class for the keypad that extends JPanel
  • a class for numeric keys that extends JButton
  • a class for operator keys that extends JButton

  • While the first 3 would be instantiated only once, the latter two would have multiple instances.

    Does this help?

    And Listeners for the Buttons. Probably two classes, a NumberListener and an OperatorListener.
    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 41600
        
      55
    And Listeners for the Buttons. Probably two classes, a NumberListener and an OperatorListener.

    Generally I'd agree, but in this case the Button classes do so little that I'd be inclined to have them implement the listener interface directly. That's a minor detail, though.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Java Calculator