/* * This file is created with Netbeans 6 Plug-In for JavaFX */ import javafx.ui.Frame; import javafx.ui.Label; import javafx.ui.TextField; import javafx.ui.Button; import java.io.*; import java.lang.System; import java.text.*; import javafx.ui.*; class tempReading { attribute CelsiusTemp: String; attribute FarenheitTemp: String; } var temp = tempReading { CelsiusTemp: "Enter a value" FarenheitTemp: " Farenheit" }; Frame { title: "Celsius Converter " content: GroupPanel { var InputRow = Row { alignment: BASELINE } var OutputRow = Row { alignment: BASELINE } var labelsColumn = Column { alignment: TRAILING } var fieldsColumn = Column { alignment: LEADING resizable: true } rows: [InputRow, OutputRow] columns: [fieldsColumn,labelsColumn] content: [ TextField { row: InputRow column: fieldsColumn columns: 25 //Binding the Celsius Temperature attribute to TextField value: bind temp.CelsiusTemp }, SimpleLabel { row: InputRow column: labelsColumn text: "Celsius" }, SimpleLabel { row: OutputRow column: labelsColumn //Binding the Farenheit Temperature attribute to label text: bind temp.FarenheitTemp }, Button { row: OutputRow column: fieldsColumn text: "Convert" toolTipText: "Press this button to Convert to Farenheit" action: operation() { System.out.println("Button Pressed"); System.out.println(temp.CelsiusTemp); try{ // Convert String to Number var CelsiusValue = new DecimalFormat("0").parse(temp.CelsiusTemp); System.out.println(CelsiusValue); var Fahtemp = (9/5 * CelsiusValue + 32); System.out.println(Fahtemp); temp.FarenheitTemp = " Fahrenheit"; //String Concatenation temp.FarenheitTemp = Fahtemp.toString().concat(temp.FarenheitTemp); // If the input cannot be converted catch ParseExcpetion }catch (e:ParseException) { System.out.println("Bad Input"); temp.FarenheitTemp = " Fahrenheit"; temp.CelsiusTemp = "Please enter a valid number"; } } }] } visible: true };