forked from serenapascual/cs151-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimePromptView.java
More file actions
117 lines (95 loc) · 2.96 KB
/
TimePromptView.java
File metadata and controls
117 lines (95 loc) · 2.96 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
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
/**
*
* @author Himanshu Mehta, Serena Pascual and Cherie Sew
* Pop up new panel for current time
*
*/
public class TimePromptView {
private JPanel panel = new JPanel();
public TimePromptView() {
final JFrame frame = new JFrame();
final JButton standardButton = new JButton("STANDARD TIME");
final JButton militaryButton = new JButton("MILITARY TIME");
standardButton.setOpaque(true);
standardButton.setBorderPainted(false);
standardButton.setFocusable(false);
standardButton.setBackground(new Color(236, 151, 31));
standardButton.setForeground(Color.WHITE);
standardButton.setFont(new Font("Tahoma", Font.BOLD, 14));
/**
* Strategy Pattern
* Anonymous class for standard time
*/
standardButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final DateFormatter format = new TimeFormatter();
displayStandard(format.formatDate());
}
});
militaryButton.setOpaque(true);
militaryButton.setBorderPainted(false);
militaryButton.setFocusable(false);
militaryButton.setBackground(new Color(68, 157, 68));
militaryButton.setForeground(Color.WHITE);
militaryButton.setFont(new Font("Tahoma", Font.BOLD, 14));
/**
* Strategy Pattern
* Anonymous class for military time
*/
militaryButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final DateFormatter format = new MilitaryTimeFormatter();
displayMilitary(format.formatDate());
}
});
panel.add(standardButton);
panel.add(militaryButton);
panel.setPreferredSize(new Dimension(350, 150));
frame.add(panel);
frame.pack();
frame.setResizable(false);
frame.setVisible(true);
}
/**
* Strategy Pattern for Military Time
* @param date to display
*/
private void displayMilitary(String date)
{
JPanel newPanel = new JPanel(new BorderLayout());
JTextArea area = new JTextArea();
area.setText(date);
area.setOpaque(false);
area.setFont(new Font("Tahoma", Font.BOLD, 30));
newPanel.add(area, BorderLayout.NORTH);
panel.add(newPanel, BorderLayout.WEST);
panel.revalidate();
panel.repaint();
}
/**
* Strategy Pattern for Standard Time
* @param date to display
*/
private void displayStandard(String date)
{
JPanel newPanel = new JPanel(new BorderLayout());
JTextArea area = new JTextArea(date);
area.setOpaque(false);
area.setFont(new Font("Tahoma", Font.BOLD, 30));
newPanel.add(area, BorderLayout.NORTH);
panel.add(newPanel, BorderLayout.WEST);
panel.revalidate();
panel.repaint();
}
}