Repository navigation
Expand file tree
/
Copy pathAddController.java
More file actions
106 lines (87 loc) · 2.46 KB
/
Copy pathAddController.java
File metadata and controls
106 lines (87 loc) · 2.46 KB
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
package application;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
public class AddController {
//DB here
TaskManager tm = new TaskManager("tm");
@FXML
private TextField habit;
@FXML
private CheckBox sun;
@FXML
private CheckBox mon;
@FXML
private CheckBox tue;
@FXML
private CheckBox wed;
@FXML
private CheckBox thu;
@FXML
private CheckBox fri;
@FXML
private CheckBox sat;
@FXML
void sendToAdd(ActionEvent event) {
String getHabit = habit.getText();
boolean [] week = new boolean [7];
if(sun.isSelected()) {
week[0] = true;
}
if(mon.isSelected()) {
week[1] = true;
}
if(tue.isSelected()) {
week[2] = true;
}
if(wed.isSelected()) {
week[3] = true;
}
if(thu.isSelected()) {
week[4] = true;
}
if(fri.isSelected()) {
week[5] = true;
}
if(sat.isSelected()){
week[6] = true;
}
//if no days are selected
if(!sun.isSelected() && !mon.isSelected() && !tue.isSelected() && !wed.isSelected()
&& !thu.isSelected() && !fri.isSelected() && !sat.isSelected()) {
infoBox1("Please choose at least one day", "Alert");
}
//if at least one day is selected
if(sun.isSelected() || mon.isSelected() || tue.isSelected() || wed.isSelected()
|| thu.isSelected() || fri.isSelected() || sat.isSelected()) {
//***push habit to DB
tm.addFromGUIToDB(getHabit, week);
clear();
}
}
public static void infoBox1(String infoMessage, String titleBar)
{
infoBox2(infoMessage, titleBar, null);
}
public static void infoBox2(String infoMessage, String titleBar, String headerMessage)
{
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle(titleBar);
alert.setHeaderText(headerMessage);
alert.setContentText(infoMessage);
alert.showAndWait();
}
private void clear() {
habit.clear();
sun.setSelected(false);
mon.setSelected(false);
tue.setSelected(false);
wed.setSelected(false);
thu.setSelected(false);
fri.setSelected(false);
sat.setSelected(false);
}
}