Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tsnsoft/tsn_idea_javafx_calc

Пример визуального приложения на JavaFX11 для IntelliJ IDEA на Java
https://github.com/tsnsoft/tsn_idea_javafx_calc

demo intellij intellij-idea java javafx javafx-11 javafx-application linux

Last synced: 28 days ago
JSON representation

Пример визуального приложения на JavaFX11 для IntelliJ IDEA на Java

Awesome Lists containing this project

README

        

# TSN_Idea_JavaFX_Calc
Пример визуального приложения на JavaFX11 для IntelliJ IDEA на Java

![screenshot](screenshot.png)

```
java -jar --module-path /opt/javafx-sdk-11.0.2/lib --add-modules javafx.controls,javafx.fxml ./out/artifacts/JavaFxApplication_jar/JavaFxApplication.jar
```

Main.java
```
package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;

public class Main extends Application {

@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setScene(new Scene(root));
primaryStage.getIcons().add(new Image("/image/icon.jpg"));
primaryStage.setResizable(false);
primaryStage.setTitle("Создание простейшей программы");
primaryStage.show();
}

public static void main(String[] args) {
launch(args);
}
}
```

Controller.java
```
package sample;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;

import javax.swing.*;
import java.awt.*;
import java.net.URL;
import java.util.ResourceBundle;

public class Controller implements Initializable {

@FXML
private Label label_answer;
@FXML
private TextField textField_A;
@FXML
private TextField textField_B;
@FXML
private TextField textField_X;
@FXML
private TextField textField_D;

@Override
public void initialize(URL url, ResourceBundle rb) {
}

@FXML
private void buttonMathAction() {
double a, b, x, d, y;
try {
a = Double.parseDouble(textField_A.getText());
b = Double.parseDouble(textField_B.getText());
x = Double.parseDouble(textField_X.getText());
d = Double.parseDouble(textField_D.getText());
} catch (Exception ex) {
Toolkit.getDefaultToolkit().beep();
JOptionPane.showMessageDialog(null, "Ошибка введенных данных!",
"Ошибка ввода", JOptionPane.ERROR_MESSAGE);
textField_A.requestFocus();
label_answer.setText("В введенных значениях допущены ошибки");
textField_A.setText("");
textField_B.setText("");
textField_X.setText("");
textField_D.setText("");
return;
}
if (x < 6) {
y = (((a + b) * (a + b)) / (x - 2));
} else {
y = ((x * (d * d * d)) + (b * b));
}
if (!(Double.isNaN(y)) && (!Double.isInfinite(y))) {
label_answer.setText("Ответ: " + String.format("%.2f", y));
} else {
label_answer.setText("Нет ответа");
}
}

@FXML
private void buttonClearAction() {
label_answer.setText("Ответ: ");
textField_A.setText("");
textField_B.setText("");
textField_X.setText("");
textField_D.setText("");
}

@FXML
private void buttonExitAction() {
System.exit(0);
}

}
```

sample.fxml
```



















```