Advertisement
Guest User

Untitled

a guest
May 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. class BoxHanterare implements EventHandler<ActionEvent>{
  2. public void handle(ActionEvent event) {
  3. if (comboBox.getValue().toString().equalsIgnoreCase("smycke")) {
  4. try {
  5. SmyckeAlert dialog = new SmyckeAlert();
  6. Optional<ButtonType> result = dialog.showAndWait();
  7. if (result.isPresent() && result.get() == ButtonType.OK) {
  8. String name = dialog.getName();
  9. int stones = dialog.getStones();
  10. boolean isGold = dialog.isGold();
  11. Smycke smy = new Smycke(name, stones, isGold);
  12. värdesaker.add(smy);
  13. }
  14. }
  15. catch(RuntimeException e){
  16. Alert msg = new Alert(Alert.AlertType.ERROR);
  17. msg.setContentText("Fel inmatning");
  18. msg.showAndWait();
  19. }
  20. } else if(comboBox.getValue().toString().equalsIgnoreCase("aktie")) {
  21. try {
  22. AktieAlert dialog = new AktieAlert();
  23. Optional<ButtonType> result = dialog.showAndWait();
  24. if (result.isPresent() && result.get() == ButtonType.OK) {
  25. String name = dialog.getName();
  26. if (name.isEmpty()) {
  27. Alert msg = new Alert(Alert.AlertType.ERROR, "Tomt namn");
  28. }
  29. double amount = dialog.getAmount();
  30. double price = dialog.getPrice();
  31. Aktie akt = new Aktie(name, amount, price);
  32. värdesaker.add(akt);
  33. }
  34. }
  35. catch(RuntimeException e){
  36. Alert msg = new Alert(Alert.AlertType.ERROR);
  37. msg.setContentText("Fel inmatning");
  38. msg.showAndWait();
  39. }
  40.  
  41. } else if (comboBox.getValue().toString().equalsIgnoreCase("apparat")){
  42. try {
  43. ApparatAlert dialog = new ApparatAlert();
  44. Optional<ButtonType> result = dialog.showAndWait();
  45. if (result.isPresent() && result.get() == ButtonType.OK) {
  46. String name = dialog.getName();
  47. if (name.isEmpty()) {
  48. Alert msg = new Alert(Alert.AlertType.ERROR, "Tomt namn");
  49. }
  50. double price = dialog.getPrice();
  51. double wear = dialog.getWear();
  52. Apparat app = new Apparat(name, price, wear);
  53. värdesaker.add(app);
  54. }
  55. }
  56. catch(RuntimeException e){
  57. Alert msg = new Alert(Alert.AlertType.ERROR);
  58. msg.setContentText("Fel inmatning");
  59. msg.showAndWait();
  60. }
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement