Could u guys help me with a calculator program

hi
i'm writing a calculator program for my java class and the code ur about to read actually works but when i click on the keypad i don't get any numbers in the display screen, the textfield
Could u guys have a look at it please:
here we go
import javax.swing.* ;
import java.awt.* ;
import java.awt.event.* ;
public class Calculator extends JFrame implements ActionListener {
public boolean firstDigit;
public int temp1 = 0;
public int temp = 0;
public int result = 0;
public String opr = "";
JTextField tf= new JTextField ("",20) ;           //sets the display initially at 0
//tf.setEditable (false) ; this doesn't work
JPanel pan = new JPanel() ;
JButton bclear= new JButton("C") ;
JButton b0= new JButton("0") ;
JButton badd = new JButton("+") ;
JButton bsub = new JButton("-") ;
JButton bmult = new JButton("x");
JButton bdiv = new JButton("/") ;
JButton bpoint= new JButton(".");
JButton bequal = new JButton("=");
public Calculator (String title) // constructor
super(title)     ;     
pan.add(tf);
for ( int i=1; i<=3; i++)
JButton butt=new JButton(""+i);
butt.addActionListener(this);
pan.add(butt);                }
badd.addActionListener(this);
pan.add(badd);
for ( int i=4; i<=6; i++)
JButton butt=new JButton(""+i);
butt.addActionListener(this);
pan.add(butt);
bsub.addActionListener(this);
pan.add(bsub);
for ( int i=7; i<=9; i++)
JButton butt=new JButton(""+i);
butt.addActionListener(this);
pan.add(butt);
bmult.addActionListener(this);
pan.add(bmult);
bclear.addActionListener(this);
pan.add(bclear);
b0.addActionListener(this);
pan.add(b0);
bpoint.addActionListener(this);
pan.add(bpoint);
bequal.addActionListener(this);
pan.add(bequal);
bdiv.addActionListener(this);
pan.add(bdiv);
//pan.add(new Button(""));
setContentPane(pan) ;
public boolean action(Event e, Object o)
//checks for operator keys
if (e.target == badd)
temp1 = temp;     //to "save" for calculation
opr = "+";
else if (e.target == bsub)
temp1 = temp;
opr = "-";
else if (e.target == bmult)
temp1 = temp;     
opr = "*";
else if (e.target == bdiv)
temp1 = temp;
opr = "/";
else if (e.target == bequal)
result = calculate(temp1,opr,temp);
tf.setText(Integer.toString(result)); //does the calculation
temp= result; //to be able to do an operation on the result
else if (e.target == bclear)
tf.setText("");
temp1 = 0; //resets the temps and display to 0
temp = 0;
else
//numeric buttons
if (firstDigit)
tf.setText( o.toString() );
firstDigit = false;
temp = Integer.parseInt(tf.getText()); //saves the number in a temp
else
tf.setText(tf.getText() + o.toString()); //for numbers longer than 1 digit
temp = Integer.parseInt(tf.getText());
return true;
firstDigit = true; // GET READY FOR NEXT NUMBER
return true;
public int calculate(int num1,String op, int num2 )
// calculate the numbers
int answers = 0;
if (op == "+")
answers = num1 + num2; //does the calculation for +
else if(op == "-")
answers = num1 - num2; //does the calculation for -
else if(op == "/")
if(num2 == 0)
tf.setText("ERROR");//gives error message if dividing by 0
else     
answers = num1 / num2;
else if(op == "*")
answers = num1 * num2; //does the calculation for *
return answers;
public void actionPerformed(ActionEvent e) {
Object source = e.getSource() ;
public static void main(String[] args)     {
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName() );
catch (Exception e) {
System.err.println("impossible to use system setting : " + e ); }
Calculator fen = new Calculator("CALCULATOR");
fen.setSize(235, 300);
fen.setVisible(true);
fen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

I Hope this would help you.
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=2&txtCodeId=2275
Thanks,
Vikas Karwal
[email protected]

Similar Messages

  • I have lost my iphone 5. The person who has my phone right now is still using my game center id to play one of my game that i have in that phone named "Clash of Clan". Could you guys help me to sign out this icloud's ID and game center's ID from that fone

    i have lost my iphone 5. The person who has my phone right now is still using my game center id to play one of my game that i have in that phone named "Clash of Clan". Could you guys help me to sign out this icloud's ID and game center's ID from that phone for me, or anyone knows how to do this, please mail back to me. Id : "[email protected]" Thanks.

    As far as I know you can't delete the primary email address for an iCloud account.  It's assigned when the account is created.  But your neighbor wouldn't have been able to get into your iCloud account without your Apple ID and password.  Are you sure the account wasn't still on your phone when you gave it to him?
    You could migrate a copy of your data to a new iCloud account but I would still be concerned that someone else was using my old account, which presumably still has your data in it.
    I'm fairly certain that you're going to have to have iCloud support help you sort this one out as they may have the ability to make changes to an existing account that users can't.  Make an appointment with the genius bar at a nearby Apple store and have them take a look at it.  If necessary, they should be able to contact iCloud support for you.

  • I need help with something could some one help me with installing windows 7 on bootcamp 4.0 with iMac 2.8 ghz model

    could some one help me with something important i have a 2.8 ghz intel quad core Imac with 10.7 with bootcamp 4.0 but still getting that black screen while trying finish the install of windows 7 etc. or do i need a new mac for it to work properly

    This might help point you in the right direction.
    http://support.apple.com/kb/HT4818
    Hope it helps
    Also google it and lots of results come up including youtube clips....

  • Hello, Honestly I just updated my 4s and my iPad 3 to iOS 6 and when try to press on the Music app or the iTunes app it says "cannot connect to iTunes Store" Could you please help me with this thank you so much, Charbel from Lebanon

    Hello, Honestly I just updated my 4s and my iPad 3 to iOS 6 and when try to press on the Music app or the iTunes app it says "cannot connect to iTunes Store" Could you please help me with this thank you so much, Charbel from Lebanon

    See these previous discussions help.
    App Store Updates (but only Updates)...: Apple Support Communities
    Apps suddenly don't update: Apple Support Communities

  • I recently upgraded to IOS 10.9.5 and now I can't export anything from final cut Pro X. Could somebody please help me with this?

    I recently upgraded to IOS 10.9.5 and now I can't export anything from final cut Pro X. Could somebody please help me with this?

    SSign in to the App Store using the Apple ID that was used to purchase the software.

  • HT1338 Could you please help me with the problem. I have mac os 10.7.4 on my macbook pro retina and want to update it to 10.7.5. I had been waiting for 2 hours to do it, but then it appeared that it was impossible. What should I do?

    Could you please help me with the problem. I have macbook with retina with mac os 10.7.4 ann want to update it to mac os 10.7.5. I had been waiting for 2 hours to do it and had tried 3 times but it appeared that it was impossible. What should I do?

    You can download the standalone updates:
    OS X Lion Update 10.7.5 (Client Combo)
    OS X Lion 10.7.5 Supplemental Update

  • I would like to remove a short gray edge from two images. I need help in that I am not yet able to use PhotoShop. Could somebody kindly help me with this?

    I would like to remove a short gray edge from two images. I need help in that I am not yet able to use PhotoShop. Could somebody kindly help me with this?

    I doubt it Doc Maik, but I am certainly happy to learn The image is this one (and a similar one). They would be beautiful portraits if not for the "extra mouth". The grey edge that I would like to remove is the excess of (grey) mouth that is actually my horse's chin, but that in the pictures looks like a wider, looping mouth. Practically, looking at the picture, the "extra mouth" to the left. What I would love it to be able correct that to look like a normal mouth, which means that half of the protruding edge should be removed. I am not sure I was able to explain myself, but here is one of the two pictures. I thank you for you kindness in being available to advise me.

  • Could anyone here help me with using WebDynpro as view, and Adweb service

    Could anyone here help me with using WebDynpro as view, and Adaptive web service  as model, I am getting the following error message:
    Exception on execution of web service with WSDL URL 'D:\temp\MI_SEARCH.wsdl' with operation 'MI_SEARCH' in interface 'MI_SEARCH'.

    Hi,
    Could you check if it is the Installed JREs in Preference Page -> Java points to the jdk path and not the JRE.
    Regards,
    Nidhi

  • I upgrade succesfully my laptop OS from mountain lion to maverick. i have my canon IR 2530 driver installed. after i reset my printer, the driver is not showing from Printer Software. could you guys help me to solve these problem?

    I upgrade succesfully my laptop OS from mountain lion to maverick. i have my canon IR2530 driver installed. after I reset my printer and add again(Canon IR2530), the driver is not showing from Printer Software. could you guys help me to solve these problem?

    Maybe this thread will help:
    https://discussions.apple.com/message/23873672#23873672

  • Help! This probably sounds dumb, but I got my Ipod touch fourth generation yesterday and they said I could sync the music from my computer to the Ipod. Could you guys help me do that? All the websites I have looked on don't help. Thanks!

    Help! This probably sounds dumb, but I got my Ipod touch fourth generation yesterday and they said I could sync the music from my computer to the Ipod. Could you guys help me do that? All the websites I checked didn't help. Thanks!

    You need to read the manual
    Click Support at the top of this page, then click manuals
    Open itunes, connect ipod, select what you want, sync

  • Please help me with this calculation script

    Hello everyone.
    I have 2 fields named A and B. FieldA is user-enter value and FieldB is calculated. I want to write a script that do the following:
    If FieldA is more than or equal to $10000, then FieldB always is $1000, Else FieldB = FieldA * 10%.
    I don't know about scripting; however, after hour of search through google, I wrote this one:
    var tvar
    If (tvar >= 10000)then deposit.value = 1000
    else deposit.value = total.rawValue*0.01
    endif
    And when I try to run, it say "Invalid Property Set Operation, value doesn't have a default property."
    I know my script is bad and over the place. Can anyone please help me with this problem ASAP. Thank you so much, I'm in your debt.
    I used Adobe LiveCycle Designer to create a PDF file.

    Thank you for your response.
    tvar = total
    At first I wrote it like this:
    If (total.rawValue >= 10000)then deposit.rawvalue = 1000
    else deposit.rawvalue = total.rawValue*0.01
    endif
    then I get an error message "accessor 'Total.rawValue' is unknown"
    Hic, I think my script is screwed. Can you help me start fresh :)
    Thank again.

  • Could someone please help me with contact form php.

    Hi,
    could someone please help me wright the php for this contact form?
    <form class="contact_form" action="kontakt.php" method="post">
                <p><input type="text" required="required" id="contact_name" name="contact_name" class="text_input" value="" size="22"  />
                <label for="contact_name">Namn *</label></p>
                <p><input type="text" required="required" id="contact_company" name="contact_company" class="text_input" value="" size="22"  />
                <label for="contact_company">Företag *</label></p>
                <p><input type="email" required="required" id="contact_email" name="contact_email" class="text_input" value="" size="22"  />
                <label for="contact_email">Epost *</label></p>
                <p><textarea required="required" name="contact_content" class="textarea" cols="30" rows="5"></textarea></p>
                <p><button type="submit" class="button white"><span>Skicka</span></button></p>
                <input type="hidden" value="[email protected]" name="contact_to"/>
            </form>
    Its no sence writing down my php as it is useless.
    All help is appriciated.
    Thank you

    Please don't post duplicate threads. Continue the discussion in http://forums.adobe.com/thread/1080721.
    This thread is now locked.

  • Could someone please help me with getting the sabnzbd daemon to start?

    Hi everyone,
    I'm a classic newbie.  I managed to follow some instructions I found on the web to get sabnzbd to install (via Yaourt), and when I invoke it from the command line, it works fine.
    I've read that you can get it to start as a daemon, which would be really good.  Could someone please explain how this should be done?
    Where do I need to put the sabnzbd.init file?
    What about the sabnzbd.confd file?
    I'm okay enough with adding sabnzbd to the /etc/rc.conf file, but I can't quite configure it so that the necessary files are in place to start it.
    If you need any details of my setup, please let me know.
    Thanks heaps,
    Luke

    birdie101 wrote:Where would I find a good place to describe how to install programs using PKGBUILDs?  and what that process is actually doing?
    Apart from the wiki article on ABS, always look at the pkgbuild when in doubt. This is also helpful when you want to know what compile arguments are passed to GCC. Custom postinstall commands are run through .install file (example what is displayed after installation), this is generally foo.install in the AUR for a pkg named foo. And most importantly, familiarize yourself with compiling process, and Arch specific routines like a daemon should be defined in /etc/rc.d/, instead of /etc/init.d/ in other linuxes.
    Edit: A best exercise would be to create a pkgbuild yourself. Arch always recommends community contributions.
    Last edited by shemz (2010-09-24 08:08:14)

  • Could every one help me with this? Thanks

    2. a. Write a program that prompts a professor to input grades for five different courses for 10 students. Prompt the professor to enter one grade at a time using the prompt �Enter grades for student #1� and �Enter grade #1�. Verify that the professor enter only A, B, C, D, or F. Use variables for the student numbers (1 through 10) and grade numbers (1 through 5). The class name is GradePoint.
    b. Modify the GradePoint program so that it calculates the grade point average (GPA) for each student. A student receives four grade points for an A, three grade points for a B, two grade points for a C, one grade point for a D, and zero grade point for an F. Store the grades and points in parallel arrays. Search the arrays to determine the points for the grade. Store the GPA for each student in another array. (Hint: Copy the GPA for each student to a different array by initializing the new array with GPAs from the other array.)
    c. Display the GPA scores from each of the two GPA arrays to verify that the GPAs were copied correctly. Identify which array the scores are from.

    I got A. but I don't know how to do B and C
    could everyone help me how to do B and C?
    here are my code in A.
    I hope I am doing right:
    here are my code in A.
    I hope I am doing right:
    public class GradePoint
    public static void main(String[] args) throws Exception
    char Grade;
    System.out.println("Enter grades for student #1");
    System.out.println("Enter A, B, C, D, or F");     
    System.out.println("\nEnter grades #1");
    Grade =(char)System.in.read();
    while(Grade != 'A' && Grade != 'B' && Grade != 'C' && Grade != 'D' && Grade != 'D')
              System.in.read(); System.in.read();
              System.out.println("Entry must be A or B or C or D or F!");
              Grade = (char)System.in.read();
    System.out.println("Enter grades for student #2");
         System.out.println("Enter A, B, C, D, or F");
         System.out.println("Enter grades #2");
         Grade =(char)System.in.read();
         System.in.read();System.in.read();
    while(Grade != 'A' && Grade != 'B' && Grade != 'C' && Grade != 'D' && Grade != 'D')
              System.in.read(); System.in.read();
              System.out.println("Entry must be A or B or C or D or F!");
              Grade = (char)System.in.read();
    System.out.println("Enter grades for student #3");
         System.out.println("Enter A, B, C, D, or F");
         System.out.println("Enter grades #3");
         Grade = (char)System.in.read();
         System.in.read();System.in.read();
    while(Grade != 'A' && Grade != 'B' && Grade != 'C' && Grade != 'D' && Grade != 'D')
              System.in.read(); System.in.read();
              System.out.println("Entry must be A or B or C or D or F!");
              Grade = (char)System.in.read();
    System.out.println("Enter grades for student #4");
         System.out.println("Enter A, B, C, D, or F");
         System.out.println("Enter grades #4");
         Grade = (char)System.in.read();
         System.in.read();System.in.read();
    while(Grade != 'A' && Grade != 'B' && Grade != 'C' && Grade != 'D' && Grade != 'D')
              System.in.read(); System.in.read();
              System.out.println("Entry must be A or B or C or D or F!");
              Grade = (char)System.in.read();
    System.out.println("Enter grades for student #5");
         System.out.println("Enter A, B, C, D, or F");
         System.out.println("Enter grades #5");
         Grade = (char)System.in.read();
         System.in.read();System.in.read();
    while(Grade != 'A' && Grade != 'B' && Grade != 'C' && Grade != 'D' && Grade != 'D')
              System.in.read(); System.in.read();
              System.out.println("Entry must be A or B or C or D or F!");
              Grade = (char)System.in.read();
    System.out.println("Enter grades for student #6");
         System.out.println("Enter A, B, C, D, or F");
         System.out.println("Enter grades #6");
         Grade = (char)System.in.read();
         System.in.read();System.in.read();
    while(Grade != 'A' && Grade != 'B' && Grade != 'C' && Grade != 'D' && Grade != 'D')
              System.in.read(); System.in.read();
              System.out.println("Entry must be A or B or C or D or F!");
              Grade = (char)System.in.read();
    System.out.println("Enter grades for student #7");
         System.out.println("Enter A, B, C, D, or F");
         System.out.println("Enter grades #7");
         Grade = (char)System.in.read();
         System.in.read();System.in.read();
    while(Grade != 'A' && Grade != 'B' && Grade != 'C' && Grade != 'D' && Grade != 'D')
              System.in.read(); System.in.read();
              System.out.println("Entry must be A or B or C or D or F!");
              Grade = (char)System.in.read();
    System.out.println("Enter grades for student #8");
         System.out.println("Enter A, B, C, D, or F");
         System.out.println("Enter grades #8");
         Grade = (char)System.in.read();
         System.in.read();System.in.read();
    while(Grade != 'A' && Grade != 'B' && Grade != 'C' && Grade != 'D' && Grade != 'D')
              System.in.read(); System.in.read();
              System.out.println("Entry must be A or B or C or D or F!");
              Grade = (char)System.in.read();
    System.out.println("Enter grades for student #9");
         System.out.println("Enter A, B, C, D, or F");
         System.out.println("Enter grades #9");
         Grade = (char)System.in.read();
         System.in.read();System.in.read();
    while(Grade != 'A' && Grade != 'B' && Grade != 'C' && Grade != 'D' && Grade != 'D')
              System.in.read(); System.in.read();
              System.out.println("Entry must be A or B or C or D or F!");
              Grade = (char)System.in.read();
    System.out.println("Enter grades for student #10");
         System.out.println("Enter A, B, C, D, or F");
         System.out.println("Enter grades #10");
         Grade = (char)System.in.read();
         System.in.read();System.in.read();
    while(Grade != 'A' && Grade != 'B' && Grade != 'C' && Grade != 'D' && Grade != 'D')
              System.in.read(); System.in.read();
              System.out.println("Entry must be A or B or C or D or F!");
              Grade = (char)System.in.read();
    b. Modify the GradePoint program so that it calculates the grade point average (GPA) for each student. A student receives four grade points for an A, three grade points for a B, two grade points for a C, one grade point for a D, and zero grade point for an F. Store the grades and points in parallel arrays. Search the arrays to determine the points for the grade. Store the GPA for each student in another array. (Hint: Copy the GPA for each student to a different array by initializing the new array with GPAs from the other array.)
    c. Display the GPA scores from each of the two GPA arrays to verify that the GPAs were copied correctly. Identify which array the scores are from.

  • Plz guys help me with this one...

    hi,
    My MacBook currently has 512mb of ram which i think is not enough. I would like this ram
    http://www.crucial.com/uk/store/listparts.aspx?model=MacBook1%2E83GHz+Intel+Core+Duo+%2813%2DinchWhite%29
    which i am sure will work. i Am all ready to buy it apart from getting my mum to let me buy it even tho im paying for it :S
    Ive tried to convince her but its still a no so i need some help as to let me buy it
    tyvm Matt

    oh theres no budget issues for me i am holding down
    two jobs and as i have no debt card or credit card
    i cant order online apart from using my mums card
    which she won let me cos she does not understand what
    it atuchally does and in her eyes " dont fix it if it
    aint broken"
    Matt
    I understand how it feels on having no debit card/credit card as you mentioned. (as i personnaly don't have one either)
    If you are really into getting the ram, get a TRUSTWORTHY friend who has a card to pay for you and pay him in cash (as you mentioned theres no budget issue). (pay him first with cash)

Maybe you are looking for

  • Find the Difference in time for creation of two activities for the same SR

    Hi I need to find the difference in time of cretaion of two different activities for an SR. Is there any function which I can use to get the same For e.g. SR # |Activity Created Date |Duration 123 12-nov 123 13 nov 1 day Thanks in advance Meena

  • Can't add markers or in/out points in prelude- please help!

    I can't add the markers.  my keyboard is wireless one, works fine, but what is going on?  I get half the use of prelude due to this.

  • Access - How to create Mail Address only list?

    Printing envelopes from mail lists - via Microsoft Excel? Access - How to create Mail Address Only list? Bearing my "new boy" status, step by step instruction would be appreciated.

  • 5600XT/No idea how to work VIVO

    I've just assembeled this system with a FX5600XT-VTDR128. The book has nothing to say except that there is an attach for video in and video out. I've tried the forceware drivers, capture drivers, Media Center, etc. I'm back to the 5663 driver, the ne

  • Basic questions about high-quality output and PDFs

    I do volunteer work in a non-profit that interfaces with local county government.  We've been discussing a project to produce an atlas-type information as a service to the residents.  The maps would be rendered by the GIS software the county uses (ES