GUI Calculator

  • (2 Pages)
  • +
  • 1
  • 2

24 Replies - 3529 Views - Last Post: 19 April 2010 - 03:01 PM Rate Topic: -----

#16 Djhar   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 35
  • Joined: 24-January 10

Re: GUI Calculator

Posted 19 April 2010 - 01:05 PM

View PostLittleMissy, on 19 April 2010 - 11:55 AM, said:

GOSH, no i am simply just trying to get this damn code to work out of the book. i been fliping threw trying to find out why it dont work and what im missing. IM SORRY IM SO F***ING Retarted.
anyways.
the book dont define the EXIT_ON_CLSOE so i was thinking it was a built in command.. same with the action thing.
thanks for make me feel like a dumb asss :stupid:


Didn't know cursing was allowed on the forums. I'm sorry if what I said came out as a bit rude but to be honest, I find it rude that you're forcing people to help you as quick as possible. There's a little thing called patience.
Was This Post Helpful? 0
  • +
  • -

#17 LittleMissy   User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 41
  • Joined: 24-March 10

Re: GUI Calculator

Posted 19 April 2010 - 01:15 PM

im not forcing anybody to do anything first off. and i thought this was for posting for help/posting to help people. NOT to make fun of them.
put them down
make them feel dumb
or what ever else your doing, plz dont post here enless your helping me not insalting me.
and yea, i do need help on this stupid little error that says that it pretty much needs defined. and i dont know what to define them as.... CAUSE IM COPING CODE STRAIT FROM THE BOOK
Dont got to make me cry :boat:
Was This Post Helpful? -1
  • +
  • -

#18 Djhar   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 35
  • Joined: 24-January 10

Re: GUI Calculator

Posted 19 April 2010 - 01:28 PM

View PostLittleMissy, on 19 April 2010 - 12:15 PM, said:

im not forcing anybody to do anything first off. and i thought this was for posting for help/posting to help people. NOT to make fun of them.
put them down
make them feel dumb
or what ever else your doing, plz dont post here enless your helping me not insalting me.
and yea, i do need help on this stupid little error that says that it pretty much needs defined. and i dont know what to define them as.... CAUSE IM COPING CODE STRAIT FROM THE BOOK
Dont got to make me cry :boat:


Ok, so then explain this: why give me negative rep on a post on a different thread I made from a long long time ago of which you had nothing to do with? Trying to set the score with me? Sorry but unlike you, I actually have respect for the people I talk to, something you'll eventually learn, I hope.

Also, you claim your copying straight from the book...this is exactly why I don't understand why you're having problems. Did you happen to read the part discussing the code? The codes in the textbook isn't just meant for you to copy but are a guide for you to get the general gist of the code and what it should look somewhat like. If every single code was copied straight from the book then efficiency in programming wouldn't serve any purpose.
Was This Post Helpful? 0
  • +
  • -

#19 LittleMissy   User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 41
  • Joined: 24-March 10

Re: GUI Calculator

Posted 19 April 2010 - 01:45 PM

I am reading the book... the only thing it says is that i can exchange the words EXIT ON CLOSE to DO_NOTHING_ON_EXIT.. which neither of them help, just like DjHar. no offence
Was This Post Helpful? 0
  • +
  • -

#20 Djhar   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 35
  • Joined: 24-January 10

Re: GUI Calculator

Posted 19 April 2010 - 01:51 PM

View PostLittleMissy, on 19 April 2010 - 12:45 PM, said:

I am reading the book... the only thing it says is that i can exchange the words EXIT ON CLOSE to DO_NOTHING_ON_EXIT.. which neither of them help, just like DjHar. no offence


Well, I don't want to waste my time, or yours by bickering on this situation so here you go

