Binary to Decimal Conversion
807588Apr 23 2009 — edited Apr 23 2009Hello there
i am new to java programming and need to build a java programme, i am using the new netbeans but my problem is that i do not know how to convert binary to decimal.
this is my programme so far which is used from a similar programme but that programme was for imperialMeasure to metricMeasure.
i need to change the imperialMeasure to Binary and the metricMeasure to Decimal.
this is my programme so far..could anyone tell me what i need to add and where? as i dont know alot about java programming
import java.awt.Color as CL
import javax.swing.border.BevelBorder
import javax.swing.SwingConstants as SC
import javax.swing.WindowConstants as WC
import groovy.swing.SwingBuilder
import net. miginfocom.swing.MigLayout
def swingB = new SwingBuilder()
def migLayout = new MigLayout(layoutConstraints: 'fill')
def doConvert = {event ->
def imperialText = swingB.imperialTextField.text
def imperialMeasure = imperialText.toDouble()
def metricMeasure = 2.54* imperialMeasure
def metricText = metricMeasure.toString()
swingB.metricTextField.text = metricText
}
def doExit = { event ->
System.exit(0)
}
swingB.actions{
action(id: 'exitAction', name: 'Exit', closure: doExit)
action(id: 'inputAction', name: '0', closure: doConvert)
}
def buildContentPane = { builder ->
builder.panel(background: CL.WHITE, layout: migLayout){
panel(constraints: 'dock north', border: new BevelBorder(BevelBorder.RAISED), layout: new
MigLayout(layoutConstraints: 'fillx'))
panel(opaque: false, layout:new MigLayout()){
label(text: 'Binary', foreground: CL.BLACK, constraints: 'wrap')
textField(id: 'imperialTextField', text:'', columns:20,actionPerformed:doConvert, constraints: 'wrap')
label(text: 'Metric', foreground: CL.BLACK, constraints: 'wrap')
textField(id: 'metricTextField', text: '', columns: 20, enabled: false, constraints: 'wrap')
}
panel(constraints: 'dock south', border: lineBorder(color: CL.BLACK)){
button(action: exitAction)
}
}
}
def frame = swingB.frame(title:'Binary', location: [100, 100], size: [700, 500],
defaultCloseOperation: WC.EXIT_ON_CLOSE){
buildContentPane(delegate)
}
swingB.doLater{ frame.visible = true}