This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes i need help with a simple add, subtract, cal. applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "i need help with a simple add, subtract, cal. applet" Watch "i need help with a simple add, subtract, cal. applet" New topic
Author

i need help with a simple add, subtract, cal. applet

J Fox
Greenhorn

Joined: Feb 01, 2005
Posts: 10
i'm having a bit of a problem with the class part of the program....
it says to first create a class called CalculatorPanel
and private int operand1, operand2, and result....and make get methods for all of these.....

then says to make another class called Calculator and create all the buttons shown in the output....

________________________________________

enter first operand : | text field "512"|
enter second operand : | text field "11" |

select operation: |button 1 " + "| or |button 2 " - "| result: "501"

________________________________________
**imagine the above as a GUI

then the third step is to create another class called CalculatorGUI
and it says to create the actual frame and stuff of the gui...

this is what i have so far...help if you can i would really appreciate it



i tried to inter-twin the 1st and 3rd step into one big class....i need imediate help lol its due at 9:30 this morning so if you have any suggestions plz...do tell..i dont know if every listener is supposed to have a implemented actionlistener or if two can use the same one.....

i know every button has to have a separate listener ....
but in the code

can the "ButtonListener" in the code be anything you want it to be named or is there a pre-defined set of words for text fields and buttons...
well if you can help

thanks,
Justin
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Originally posted by J Fox:

i tried to inter-twin the 1st and 3rd step into one big class....i need imediate help lol its due at 9:30 this morning so if you have any suggestions plz


I'd suggest that you should get an early start so if you have problems you'll have time to figure them out, but it seems a little late for that.



...do tell..i dont know if every listener is supposed to have a implemented actionlistener or if two can use the same one.....


It seems like you are asking if you need a seperate instance of a listener for every GUI object you want to assign a listener to. The answer is no. You can have different listeners for each GUI object or you can use the same one (in which case you have to differentiate between the different objects which can fire that event).


can the "ButtonListener" in the code be anything you want it to be named or is there a pre-defined set of words for text fields and buttons...
well if you can help


It has to be an instance of a class which implements the interface ActionListener. How do I know? The Java Documentation for JButton told me.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
It has to be an instance of a class which implements the interface ActionListener. How do I know? The Java Documentation for JButton told me.


Read the documentation? NOOOOOOO! Anything but that!


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
 
Consider Paul's rocket mass heater.
 
subject: i need help with a simple add, subtract, cal. applet
 
Similar Threads
simple program with a panel class and actionlistener
Calculator clear button not working...
Java Help non-HTML textpad
Swing and RuntimeException
NullPointerException - Using JTextField to Add Numbers