Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sample;
- import javafx.application.Application;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.stage.Stage;
- import java.io.IOException;
- public class Main extends Application {
- @Override
- public void start(Stage primaryStage) throws Exception {
- try {
- Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
- primaryStage.setTitle("Hello World");
- primaryStage.setScene(new Scene(root));
- primaryStage.show();
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
- package sample;
- import javafx.fxml.FXML;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextField;
- import javafx.stage.Stage;
- import java.io.IOException;
- public class Controller {
- private String c;
- private String d;
- private int b=0;
- @FXML
- private TextField zakres;
- @FXML
- private TextField args;
- @FXML
- private Label label;
- @FXML
- void akcja() {
- try {
- c = zakres.getText();
- d = args.getText();
- int a = Integer.parseInt(c);
- b = Integer.parseInt(d);
- try {
- Parent root1 = FXMLLoader.load(getClass().getResource("sample2.fxml"));
- Stage stage = new Stage();
- stage.setTitle("My New Stage Title");
- stage.setScene(new Scene(root1));
- stage.show();
- label.setText("Dane: " + c + "\t" + d);
- } catch (IOException e) {
- e.printStackTrace();
- }
- } catch (NumberFormatException e) {
- label.setText("Nieprawidłowe dane: " + c + "\t" + d);
- }
- }
- @FXML
- private TextField args2;
- @FXML
- private Label wyniki;
- @FXML
- private Button ok;
- @FXML
- private Label kom;
- @FXML
- public void akcja2() throws Exception {
- try {
- String parameters = args2.getText();
- String[] parameterpParts = parameters.split(" ");
- System.out.println();
- if (parameterpParts.length != b){ ////////////////////////// <<<<<<<<<<<<<< HERE
- kom.setText("Swietnie");
- } else throw new Exception();
- } catch (Exception a) {
- kom.setText("Nieprawidlowa ilosc argumentow");
- }
- }
- }
- <?import javafx.scene.control.Button?>
- <?import javafx.scene.control.Label?>
- <?import javafx.scene.layout.Pane?>
- <?import javafx.scene.control.TextField?>
- <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">
- <children>
- <Label layoutX="147.0" layoutY="180.0" text="Podaj zakres:" />
- <Label layoutX="147.0" layoutY="259.0" text="Podai ilosc argumentow:" />
- <TextField fx:id="zakres" layoutX="324.0" layoutY="176.0" />
- <TextField fx:id="args" layoutX="324.0" layoutY="255.0" />
- <Button fx:id="przycisk" layoutX="473.0" layoutY="333.0" mnemonicParsing="false" onAction="#akcja" text="Button" />
- <Label fx:id="label" layoutX="80.0" layoutY="307.0" prefHeight="62.0" prefWidth="382.0" />
- </children>
- </Pane>
- <?xml version="1.0" encoding="UTF-8"?>
- <?import javafx.scene.control.*?>
- <?import javafx.scene.layout.*?>
- <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">
- <children>
- <Label layoutX="134.0" layoutY="160.0" text="Dane: " />
- <TextField fx:id="args2" layoutX="300.0" layoutY="156.0" />
- <Label fx:id="wyniki" layoutX="134.0" layoutY="200.0" prefHeight="117.0" prefWidth="314.0" text="Wyniki: " />
- <Button fx:id="ok" layoutX="475.0" layoutY="317.0" mnemonicParsing="false" onAction="#akcja2" text="ok" />
- <Label fx:id="kom" layoutX="55.0" layoutY="321.0" prefHeight="17.0" prefWidth="345.0" />
- </children>
- </Pane>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement