-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCellPanel.java
More file actions
92 lines (81 loc) · 2.22 KB
/
CellPanel.java
File metadata and controls
92 lines (81 loc) · 2.22 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
/* * * * * * * * * * *\
* CellPanel.java
* Description: Used by CalendarPanel.java, represents each individual "day" cell on the calendar. When mouse hovers over a cell
* the background color changes to gray. If the cells value is the same as the current date, the cell is highlited
* blue. Also has another constructor to create a blank cell. If a cell is clicked and not blank, the value is
* sent to CalendarPanel.java where it gets handled.
*
* Date: 5/7/16
* @author Brandon Ballard
\* * * * * * * * * * */
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.awt.event.*;
import java.text.*;
class CellPanel extends JPanel implements MouseListener
{
JLabel day;
int dayNum, currYear;
CalendarPanel cp;
boolean active = false, today = false;
//Constructor for creating a cell with value
public CellPanel(int day, CalendarPanel cp, String currMonth, int currYear)
{
this.currYear = currYear;
this.cp = cp;
this.day = new JLabel(Integer.toString(day));
this.day.setForeground(Color.DARK_GRAY);
active = true;
dayNum = day;
setBackground(Color.WHITE);
addMouseListener(this);
add(this.day);
//Check to see if cell value matches current date, if so, make it blue
if(Integer.parseInt(new SimpleDateFormat("d").format(new Date())) == day && new SimpleDateFormat("MMMMM").format(new Date()).equals(currMonth)&& Integer.parseInt(new SimpleDateFormat("yyyy").format(new Date())) == currYear)
{
today = true;
setBackground(Color.BLUE);
this.day.setForeground(Color.WHITE);
}
}
//Constructor for creating a blank cell
public CellPanel(String day)
{
this.day = new JLabel("");
setBackground(Color.WHITE);
}
//Toggle cell colors
public void mouseEntered(MouseEvent me)
{
setBackground(Color.GRAY);
day.setForeground(Color.WHITE);
}
//Toggle cell colors
public void mouseExited(MouseEvent me)
{
if(!today)
{
setBackground(Color.WHITE);
day.setForeground(Color.DARK_GRAY);
}
else
{
setBackground(Color.BLUE);
day.setForeground(Color.WHITE);
}
}
public void mouseClicked(MouseEvent me)
{
if(active)
{
cp.selectedDay = dayNum;
}
}
public void mouseReleased(MouseEvent me)
{
}
public void mousePressed(MouseEvent me)
{
}
}