-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddLikes.java
More file actions
180 lines (146 loc) · 5.23 KB
/
AddLikes.java
File metadata and controls
180 lines (146 loc) · 5.23 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package speedmatch;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class AddLikes extends JFrame {
Dating event;
public AddLikes(Dating evt) {
event = evt;
initGUI();
}
public void initGUI() {
JPanel panel = new JPanel(new GridBagLayout());
panel.setOpaque(false);
this.getContentPane().add(panel);
this.getContentPane().setBackground(new Color(255, 229, 204));
setExtendedState(JFrame.MAXIMIZED_BOTH);
// Title
JLabel title = new JLabel("Add new likes");
title.setForeground(new Color(250, 92, 92));
title.setFont(new Font("Arial", Font.BOLD, 30));
// Seperator
JSeparator sep = new JSeparator();
sep.setPreferredSize(new Dimension(500, 20));
// Labels
JLabel id = new JLabel("Your ID: ");
id.setForeground(new Color(250, 92, 92));
id.setFont(new Font("Arial", Font.PLAIN, 15));
JLabel[] likeArray = new JLabel[event.getMaxMatch()];
// Dynamically generate Labels as specified by maximum number of likes
for (int i = 0; i < event.getMaxMatch(); i++) {
int nbr = i + 1;
likeArray[i] = new JLabel("Like " + nbr + " (ID): ");
likeArray[i].setForeground(new Color(250, 92, 92));
likeArray[i].setFont(new Font("Arial", Font.PLAIN, 15));
}
// Text Fields
JTextField idbox = new JTextField();
JTextField[] textArray = new JTextField[event.getMaxMatch()];
// Dynamically generate Text fields
for (int i = 0; i < event.getMaxMatch(); i++) {
if (i == 0) {
textArray[i] = new JTextField();
} else if (i == 1) {
textArray[i] = new JTextField();
} else if (i == 2) {
textArray[i] = new JTextField();
} else {
int nbr = i + 1;
textArray[i] = new JTextField();
}
textArray[i].setColumns(10);
}
// Buttons
JPanel actionPanel = new JPanel();
actionPanel.setOpaque(false);
JButton disc = new JButton("Discard");
actionPanel.add(disc);
JButton addLike = new JButton("Add");
actionPanel.add(addLike);
// Action Listener Discard-Button
disc.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
// Action Listener Add-ButtonF>
addLike.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
int key = Integer.parseInt(idbox.getText());
int[] likearr = new int[textArray.length];
for (int i = 0; i < textArray.length; i++) {
likearr[i] = Integer.parseInt(textArray[i].getText());
}
event.addLikes(key, likearr);
dispose();
} catch (Exception e1) {
JOptionPane.showMessageDialog(AddLikes.this, "ERROR: " + e1.getMessage(), "ERROR",
JOptionPane.ERROR_MESSAGE);
}
}
});
// Adding
/*
* GridBagConstraints gbc = new GridBagConstraints(); gbc.fill =
* GridBagConstraints.HORIZONTAL; // gbc.gridwidth =
* GridBagConstraints.RELATIVE;
*
* int i = 1;
*
* gbc.gridx = 0; gbc.gridy = 0; // gbc.weighty = 1; gbc.ipady = 20; gbc.anchor
* = GridBagConstraints.PAGE_START; panel.add(title, gbc);
*
* /* gbc.gridx = 0; gbc.gridy = 1; panel.add(sep, gbc);
*
*
* gbc.gridx = 0; gbc.gridy = i; panel.add(id, gbc);
*
* gbc.gridx = 2; gbc.gridy = i; panel.add(idbox, gbc);
*
* i++;
*
* for(int y=0; y<event.getMaxMatch();y++) { gbc.gridx = 0; gbc.gridy = i;
* panel.add(likeArray[y], gbc);
*
* gbc.gridx = 2; gbc.gridy = i; panel.add(textArray[y], gbc);
*
* i++; }
*
* gbc.gridx = 0; gbc.gridy = i; // gbc.weighty = 1; gbc.anchor =
* GridBagConstraints.SOUTHEAST; panel.add(actionPanel, gbc);
*
* this.pack();
*
* this.setVisible(true);
*/
panel.add(title, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0, GridBagConstraints.PAGE_START,
GridBagConstraints.CENTER, new Insets(20, 0, 10, 0), 0, 0));
panel.add(sep, new GridBagConstraints(1, 1, GridBagConstraints.REMAINDER, 1, 0.0, 0.0,
GridBagConstraints.PAGE_START, GridBagConstraints.BOTH, new Insets(0, 0, 20, 0), 0, 0));
panel.add(id, new GridBagConstraints(0, 2, GridBagConstraints.REMAINDER, 1, 0.0, 0.0,
GridBagConstraints.PAGE_START, GridBagConstraints.BOTH, new Insets(20, 0, 0, 0), 0, 0));
panel.add(idbox, new GridBagConstraints(0, 3, GridBagConstraints.REMAINDER, 1, 0.0, 0.0,
GridBagConstraints.PAGE_START, GridBagConstraints.BOTH, new Insets(0, 0, 20, 0), 0, 0));
int i = 4;
for (int y = 0; y < event.getMaxMatch(); y++) {
panel.add(likeArray[y], new GridBagConstraints(0, i++, GridBagConstraints.REMAINDER, 1, 0.0, 0.0,
GridBagConstraints.PAGE_START, GridBagConstraints.BOTH, new Insets(20, 0, 0, 0), 0, 0));
panel.add(textArray[y], new GridBagConstraints(0, i++, GridBagConstraints.REMAINDER, 1, 0.0, 0.0,
GridBagConstraints.PAGE_START, GridBagConstraints.BOTH, new Insets(0, 0, 20, 0), 0, 0));
}
panel.add(actionPanel, new GridBagConstraints(0, i + 1, GridBagConstraints.REMAINDER, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(50, 0, 100, 0), 0, 0));
this.pack();
this.setVisible(true);
}
public void initializeLikes() {
// AddLikes frame = new AddLikes();
this.pack();
this.setVisible(true);
this.setTitle("SpeedDating - MatchFinder");
this.setSize(800, 700);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}