I played with AngularJS during the last couple of days and started to build a small application to test my Java knowledge. You can play with it too, here.
If you like it, please drop me a Java technical interview-like question in the comments below. I will include your question in the quizzes.
The HTML source of the application is here, and its controller here.
Let's have fun while studying Java!
Sunday, 9 November 2014
Friday, 24 October 2014
Updating A JavaFX Component From A TimerTask Callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Controller implements BidListener{ | |
//Bid emulator | |
private static BidEmulator bidEmulator; | |
@FXML | |
TextArea simulatorConsole; | |
@FXML | |
private void handleStartSimulationButtonClicked(ActionEvent ae){ | |
//Initialize bid emulator | |
bidEmulator = new BidEmulator(); | |
//Register this class as a listener | |
bidEmulator.addListener(this); | |
//start bidding process emulation | |
Timer timer = new Timer(); | |
timer.scheduleAtFixedRate(bidEmulator, 0, 100); | |
} | |
@Override | |
public void bidEvent(Bid bid) { | |
Platform.runLater(() -> simulatorConsole.setText(simulatorConsole.getText() +"Received a new bid!\n" )); | |
} | |
} |
Friday, 17 October 2014
Simple JavaFX FXML Calculator Using Bindings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package application; | |
import javax.annotation.PostConstruct; | |
import javafx.beans.binding.Bindings; | |
import javafx.beans.binding.NumberBinding; | |
import javafx.beans.property.DoubleProperty; | |
import javafx.beans.property.SimpleDoubleProperty; | |
import javafx.fxml.FXML; | |
import javafx.scene.control.TextField; | |
import javafx.util.StringConverter; | |
import javafx.util.converter.DoubleStringConverter; | |
public class CalculatorController{ | |
@FXML | |
private TextField number1TextField; | |
@FXML | |
private TextField number2TextField; | |
@FXML | |
private TextField sumTextField; | |
@FXML | |
private TextField difTextField; | |
@FXML | |
private TextField multTextField; | |
@FXML | |
private TextField divTextField; | |
// private NumberBinding sum, dif, mult, div; | |
private DoubleProperty num1, num2, suma, dif, mult, div; | |
// @PostConstruct | |
@FXML | |
private void initialize(){ | |
num1 = new SimpleDoubleProperty(1); | |
num2 = new SimpleDoubleProperty(2); | |
suma = new SimpleDoubleProperty(); | |
dif = new SimpleDoubleProperty(); | |
mult = new SimpleDoubleProperty(); | |
div = new SimpleDoubleProperty(); | |
suma.bind(num1.add(num2)); | |
dif.bind(num1.subtract(num2)); | |
mult.bind(num1.multiply(num2)); | |
div.bind(num1.divide(num2)); | |
StringConverter<? extends Number> converter = new DoubleStringConverter(); | |
Bindings.bindBidirectional(number1TextField.textProperty(), num1, (StringConverter<Number>)converter); | |
Bindings.bindBidirectional(number2TextField.textProperty(), num2, (StringConverter<Number>)converter); | |
Bindings.bindBidirectional(sumTextField.textProperty(), suma, (StringConverter<Number>)converter); | |
Bindings.bindBidirectional(difTextField.textProperty(), dif, (StringConverter<Number>)converter); | |
Bindings.bindBidirectional(multTextField.textProperty(), mult, (StringConverter<Number>)converter); | |
Bindings.bindBidirectional(divTextField.textProperty(), div, (StringConverter<Number>)converter); | |
} | |
} |
Wednesday, 10 September 2014
Wednesday, 14 May 2014
Tuesday, 6 May 2014
Rewriting The JavaFX Calculator Using Lambdas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//create buttons | |
Button seven = new Button("7"); | |
seven.setOnMouseClicked(e -> { | |
displayField.setText(displayField.getText() + "7"); | |
}); | |
seven.setPrefWidth(PREF_BUTTON_WIDTH); | |
moreButtons.add(seven,0,0); |
Saturday, 29 March 2014
Thursday, 6 March 2014
Eventually I added a basic calculator engine to my JavaFX Calculator.
https://code.google.com/p/learn-javafx/source/browse/Calculator/AdvancedCalculator.java
https://code.google.com/p/learn-javafx/source/browse/Calculator/AdvancedCalculator.java
Subscribe to:
Posts (Atom)