This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Programming Help (conversions)  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am currently writing a program which will perform binary to decimal, decimal to binary, hexadecimal to decimal, decimal to hexadecimal conversions, 1's compliment, 2's compliment, and show the list of boolean algebra rules.

I have created the GUI however, I cannot figure out how to make the Jbuttons generate the coding needed for a binary to decimal conversion of the input in a JTextField. The code is below:



 
Marshal
Posts: 58336
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch It seems appropriate to have a Wmurphy signed on on 17th March

What is the logic for converting, eg binary to denary (decimal) without using a button? I presume you are doing the conversion yourself and not using % tags in the format or printf methods?
 
Campbell Ritchie
Marshal
Posts: 58336
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't want to have lots of frames inside your actionPerformed methods. You have one frame with lots of buttons attached; each button has its own Listener. That Listener calls a method to read the number, one to convert it and one to display it.
 
James Wmurphy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know my formatting isn't the best , but it also shows my level of expertise with dealing with Java on a GUI level. If you could help me format my existing code as well as show me how to convert user input from binary to decimal, it would greatly be appreciated.
 
author
Marshal
Posts: 23435
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

James Wmurphy wrote:I know my formatting isn't the best , but it also shows my level of expertise with dealing with Java on a GUI level. If you could help me format my existing code as well as show me how to convert user input from binary to decimal, it would greatly be appreciated.



Maybe it would be a good idea to not use GUI first -- say just work out a very simple method that will convert a number from one base to another. Once you get that working, then you can attach it to a GUI.

Henry

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!