-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivity_creation.java
More file actions
108 lines (101 loc) · 4.32 KB
/
activity_creation.java
File metadata and controls
108 lines (101 loc) · 4.32 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
107
108
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Statement;
public class activity_creation extends JFrame {
private JPanel activityCreatement;
private JButton backButton;
private JButton saveButton;
private JRadioButton massActivityRadioButton;
private JRadioButton individualActivityRadioButton;
private JTextField name;
private JTextField link;
private JTextField age;
private JTextField capacity;
private String selection;
public activity_creation(){
add(activityCreatement);
Root strt = new Root();
capacity.setEnabled(false);
capacity.setBackground(Color.gray);
age.setEnabled(false);
age.setBackground(Color.gray);
ButtonGroup group = new ButtonGroup();
group.add(massActivityRadioButton);
group.add(individualActivityRadioButton);
backButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
operation_selection oprt = new operation_selection();
oprt.setVisible(true);
setVisible(false);
}
});
saveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (selection == "indiv"){
try {
Statement stmnt = null;
String query = "insert into individualActivity(activity_name, age_requirement, internet_link) values('"+(name.getText())+"','"+(age.getText())+"','"+(link.getText())+"')";
stmnt = strt.getConnection().createStatement();
stmnt.executeUpdate(query);
JOptionPane.showMessageDialog(null,"Values inserted successfully");
name.setText("");
age.setText("");
link.setText("");
} catch (Exception a) {
JOptionPane.showMessageDialog(null, "Something went wrong","ERROR",JOptionPane.ERROR_MESSAGE);
a.printStackTrace();
return;
}
}
else if (selection == "mass") {
try {
Statement stmnt = null;
String query = "insert into massActivity(activity_name, capacity, internet_link) values('"+(name.getText())+"',"+(capacity.getText())+",'"+(link.getText())+"')";
stmnt = strt.getConnection().createStatement();
stmnt.executeUpdate(query);
JOptionPane.showMessageDialog(null,"Values inserted successfully");
name.setText("");
age.setText("");
link.setText("");
} catch (Exception a) {
JOptionPane.showMessageDialog(null, "Something went wrong","ERROR",JOptionPane.ERROR_MESSAGE);
a.printStackTrace();
return;
}
}
else{
JOptionPane.showMessageDialog(null, "Please select a activity type","ERROR",JOptionPane.ERROR_MESSAGE);
return;
}
}
});
massActivityRadioButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
capacity.setEnabled(true);
capacity.setBackground(Color.WHITE);
age.setEnabled(false);
age.setBackground(Color.gray);
selection = "mass";
}
});
individualActivityRadioButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
capacity.setEnabled(false);
capacity.setBackground(Color.gray);
age.setEnabled(true);
age.setBackground(Color.WHITE);
selection = "indiv";
}
});
setTitle("Activity Creation");
setResizable(true);
setSize(600,350);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}