Created
November 17, 2016 14:01
-
-
Save NielsPilgaard/684132fa5dc1d0172c525ea5547d7bfa to your computer and use it in GitHub Desktop.
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 gui; | |
import application.model.Excursion; | |
import application.service.Service; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Alert; | |
import javafx.scene.control.Alert.AlertType; | |
import javafx.scene.control.Button; | |
import javafx.scene.control.Label; | |
import javafx.scene.control.TextField; | |
import javafx.scene.layout.GridPane; | |
import javafx.stage.Stage; | |
public class ExcursionWindow extends Stage { | |
private Excursion createdExcursion; | |
private TextField txfDescription, txfPrice; | |
private Button btnCreate, btnCancel; | |
private boolean newExcursion; | |
private Excursion excursion; | |
public ExcursionWindow(String title) { | |
createdExcursion = null; | |
setTitle(title); | |
GridPane pane = new GridPane(); | |
initContent(pane); | |
Scene scene = new Scene(pane); | |
setScene(scene); | |
} | |
private void initContent(GridPane pane) { | |
pane.setHgap(10); | |
pane.setVgap(10); | |
Label lblDescription = new Label("Description:"); | |
txfDescription = new TextField(); | |
pane.add(lblDescription, 0, 0); | |
pane.add(txfDescription, 1, 0); | |
Label lblPrice = new Label("Price:"); | |
txfPrice = new TextField(); | |
pane.add(lblPrice, 0, 1); | |
pane.add(txfPrice, 1, 1); | |
btnCreate = new Button("Create"); | |
pane.add(btnCreate, 0, 2); | |
btnCancel = new Button("Cancel"); | |
btnCancel.setOnAction(event -> cancelAction()); | |
pane.add(btnCancel, 1, 2); | |
} | |
public void createExcursion() { | |
setTitle("Create excursion"); | |
btnCreate.setText("Create"); | |
btnCreate.setOnAction(event -> createAction()); | |
} | |
private void createAction() { | |
String description = txfDescription.getText().trim(); | |
double price = Double.valueOf(txfPrice.getText().trim()); | |
try { | |
price = Double.valueOf(txfPrice.getText().trim()); | |
} catch (Exception e) { | |
price = 0; | |
if (description.length() != 0 || description != null) { | |
createdExcursion = Service.createExcursion(description, price); | |
newExcursion = true; | |
clearTextFields(); | |
hide(); | |
} else | |
{// TODO | |
Alert alert = new Alert(AlertType.INFORMATION); | |
alert.setTitle("Not enough information given"); | |
alert.setHeaderText("Give more information"); | |
alert.setContentText("You have to give an excursions description and price."); | |
alert.showAndWait(); | |
} | |
} | |
} | |
private void cancelAction() { | |
clearTextFields(); | |
newExcursion = false; | |
hide(); | |
} | |
private void clearTextFields() { | |
txfDescription.clear(); | |
txfPrice.clear(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment