Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. package sample;
  2.  
  3.  
  4. import javafx.application.Application;
  5. import javafx.fxml.FXMLLoader;
  6. import javafx.scene.Parent;
  7. import javafx.scene.Scene;
  8. import javafx.stage.Stage;
  9.  
  10. import java.io.IOException;
  11.  
  12. public class Main extends Application {
  13.  
  14. @Override
  15. public void start(Stage primaryStage) throws Exception {
  16. try {
  17. Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
  18. primaryStage.setTitle("Hello World");
  19. primaryStage.setScene(new Scene(root));
  20. primaryStage.show();
  21.  
  22. }
  23. catch (IOException e) {
  24. e.printStackTrace();
  25. }
  26. }
  27.  
  28.  
  29.  
  30. public static void main(String[] args) {
  31. launch(args);
  32. }
  33. }
  34. package sample;
  35.  
  36. import javafx.fxml.FXML;
  37. import javafx.fxml.FXMLLoader;
  38. import javafx.scene.Parent;
  39. import javafx.scene.Scene;
  40. import javafx.scene.control.Button;
  41. import javafx.scene.control.Label;
  42. import javafx.scene.control.TextField;
  43. import javafx.stage.Stage;
  44.  
  45. import java.io.IOException;
  46.  
  47. public class Controller {
  48.  
  49. private String c;
  50. private String d;
  51. private int b=0;
  52.  
  53. @FXML
  54. private TextField zakres;
  55.  
  56. @FXML
  57. private TextField args;
  58.  
  59. @FXML
  60. private Label label;
  61.  
  62. @FXML
  63. void akcja() {
  64. try {
  65. c = zakres.getText();
  66. d = args.getText();
  67. int a = Integer.parseInt(c);
  68. b = Integer.parseInt(d);
  69. try {
  70. Parent root1 = FXMLLoader.load(getClass().getResource("sample2.fxml"));
  71. Stage stage = new Stage();
  72. stage.setTitle("My New Stage Title");
  73. stage.setScene(new Scene(root1));
  74. stage.show();
  75. label.setText("Dane: " + c + "\t" + d);
  76.  
  77. } catch (IOException e) {
  78. e.printStackTrace();
  79. }
  80. } catch (NumberFormatException e) {
  81. label.setText("Nieprawidłowe dane: " + c + "\t" + d);
  82. }
  83.  
  84. }
  85.  
  86. @FXML
  87. private TextField args2;
  88. @FXML
  89. private Label wyniki;
  90. @FXML
  91. private Button ok;
  92. @FXML
  93. private Label kom;
  94.  
  95. @FXML
  96. public void akcja2() throws Exception {
  97.  
  98.  
  99. try {
  100. String parameters = args2.getText();
  101. String[] parameterpParts = parameters.split(" ");
  102. System.out.println();
  103.  
  104. if (parameterpParts.length != b){ ////////////////////////// <<<<<<<<<<<<<< HERE
  105. kom.setText("Swietnie");
  106. } else throw new Exception();
  107. } catch (Exception a) {
  108. kom.setText("Nieprawidlowa ilosc argumentow");
  109. }
  110. }
  111. }
  112.  
  113.  
  114.  
  115.  
  116. <?import javafx.scene.control.Button?>
  117. <?import javafx.scene.control.Label?>
  118.  
  119. <?import javafx.scene.layout.Pane?>
  120. <?import javafx.scene.control.TextField?>
  121. <Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
  122. <children>
  123. <Label layoutX="147.0" layoutY="180.0" text="Podaj zakres:" />
  124. <Label layoutX="147.0" layoutY="259.0" text="Podai ilosc argumentow:" />
  125. <TextField fx:id="zakres" layoutX="324.0" layoutY="176.0" />
  126. <TextField fx:id="args" layoutX="324.0" layoutY="255.0" />
  127. <Button fx:id="przycisk" layoutX="473.0" layoutY="333.0" mnemonicParsing="false" onAction="#akcja" text="Button" />
  128. <Label fx:id="label" layoutX="80.0" layoutY="307.0" prefHeight="62.0" prefWidth="382.0" />
  129. </children>
  130. </Pane>
  131. <?xml version="1.0" encoding="UTF-8"?>
  132.  
  133. <?import javafx.scene.control.*?>
  134. <?import javafx.scene.layout.*?>
  135. <Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
  136. <children>
  137. <Label layoutX="134.0" layoutY="160.0" text="Dane: " />
  138. <TextField fx:id="args2" layoutX="300.0" layoutY="156.0" />
  139. <Label fx:id="wyniki" layoutX="134.0" layoutY="200.0" prefHeight="117.0" prefWidth="314.0" text="Wyniki: " />
  140. <Button fx:id="ok" layoutX="475.0" layoutY="317.0" mnemonicParsing="false" onAction="#akcja2" text="ok" />
  141. <Label fx:id="kom" layoutX="55.0" layoutY="321.0" prefHeight="17.0" prefWidth="345.0" />
  142. </children>
  143. </Pane>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement