File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Adding .binary and hexidecimal to an answer from a calculation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Adding .binary and hexidecimal to an answer from a calculation" Watch "Adding .binary and hexidecimal to an answer from a calculation" New topic

Adding .binary and hexidecimal to an answer from a calculation

Johnny Gambles

Joined: Mar 17, 2006
Posts: 2
Hi guys, sorry if this is too much of a beginners question to be in here, but I'm trying to add a binary and hexidecimal method to a string. But the string has a comment which has writing in it. So I was just wondering how to change this for use in a calculator

For example here is my multiply button

aButton3.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent b)
int z;
x = Integer.parseInt(aTextField1.getText());
y = Integer.parseInt(aTextField2.getText());
z = x * y;
String c = new String(x + " x " + y + " = " + z);
aButton3.setPreferredSize(new Dimension(x, y));

This is just one of my 7 buttons used, I wont quote them all for space, but I needed a button which will use the .toHexString and .toBinaryString to the 'atextField3'

THe user will enter data in text field a, then in text field b and then recieve an answer along the lines of "12 + 12 = 24" in text field c. In the field d I want to get the answer from text field c and change that into binary. Also the text field c MUST have "12 + 12 = 24" in it without fail

If any help can be issued, I'll be majorly greatful, thanks!
[ March 17, 2006: Message edited by: Johnny Gambles ]
Charles Lyons
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
So you know the values of the two original numbers (x and y), so why don't you just convert those, then place the result in field D - just as you did with field C? For example, suppose 'x' and 'y' represent the values of the fields A and B, then (adjust my variable names as appropriate):

Does that help?

Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
I agree. Here's the link:
subject: Adding .binary and hexidecimal to an answer from a calculation
It's not a secret anymore!