Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding .binary and hexidecimal to an answer from a calculation

 
Johnny Gambles
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
aTextField3.setText(c);
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
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic