Skip to content

Instantly share code, notes, and snippets.

@aleroddepaz
Created March 3, 2014 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aleroddepaz/9334685 to your computer and use it in GitHub Desktop.
Save aleroddepaz/9334685 to your computer and use it in GitHub Desktop.
JavaFX example application
public class HelloWorld extends Application {
private Calculator calculatorService;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws MalformedURLException {
URL url = new URL("http://10.152.34.131:7001/CalculatorImpl/CalculatorService?WSDL");
QName qName = new QName("http://example.org/services/calculator", "CalculatorService");
Service service = Service.create(url, qName);
calculatorService = service.getPort(Calculator.class);
primaryStage.setTitle("Hello World!");
final TextField operatorField1 = new TextField();
final TextField operatorField2 = new TextField();
final Button addButton = new Button("Add");
final Button multiplyButton = new Button("Multiply");
final Label result = new Label();
addButton.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
try {
int a = Integer.parseInt(operatorField1.getText());
int b = Integer.parseInt(operatorField2.getText());
result.setText(String.format("The result is %s", calculatorService.add(a, b)));
} catch (Exception e) {
result.setText("Formato incorrecto");
}
}
});
multiplyButton.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
try {
int a = Integer.parseInt(operatorField1.getText());
int b = Integer.parseInt(operatorField2.getText());
result.setText(String.format("The result is %s", calculatorService.multiply(a, b)));
} catch (Exception e) {
result.setText("Formato incorrecto");
}
}
});
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.add(operatorField1, 0, 0, 2, 1);
grid.add(operatorField2, 0, 1, 2, 1);
grid.add(addButton, 0, 2);
grid.add(multiplyButton, 1, 2);
grid.add(result, 0, 3, 2, 1);
primaryStage.setScene(new Scene(grid, 300, 250));
primaryStage.show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment