-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArjun.java
More file actions
519 lines (438 loc) · 21.7 KB
/
Arjun.java
File metadata and controls
519 lines (438 loc) · 21.7 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
// Austin Trinh, Arjun Rao, Geethan Sundaram, Rayyan Alam
// Phoenix Hackathon 2022 Project
// 12.3.2022
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GradientPaint;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Collections;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import javax.sound.sampled.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import javax.sound.sampled.*;
import java.util.Collections;
public class Arjun extends JPanel{
// Fields:
public int titleX, titleY, gui, angle, tick, constantX, constantY, index;
public static final int WIDTH = 1000;
public static final int HEIGHT = 1000;
private JLabel name, wishName, wishList;
private JPanel menu, santaMenu, doneMenu, textMenu;
private JPanel north, south, east, west, insert;
private JPanel north2, east2, west2, south2, doneMenu2;
private JButton testButton;
private JTextField insertName, insertWish;
private ImageIcon santaTitle, santaLogo;
private Timer timer;
private ArrayList<SSPerson> people = new ArrayList<SSPerson>();
private ArrayList<String> wishlist = new ArrayList<String>();
public Star[] stars = new Star[4];
public Star2[] stars2 = new Star2[4];
public XmasTree[] trees = new XmasTree[2];
// private etc.
// Panel Object
public Arjun() {
stars[0] = new Star(800,100);
stars[1] = new Star(100, 50);
stars[2] = new Star(887,142);
stars[3] = new Star(100, 50);
stars2[0] = new Star2(154,162);
stars2[1] = new Star2(875, 50);
stars2[2] = new Star2(154,162);
stars2[3] = new Star2(875, 50);
trees[0] = new XmasTree(700, 500);
trees[1] = new XmasTree(10, 550);
// Base Panel
setLayout(new BorderLayout());
setOpaque(false);
// Instantiating Variables
gui = 0;
angle = 0;
tick = 0;
// Instantiating title
santaTitle = new ImageIcon("Title.png");
santaLogo = new ImageIcon("SecretSantaLogo.png");
// Instantiating Timer
timer = new Timer(100, new TimerListener());
timer.start();
// Menu Panel
menu = new JPanel();
menu.setLayout(new BorderLayout());
menu.setPreferredSize(new Dimension(WIDTH, HEIGHT));
menu.setOpaque(false);
add(menu);
// North Panel
north = new JPanel();
north.setLayout(new BorderLayout());
north.setPreferredSize(new Dimension(WIDTH, HEIGHT/3));
north.setOpaque(false);
menu.add(north, BorderLayout.PAGE_START);
testButton = new JButton("Let's Begin!");
testButton.setFont(new Font("Roboto", Font.BOLD, 30));
testButton.setBackground(Color.RED); // Button Background
testButton.setForeground(Color.WHITE); // Font color
testButton.addActionListener(new Test());
testButton.setPreferredSize(new Dimension(WIDTH/4, 0));
testButton.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(0,0,0,0, Color.BLACK),
BorderFactory.createMatteBorder(3,3,3,3, Color.BLACK)),
BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(2,2,2,2, Color.WHITE),
BorderFactory.createMatteBorder(6,3,6,3, new Color(136,65,62)))));
menu.add(testButton, BorderLayout.CENTER);
// Filler code
west = new JPanel();
west.setPreferredSize(new Dimension(WIDTH/4, 0));
west.setOpaque(false);
menu.add(west, BorderLayout.WEST);
east = new JPanel();
east.setPreferredSize(new Dimension(WIDTH/4, 0));
east.setOpaque(false);
menu.add(east, BorderLayout.EAST);
south = new JPanel();
south.setPreferredSize(new Dimension(WIDTH, HEIGHT/4));
south.setOpaque(false);
menu.add(south, BorderLayout.SOUTH);
// Santa Menu
santaMenu = new JPanel();
santaMenu.setLayout(new BorderLayout());
santaMenu.setOpaque(false);
// Prompt
insert = new JPanel();
insert.setPreferredSize(new Dimension(WIDTH/4, 0));
insert.setLayout(new BorderLayout());
insert.setBackground(Color.RED);
insert.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(0,0,0,0, Color.BLACK),
BorderFactory.createMatteBorder(3,3,3,3, Color.BLACK)),
BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(2,2,2,2, Color.WHITE),
BorderFactory.createMatteBorder(6,3,6,3, new Color(136,65,62)))));
santaMenu.add(insert, BorderLayout.CENTER);
// Insert Fillers
JPanel insertFiller = new JPanel();
insertFiller.setOpaque(false);
insertFiller.setPreferredSize(new Dimension(WIDTH/32, 0));
insert.add(insertFiller, BorderLayout.WEST);
JPanel insertFiller2 = new JPanel();
insertFiller2.setOpaque(false);
insertFiller2.setPreferredSize(new Dimension(WIDTH/32, 0));
insert.add(insertFiller2, BorderLayout.EAST);
JPanel insertFiller3 = new JPanel();
insertFiller3.setOpaque(false);
insertFiller3.setPreferredSize(new Dimension(0, HEIGHT/32));
insert.add(insertFiller3, BorderLayout.NORTH);
JPanel insertFiller4 = new JPanel();
insertFiller4.setOpaque(false);
insertFiller4.setPreferredSize(new Dimension(0, HEIGHT/32));
insert.add(insertFiller4, BorderLayout.SOUTH);
// Panel for Insert Name and Name TextField
JPanel insert2 = new JPanel(new BorderLayout());
insert2.setOpaque(false);
insert.add(insert2, BorderLayout.CENTER);
// Insert JLabel
name = new JLabel("Insert Name");
name.setFont(new Font("Roboto", Font.BOLD, 30));
//name.setHorizontalAlignment(JLabel.CENTER);
name.setForeground(Color.WHITE);
insert2.add(name, BorderLayout.NORTH);
// Insert TextField
insertName = new JTextField();
insertName.setFont(new Font("Roboto", Font.PLAIN, 20));
insertName.setPreferredSize(new Dimension(0, HEIGHT/32));
insert2.add(insertName, BorderLayout.CENTER);
// JPanel insert2filler = new JPanel();
//insert2filler.setOpaque(false);
//insert2filler.setPreferredSize(new Dimension(0, HEIGHT/32));
// insert2.add(insert2filler, BorderLayout.SOUTH);
JPanel wish = new JPanel();
wish.setLayout(new BorderLayout());
wish.setOpaque(false);
wish.setPreferredSize(new Dimension(0, 220));
insert2.add(wish, BorderLayout.SOUTH);
JPanel fill1 = new JPanel();
fill1.setPreferredSize(new Dimension(0, HEIGHT/32));
fill1.setOpaque(false);
wish.add(fill1, BorderLayout.NORTH);
JPanel wish2 = new JPanel(new GridLayout(2,0));
wish2.setOpaque(false);
wish.add(wish2, BorderLayout.CENTER);
JLabel wishLabel = new JLabel("Insert Wish Item");
wishLabel.setFont(new Font("Roboto", Font.BOLD, 30));
wishLabel.setVerticalAlignment(JLabel.TOP);
wishLabel.setForeground(Color.WHITE);
wish2.add(wishLabel);
insertWish = new JTextField();
insertWish.setPreferredSize(new Dimension(0, HEIGHT/32));
insertWish.setFont(new Font("Roboto", Font.PLAIN, 20));
wish2.add(insertWish);
JPanel buttons = new JPanel(new BorderLayout());
buttons.setOpaque(false);
buttons.setPreferredSize(new Dimension(0, HEIGHT/9));
wish.add(buttons, BorderLayout.SOUTH);
JPanel fill2 = new JPanel();
fill2.setPreferredSize(new Dimension(0, HEIGHT/32));
fill2.setOpaque(false);
buttons.add(fill2, BorderLayout.NORTH);
JPanel buttons2 = new JPanel(new GridLayout(0, 3, HEIGHT/32, 0));
buttons2.setOpaque(false);
buttons.add(buttons2, BorderLayout.CENTER);
JButton done = new JButton("Done");
done.addActionListener(new doneListener());
done.setFont(new Font("Roboto", Font.BOLD, WIDTH/64));
done.setBackground(Color.ORANGE);
done.setForeground(Color.WHITE);
done.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(0,0,0,0, Color.BLACK),
BorderFactory.createMatteBorder(3,3,3,3, Color.BLACK)),
BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(2,2,2,2, Color.WHITE),
BorderFactory.createMatteBorder(6,3,6,3, Color.ORANGE.darker()))));
buttons2.add(done);
JButton addWish = new JButton("+ Wish");
addWish.addActionListener(new addWishListener());
addWish.setFont(new Font("Roboto", Font.BOLD, WIDTH/64));
addWish.setBackground(Color.ORANGE);
addWish.setForeground(Color.WHITE);
addWish.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(0,0,0,0, Color.BLACK),
BorderFactory.createMatteBorder(3,3,3,3, Color.BLACK)),
BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(2,2,2,2, Color.WHITE),
BorderFactory.createMatteBorder(6,3,6,3, Color.ORANGE.darker()))));
buttons2.add(addWish);
JButton addPerson = new JButton("+ Person");
addPerson.addActionListener(new addPersonListener());
addPerson.setFont(new Font("Roboto", Font.BOLD, WIDTH/64));
addPerson.setBackground(Color.ORANGE);
addPerson.setForeground(Color.WHITE);
addPerson.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(0,0,0,0, Color.BLACK),
BorderFactory.createMatteBorder(3,3,3,3, Color.BLACK)),
BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(2,2,2,2, Color.WHITE),
BorderFactory.createMatteBorder(6,3,6,3, Color.ORANGE.darker()))));
buttons2.add(addPerson);
// Fillers
north2 = new JPanel();
north2.setPreferredSize(new Dimension(WIDTH, HEIGHT/3));
north2.setOpaque(false);
santaMenu.add(north2, BorderLayout.NORTH);
east2 = new JPanel();
east2.setPreferredSize(new Dimension(WIDTH/4, 0));
east2.setOpaque(false);
santaMenu.add(east2, BorderLayout.EAST);
west2 = new JPanel();
west2.setPreferredSize(new Dimension(WIDTH/4, 0));
west2.setOpaque(false);
santaMenu.add(west2, BorderLayout.WEST);
south2 = new JPanel();
south2.setPreferredSize(new Dimension(WIDTH, HEIGHT/4));
south2.setOpaque(false);
santaMenu.add(south2, BorderLayout.SOUTH);
doneMenu = new JPanel(new BorderLayout());
doneMenu.setBackground(Color.RED);
doneMenu.setPreferredSize(new Dimension(WIDTH/4, 0));
doneMenu.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(0,0,0,0, Color.BLACK),
BorderFactory.createMatteBorder(3,3,3,3, Color.BLACK)),
BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder(2,2,2,2, Color.WHITE),
BorderFactory.createMatteBorder(6,3,6,3, new Color(136,65,62)))));
JPanel fill3 = new JPanel();
fill3.setOpaque(false);
fill3.setPreferredSize(new Dimension(0, HEIGHT/32));
doneMenu.add(fill3, BorderLayout.NORTH);
JPanel fill4 = new JPanel();
fill4.setOpaque(false);
fill4.setPreferredSize(new Dimension(HEIGHT/32, 0));
doneMenu.add(fill4, BorderLayout.WEST);
JPanel fill5 = new JPanel();
fill5.setOpaque(false);
fill5.setPreferredSize(new Dimension(HEIGHT/32, 0));
doneMenu.add(fill5, BorderLayout.EAST);
JPanel fill6 = new JPanel();
fill6.setOpaque(false);
fill6.setPreferredSize(new Dimension(0, WIDTH/32));
doneMenu.add(fill6, BorderLayout.SOUTH);
doneMenu2 = new JPanel(new GridLayout(4,0));
doneMenu2.setOpaque(false);
doneMenu.add(doneMenu2, BorderLayout.CENTER);
constantX = WIDTH/2 - (int)((675*0.8)/2);
// titleY = north.getHeight()/2 + (int)((288*0.8)/2);
constantY = (WIDTH/3)/2 - (int)((288*0.8)/2);
}
public void paintComponent(Graphics g) {
Graphics2D g2D = (Graphics2D) g;
GradientPaint blueToOrange = new GradientPaint(0, 0, new Color(60, 0, 16), 0, HEIGHT, new Color(255,0,35));
g2D.setPaint(blueToOrange);
g2D.fillRect(0, 0, WIDTH, HEIGHT);
GradientPaint blue = new GradientPaint(0, 0, new Color(60, 0, 16), 0, HEIGHT, new Color(255,0,35));
GradientPaint snow = new GradientPaint(0,0, new Color(255,255,255), 0, HEIGHT, new Color(247,247,247));
GradientPaint packedSnow = new GradientPaint(0,0, new Color(192,192,192), 0, HEIGHT, new Color(247,247,247));
g2D.setPaint(blue);
g2D.fillRect(0, 0, WIDTH, HEIGHT);
g2D.setPaint(snow);
g2D.fillOval(-100,800,WIDTH+200,350);
g2D.setPaint(packedSnow);
g2D.fillOval(-100,850,WIDTH+200,350);
// Secret Santa Logo
drawTitle(g);
//drawLogo(g);
if(gui == 1) {
//drawTitle(g);
}
// 675, 288
}
public void drawTitle(Graphics g) {
g.drawImage(santaTitle.getImage(), titleX, titleY, (int)(675*0.8), (int)(288*0.8), null);
drawStar(g);
drawStar2(g);
drawTree(g);
}
public void drawLogo(Graphics g) {
g.drawImage(santaLogo.getImage(), 500, 300, 100, 100, null);
}
public void drawStar(Graphics g) {
for(Star star : stars)
star.drawStar(g);
}
public void drawStar2(Graphics g) {
for(Star2 star : stars2)
star.drawStar2(g);
}
public void drawTree(Graphics g) {
for(XmasTree tree : trees)
tree.drawTree(g);
}
// Button Actions
private class Test implements ActionListener {
public void actionPerformed(ActionEvent e) {
remove(menu);
add(santaMenu);
gui = 1;
repaint();
revalidate();
}
}
private class doneListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
santaMenu.remove(insert);
santaMenu.add(doneMenu);
ArrayList<Integer> randIndex = new ArrayList<Integer>();
for(int j = 0; j < people.size(); j++){
randIndex.add(j);
}
Collections.shuffle(randIndex);
for(int j = 0; j < randIndex.size(); j++){
while(j == randIndex.get(j)){
Collections.shuffle(randIndex);
j = 0;
}
}
for(int j = 0; j < people.size(); j++){
people.get(j).assignPerson(people.get(randIndex.get(j)));
}
wishName = new JLabel(people.get(0).getName()+"! You are "+people.get(0).getPerson()+"'s Secret Santa!", SwingConstants.CENTER);
wishName.setForeground(Color.WHITE);
wishName.setFont(new Font("Roboto", Font.BOLD, 20));
doneMenu2.add(wishName);
JPanel fillPanel = new JPanel();
fillPanel.setOpaque(false);
fillPanel.setPreferredSize(new Dimension(0, HEIGHT/32));
doneMenu2.add(fillPanel);
wishList = new JLabel("Here's is that person's wishlist:", SwingConstants.CENTER);
wishList.setForeground(Color.WHITE);
wishList.setFont(new Font("Roboto", Font.BOLD, 20));
doneMenu2.add(wishList);
//int num = people.get(0).getPerson2().getWishlist().size();
//System.out.println(num);
JPanel wishPanel2 = new JPanel(new GridLayout(2,0));
wishPanel2.setOpaque(false);
doneMenu2.add(wishPanel2);
JLabel l10 = new JLabel("1) Pumpkin Pie");
l10.setFont(new Font("Roboto", Font.BOLD, 20));
l10.setForeground(Color.WHITE);
wishPanel2.add(l10);
JLabel l11 = new JLabel("2) Beanie");
l11.setFont(new Font("Roboto", Font.BOLD, 20));
l11.setForeground(Color.WHITE);
wishPanel2.add(l11);
gui = 2;
repaint();
revalidate();
}
}
private class addWishListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if(insertName.getText().length() > 0) {
wishlist.add(insertWish.getText());
insertWish.setText("");
}
}
}
private class addPersonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if(insertName.getText().length() > 0) {
SSPerson person = new SSPerson(insertName.getText(), wishlist);
people.add(person);
insertName.setText("");
insertWish.setText("");
}
}
}
private class TimerListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
repaint();
tick++;
angle+=2;
// if(tick %10 == 0) {
// angle++;
// }
titleX = constantX;
titleY = (int)(constantY + 20*Math.sin(Math.toRadians(angle)));
}
}
// Panel Driver
public static void main(String[] args) {
JFrame frame = new JFrame("Arjun: Secret Santa");
frame.setSize(WIDTH, HEIGHT);
frame.setLocation(0,0);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new Arjun());
frame.setVisible(true);
}
}
/*
* public static void gradientBackground(Graphics g) {
// convert g into a graphics2d object
Graphics2D g2D = (Graphics2D) g;
//create gradient paint object
//experiment with the parameters to see how changing them affects the gradient
GradientPaint blueToOrange = new GradientPaint(0, 0, new Color(117, 0, 16), 0, HEIGHT, new Color(255,0,35));
//draw a rectangle filling the frame (background)
//that uses the gradient we just created
g2D.setPaint(blueToOrange);
g2D.fillRect(0, 0, WIDTH, HEIGHT);
}
*/