java program for calendar using applet

Solutions on MaxInterview for java program for calendar using applet by the best coders in the world

showing results for - "java program for calendar using applet"
Roxane
15 Mar 2019
1View in Browser. 
2
Stevie
18 Jun 2020
1import java.awt.*;
2
3import java.util.GregorianCalendar;
4
5import javax.swing.*;
6
7 
8
9    public class CalendarDisplayApplet extends JApplet {
10
11        // Instance Variables
12
13        GregorianCalendar calendar = new GregorianCalendar();
14
15        int arrange = 7;
16
17        int column = 7;
18
19        String[] week = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
20
21        String[] month = { "January", "Februrary", "March", "April", "May", "June", "July", "August",
22
23                "September", "October", "November", "December"};
24
25        JLabel[][] grid = new JLabel[arrange][column];
26
27        JPanel jpnlCalendar = new JPanel(new GridLayout(7, 7));
28
29        int today = calendar.get(GregorianCalendar.DAY_OF_MONTH);
30
31        int daysInMonth = calendar.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
32
33        int daysInWeek = calendar.get(GregorianCalendar.DAY_OF_WEEK);
34
35 
36
37        public void init() {
38
39            // setting grid
40
41            for (int i = 0; i < grid.length; i++) {
42
43                for (int j = 0; j < grid[0].length; j++) {
44
45                    grid[i][j] = new JLabel();
46
47                }
48
49 
50
51            }
52
53            // grid layout
54
55            Container contenu = getContentPane();
56
57            for (int i = 0; i < arrange; i++) {
58
59                for (int j = 0; j < column; j++) {
60
61                    jpnlCalendar.add(grid[i][j]);
62
63                }
64
65            }
66
67             
68
69            // adding JPanels + positions
70
71            contenu.add(jpnlCalendar);
72
73 
74
75            // draw week days
76
77            for (int i = 0; i < week.length; i++) {
78
79                grid[0][i].setText(week[i]);
80
81            }
82
83            // draw name of month
84
85            //for (int m = 0; m < month.length; m++) {
86
87                //grid[0][m].setText(month[m]); 
88
89           // }
90
91 
92
93            //conditions for the calendar
94
95            calendar.set(GregorianCalendar.DAY_OF_MONTH, 1);
96
97            int daysInWeek = calendar.get(GregorianCalendar.DAY_OF_WEEK)- 1;
98
99            System.out.print(daysInWeek);
100
101            if (daysInWeek == 0)
102
103                daysInWeek = 7;
104
105            calendar.set(GregorianCalendar.DAY_OF_MONTH, today);
106
107 
108
109            int days = 1;
110
111 
112
113            for (int k = daysInWeek; k < column; k++) {
114
115                grid[1][k].setText(days + "");
116
117                if (days == today)
118
119                    grid[1][k].setText(days + "*");
120
121                days++;
122
123            }
124
125            // draw calendar
126
127            for (int i = 2; i <= column; i++) {
128
129                for (int j = 0; j < arrange; j++) {
130
131                    if (days <= daysInMonth) {
132
133                        grid[i][j].setText(days + "");
134
135                        if (days == today)
136
137                            grid[i][j].setText(days + "*");
138
139                        days++;
140
141                    }
142
143                }
144
145            }
146
147 
148
149        }
150
151    }
152