import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class Calc17 extends JFrame implements ActionListener{


        public static final int WIDTH = 500;
        public static final int HIGHT = 600;
        public static final int NUMBER_OF_DIGITS = 30;

        private JTextField ioField;
        private double result = 0.0;

        public static void main(String[] args){
                Calc17 aCalculator = new Calc17();
                aCalculator.setVisible(true);
        }


        public Calc17(){
                setTitle("Calculator");
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                setSize(WIDTH, HIGHT);
                setLayout(new BorderLayout());

                JPanel textPanel = new JPanel();
                textPanel.setLayout(new FlowLayout());
                ioField = new JTextField("Enter numbers here.", NUMBER_OF_DIGITS);
                ioField.setBackground(Color.WHITE);
                textPanel.add(ioField);
                add(textPanel, BorderLayout.NORTH);
                JPanel buttonPanel = new JPanel();
                buttonPanel.setBackground(Color.BLUE);
                buttonPanel.setLayout(new FlowLayout());

                JButton addButton = new JButton("+");
                addButton.addActionListener(this);
                buttonPanel.add(addButton);

                JButton subtractButton = new JButton("-");
                addButton.addActionListener(this);
                buttonPanel.add(subtractButton);

                JButton resetButton = new JButton("Reset");
                addButton.addActionListener(this);
                buttonPanel.add(resetButton);

                add(buttonPanel, BorderLayout.CENTER);
        }

public void actionPerformed(ActionEvent e){
        try{
                assumingCorrectNumberFormates(e);
        }
        catch(NumberFormatException e2){
                ioField.setText("Error: Reenter Number.");
        }
}

public void assumingCorrectNumberFormates(ActionEvent e){
        String actionCommand = e.getActionCommand();

        if(actionCommand.equals("+")){
                result = result + stringToDouble(ioField.getText());
                ioField.setText(Double.toString(result));
        }
                else if (actionCommand.equals("-")){
                                        result = result - stringToDouble(ioField.getText());
                ioField.setText(Double.toString(result));
                }
                                else if (actionCommand.equals("Reset")){
                                                        result = 0.0;
                                ioField.setText("0.0");
                        }
                                else
                                        ioField.setText("Unexpected error.");
}

private static double stringToDouble(String stringObject){
        return Double.parseDouble(stringObject.trim());
}

}



Should run just fine then
Was This Post Helpful? 0
  • +
  • -

#21 LittleMissy   User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 41
  • Joined: 24-March 10

Re: GUI Calculator

Posted 19 April 2010 - 02:05 PM

OMG THANK YOU! it does work, but i really didnt need the whole code, i just wanted to know why mine didnt work. your command seems to work fine and it looks just like mine. i will have to check out and see why. thankies. :gunsmilie:
NOW TO MAKE IT BETTER :bananaman:
Was This Post Helpful? 0
  • +
  • -

#22 Djhar   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 35
  • Joined: 24-January 10

Re: GUI Calculator

Posted 19 April 2010 - 02:07 PM

View PostLittleMissy, on 19 April 2010 - 01:05 PM, said:

OMG THANK YOU! it does work, but i really didnt need the whole code, i just wanted to know why mine didnt work. your command seems to work fine and it looks just like mine. i will have to check out and see why. thankies. :gunsmilie:
NOW TO MAKE IT BETTER :bananaman:


Ah, they were just spelling errors. By the way, I'd appreciate my rep back as a way of "thank you" please.
Was This Post Helpful? 1
  • +
  • -

#23 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2975
  • View blog
  • Posts: 11,224
  • Joined: 15-July 08

Re: GUI Calculator

Posted 19 April 2010 - 02:43 PM

You didn't copy straight from the book...you changed the class name right? Well that's the issue, you have a Calculator() constructor and make a Calculator object in you main, but you have a calc17 class instead. Rename the class to be Calculator and you should be ok.

edit: This was your other post....

This post has been edited by Dogstopper: 19 April 2010 - 02:59 PM

Was This Post Helpful? 0
  • +
  • -

#24 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: GUI Calculator

Posted 19 April 2010 - 02:44 PM

View Postmacosxnerd101, on 19 April 2010 - 02:33 PM, said:

You misspelled all three of those in your code. Note that Format is spelled without an 'e' in NumberFormatException.

@Djhar: Beat you to it. :P At the rate the OP is going though, I wouldn't expect an upvote for pointing that out, as I got downed for pointing it out.

@LittleMissy: I think if you took a closer look, you would have found that you spelled CLOSE as CLSOE in EXIT_ON_CLOSE; and Action as Actoin in getActionCommand(). Djhar was very generous in correcting your code for you, and he also made a valid point. He didn't call you stupid at all, by the way. That point was that you should put a little effort into following through on our suggestions (which was to check your spelling on those three lines, as I was right about the NumberFormatException), which may not always be a "this is wrong, type this in its place" type answer. Instead, we try to point members in the right directions so they can solve the problems and learn from them. And by the way, if you want continued help, you should show members who attempt to help a little respect, as they are all volunteers. So if you don't like someone's answer, do the courtesy of noting so for the given post. The whole point of the "rep" system is to highlight good and bad answers, so that future DICs can better learn from this thread.

Also, you should check out SwiftStriker00's tutorial on Fixing Your Own Errors For Beginners. It does cover the Cannot Find Symbol Error.
Was This Post Helpful? 1
  • +
  • -

#25 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2975
  • View blog
  • Posts: 11,224
  • Joined: 15-July 08

Re: GUI Calculator

Posted 19 April 2010 - 03:01 PM

Topics. Merged. I helped in your other topic.

If you continue being rude to out members INCLUDING bumping incessantly, double posting, etc, your topic WILL be closed and you will be reported to the administrators. Please do NOT be rude to those trying to help you!

This is your warning.
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2