-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoids.java
151 lines (129 loc) · 4.47 KB
/
Poids.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package convertisseurlongueurpoidsjavafx;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Tab;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
public class Poids {
Tab tab;
public Poids(Tab tab) {
this.tab=tab;
}
public void open() {
GridPane gp = new GridPane();
gp.setAlignment(Pos.CENTER);
gp.setPadding(new Insets(15));
gp.setHgap(50);
gp.setVgap(50);
Label label_1 = new Label("VALEUR :");
TextField textField_1 = new TextField();
textField_1.setPromptText("SVP entrer la valeure ! ");
gp.add(label_1,0,0);
gp.add(textField_1, 1,0);
RadioButton rb1 = new RadioButton("mg");
RadioButton rb2 = new RadioButton("g");
RadioButton rb3 = new RadioButton("kg");
gp.add(rb1,2, 0);
gp.add(rb2, 3, 0);
gp.add(rb3,4, 0);
ToggleGroup group1 = new ToggleGroup();
rb1.setToggleGroup(group1);
rb2.setToggleGroup(group1);
rb3.setToggleGroup(group1);
rb1.setSelected(true);
Label label_2 = new Label("VALEUR :");
TextField textField_2 = new TextField();
textField_2.setDisable(true);
textField_2.setStyle("-fx-border-color: black;" +
"-fx-background-color: white;"
);
gp.add(label_2,0,1);
gp.add(textField_2, 1, 1);
RadioButton rb4 = new RadioButton("mg");
RadioButton rb5 = new RadioButton("g");
RadioButton rb6 = new RadioButton("kg");
gp.add(rb4,2, 1);
gp.add(rb5, 3, 1);
gp.add(rb6,4,1);
ToggleGroup group2 = new ToggleGroup();
rb4.setToggleGroup(group2);
rb5.setToggleGroup(group2);
rb6.setToggleGroup(group2);
rb4.setSelected(true);
Button convertir = new Button("CONVERTIR");
Label errorLabel = new Label();
gp.add(convertir, 0, 2);
gp.add(errorLabel, 1, 2);
errorLabel.setTextFill(Color.RED);
convertir.setOnAction(e ->
{
if((!textField_1.getText().matches("\\d*?\\.?\\d+"))){
textField_1.setText("");
errorLabel.setText("error ! enter number");
}
else if (textField_1.getText()==null) {
errorLabel.setText("SVP entrer la valeur !");
textField_2.setText("");
}
else if (rb1.isSelected() && rb4.isSelected() || rb2.isSelected() && rb5.isSelected() || rb3.isSelected() && rb6.isSelected() )
{
textField_2.setText(textField_1.getText());
errorLabel.setText("");
}
else if(rb3.isSelected() && rb4.isSelected()) {
Double num = Double.parseDouble(textField_1.getText());
Double result = num*1000000;
textField_2.setText(""+result);
errorLabel.setText("");
}
else if(rb3.isSelected() && rb5.isSelected()) {
Double num = Double.parseDouble(textField_1.getText());
Double result = num*1000;
textField_2.setText(""+result);
errorLabel.setText("");
}
else if(rb2.isSelected() && rb6.isSelected()) {
Double num = Double.parseDouble(textField_1.getText());
Double result = num/1000;
textField_2.setText(""+result);
errorLabel.setText("");
}
else if(rb2.isSelected() && rb4.isSelected()) {
Double num = Double.parseDouble(textField_1.getText());
Double result = num*1000;
textField_2.setText(""+result);
errorLabel.setText("");
}
else if(rb1.isSelected() && rb5.isSelected()) {
Double num = Double.parseDouble(textField_1.getText());
Double result = num/1000;
textField_2.setText(""+result);
errorLabel.setText("");
}
else if(rb1.isSelected() && rb6.isSelected()) {
Double num = Double.parseDouble(textField_1.getText());
Double result = num/1000000;
textField_2.setText(String.format("%.6f", result));
errorLabel.setText("");
}
else
{
errorLabel.setText("Wrong !!");
textField_2.setText("");
}
}
);
gp.setStyle("-fx-padding: 250;" +
"-fx-text-fill: white;" +
"-fx-font-weight: bold;" +
"-fx-font-family: Arial Narrow;" +
"-fx-font-size: 20px;"
);
tab.setContent(gp);
}
}