monsterbb1's Profile
Reputation: 0
Apprentice
- Group:
- New Members
- Active Posts:
- 4 (0.01 per day)
- Joined:
- 02-June 11
- Profile Views:
- 125
- Last Active:
Jun 07 2011 03:03 PM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: JFrame Calculator. It will only add single-digit numbers.
Posted 6 Jun 2011
ok, but can you tell me why you said
if (text.indexOf('+')>-1)
textField1.setText(""+(a+
);
else if (text.indexOf('-')>-1)
textField1.setText(""+(a-
);
else if (text.indexOf('*')>-1)
textField1.setText(""+(a*
);
else if(text.indexOf('/')>-1)
textField1.setText(""+(a/
);
why is the index > -1? I mean what is this part of the code doing explicitly? -
In Topic: JFrame Calculator. It will only add single-digit numbers.
Posted 2 Jun 2011
thank you so much. I didn't know anything about StringTokenizer but this makes a lot more sense when using calculators. -
In Topic: JFrame Calculator. It will only add single-digit numbers.
Posted 2 Jun 2011
immeraufdemhund, on 02 June 2011 - 08:47 PM, said:2 things you should look at. One learning how to parse your string from your text field so that it can split up your numbers for you. 2nd clean up some of your code in your Calculator method. You called setSize(100,150); a million times. What your setting is the size of your frame over and over again. Your not changing the size of your button (which I think you were trying to do) if you want to change the size of your buttons then you do something like num0.setSize(100,150); or use num0.setPreferredSize(new Dimension(100,150));
Once I find the post that talks about how to make your own parser I'll edit this post and give you the link. I used it my self.
*edit*
http://www.dreaminco..._1&#entry974026
funny thing is I AM the one who asked the question! hahaha. Atleast I remembered that I found a answer to that problem!
Can you just help me with the single digit problem please....do not worry about shrinking my code. It's an emergency right now actually. All I need is to make the calc read more than one digit. Please help me!!!
*edit again*
so I've been playing with your code a bit and it can shrink a BUNCH! It seems that some of it is generated, and some of it is you. A few tips I would like to give you is to combine like code together. In other words move all the setters for your JFrame together. Also don't add a component to a container until it is done being changed. Also consider going to one actionlistener. Last thing is I would have 1 JTextArea and 1 JLabel. The JTextArea would replace your JTextField. The JLabel would be for your answer. with JTextArea you can append all your button strings together. Also set editable to false for your JTextArea. Let me show you what I did for your buttons.
String[] buttText = {"0","1","2","3","4","5","6","7","8","9","+","-","*","/","=","C"}; for (int a=0; a<buttText.length; a++) { JButton numButt = new JButton(buttText[a]); numButt.setFont(bigf); numButt.addActionListener(new bListener()); add(numButt); }
that small bit of code does the exact same thing as your old code did with the exception of your button that had the =.
that is all I have for now.
Can you just help me fix the single digit problem. Don't worry about shrinking the code. Please I just need to fix the single digit problem. It's an emergency. I will be very thankful!!!
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Private
Friends
|
|


Find Topics
Find Posts
View Reputation Given


|
Comments
monsterbb1 has no profile comments yet. Why not say hello?