From 3015bbe1c0b21449c29b32bf0bf065b61cbc733e Mon Sep 17 00:00:00 2001 From: Karan Patel <96780293+karanop001018@users.noreply.github.com> Date: Sat, 21 Oct 2023 18:21:17 +0530 Subject: [PATCH] Add files via upload --- calender/Calendar$1.class | Bin 0 -> 405 bytes calender/Calendar$btnNext_Action.class | Bin 0 -> 589 bytes calender/Calendar$btnPrev_Action.class | Bin 0 -> 588 bytes calender/Calendar$cmbYear_Action.class | Bin 0 -> 815 bytes calender/Calendar$tblCalendarRenderer.class | Bin 0 -> 1126 bytes calender/Calendar.class | Bin 0 -> 5634 bytes calender/Calendar.java | 217 ++++++++++++++++++++ 7 files changed, 217 insertions(+) create mode 100644 calender/Calendar$1.class create mode 100644 calender/Calendar$btnNext_Action.class create mode 100644 calender/Calendar$btnPrev_Action.class create mode 100644 calender/Calendar$cmbYear_Action.class create mode 100644 calender/Calendar$tblCalendarRenderer.class create mode 100644 calender/Calendar.class create mode 100644 calender/Calendar.java diff --git a/calender/Calendar$1.class b/calender/Calendar$1.class new file mode 100644 index 0000000000000000000000000000000000000000..696b0b790d8f129f85e5206095e493848fd4a5c6 GIT binary patch literal 405 zcmYjNO-lnY5Pj3#c5B^!_*Fp=1UliuWtZn*sh@jFMuDSj0$1@S-gn1$i6D`80BKBWppJUM4|Ir zcNwOM)P%}~GAh3$c%AMfK$TF7g_b4}*}*Bnk6A`&4wR9jVm_7G!c1r=8%wQwiCVNK zlso-?_m1u3w8&=iT50yxm%UEhFx;nSW;(Sz(NN}3X%b+KP+f{bY+#e$oC{?L?auwc zxgst21LHhn*Lios`jNExO=@#O*f&OIu@=@!i#-Iq0(Ttp5=I|5r!2wUn u=*qwm<0?W%C*5K8m`mO}TeAHb94K$g3w6Kn?MW%%|bB*-@GoL@A6HV^` literal 0 HcmV?d00001 diff --git a/calender/Calendar$btnNext_Action.class b/calender/Calendar$btnNext_Action.class new file mode 100644 index 0000000000000000000000000000000000000000..fbdde6cfd752c2492a5bb5f9b069c3cb9bd2828e GIT binary patch literal 589 zcmZuu!A=`N41G=l8#WsVDQ$oPp%sUuhvp8bQWX^uDWsJ^k$R$&je&(^7R^p5pVM2< zzyZXer>dl{6GC&b82or{P3@3X}G$WNpquTcHl2Cd?mpWFr_}FfL3~dx^4<*9JYr9X4C4({qR#l6+ya6PrGF3FS)jS+Y-#c%|AVr`{1BbsE4@}5wkt57M%6#uwWF{?6?0THY=z@k8G4-BG5>5!?|NjGvn3CxeUdbv_ za%2PYnig+fZgR-GbI^%6gc-3e4Ez>5i`QaZ>b8`+;_4~9Lhc8O=`(nz$Y;KtA^#IO zft@RmLoZNpbg3cTtPlc!WFLPK;2%o3LK)Yn;0ALN$skqokQOzrVnJf=&Wdipm-bWQ Hzd`m6fs21$ literal 0 HcmV?d00001 diff --git a/calender/Calendar$btnPrev_Action.class b/calender/Calendar$btnPrev_Action.class new file mode 100644 index 0000000000000000000000000000000000000000..e06eb3d833748f4f7121479ec39d28524f6f75a8 GIT binary patch literal 588 zcmZuuT}xX*5IvJbZ*p^^(fCzA+aj3sp?TLLNU#`)R!{=ID4UzHUX6QY?wE-(KQ++$^Y z!AAm&qC^-rd}ug1dZQUA*Xxz0hjGH>E4tXSdfRaCU@f#!tUXK;=K4a_xvg?fx>o;% z8c||dv&hNR;xA@Efxd$sjf1AuVED#XJ`JcUEKrzH}dxMSeo| EFZ20+{Qv*} literal 0 HcmV?d00001 diff --git a/calender/Calendar$cmbYear_Action.class b/calender/Calendar$cmbYear_Action.class new file mode 100644 index 0000000000000000000000000000000000000000..5915b66c1401e97391c7288bba54f5eae504e142 GIT binary patch literal 815 zcmZuvTTc^F5dKaJY`bi^$W74-O4VIN)*C*EG0{finifr}O?)z^+o3GByJYti_*-Iv z#0MXF@X2_I|He3HTLKavc4p4Z?Du^$=Y0M1`3r!Dcwi!ftbqXwgBTJR+mbudZOgFb zzHDrfuLOo31!15b3uJAlo<|OO1Ez&xSOU4SY*W~jv4G)s8gEHQGZhW8=O()W!@MX* zoksLD+FLa-f>8rw7RGT-VCuhJ0;4TbHEJ_AH9bWgfl1p*Ay4aKvxjGqkYg^F6lqI26aPKb{z%s$1|M{qnn`DF`pm=_rKyKzjR z>dhxnkOgDcL+(*`V!tPThdRJ3G#n`fGgm#8*KS z8n`J?O!dlL<M9zQUFpP0ojzN+82&Dku(0-HN&^IhCa QeGd28n@no+{jDJP7shD5bN~PV literal 0 HcmV?d00001 diff --git a/calender/Calendar$tblCalendarRenderer.class b/calender/Calendar$tblCalendarRenderer.class new file mode 100644 index 0000000000000000000000000000000000000000..fc52266e431eb2b2b218d1ddca56b4a5c2ca270b GIT binary patch literal 1126 zcmZuwT~8B16g>l_+m_*@LP3!#3TnGlR{X$^A}U3+1~3t$fwyfLOL5sH)2(RYi*Lq% z;9CsSajyCui z^fmK=`OqkA=Ixx}ni)$NGvc0EwA|ZjkrI}5OV}$y3d!J~%-eZ)ilH?YzoUo(96^K_ zqB-#|KIN=$IJU4|hRdf7*pIy$_HhhgKSQ@Cp-D1Bz;zZ~N%k@H#%kg{KsA~SA&LVU4ss0P5JPyE zA#J-Nr+f`;n6e;f$q=b&Xl96~gBZq$h9ewDag6ZwyD(@{nAVK>h=F;iIEStvJX@5K zyq|Y$cU7e)IF750ph{>&4UQ8k+FpY%2~#TcNsd$ANeZok%Gom<6F5s0$~Q++Q!pI( zyRsQCY*cs2z97};Jg2@(GPGqZGMhYXE-=-R917zi$CN6Ws>!S)MZG4zl(Qljy5{n> zSSYS%g!FocfQv4%&6^vwb!gEk%B+~pTLkZ@8#JceCc_p)!M*Mj$Y7qfZ6Q;ZSty7C z)%-u5L4^uabE}^k={o_#C7MO)%~V9+2Kzu0>TDX-Ht>Q*`WR?b(4Wxg0iNljiD<+Z zX^Z%`q1}!6pCc6Ucl%2i(7&R6DU6*ke$js$9TjwMp?^0_J3G~I;yWf174&_^U>S!? zh?fy7W3+^!GRDdnFE!E>RU=Jj6`a<~I9I`>{+`sdczShG3A{unwy3LLVH~e<6>pHn tTdd+89;1vW_=ugZLPEHf4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ChIOnkNStN&_h2k&HU(4_uI*g84`cMdu`4R;pfGdMAaB0DE$F*$?E9Hz1|i_s z5AebaKD$0<>5J<*$^I9n@!||#n#LDq@TH{lS$s7cO@BR;ZApJKlZ~bSD3fhX|8XYk zr2iz7ji>)ClTEg!{~|LI-PVUZM1laT|+;?Gi_yq_IP;;A?#i2IL0pW^~;nN0^g}e6+t6x6Au5 zEFa>_{As4NkMf2691h3}I4GaTsC)^BZ!S1|6jO9klb;!QWC` zkXIZ8jvSWrSo|tCK2IgJnfxEdf=CNvK^ql%S5k$r*-F^7%TnT|T{;Pzc3Dp3v`ZJE z(=JyU?6k{OBpkb%goD?Rw6)8%B#CxeOR}I{)@Mct_?AHEf`<)R_5>C$HyB9dp8-K} zkeIoCS#rUXwc-5Hr_AtSGfeloZrP?l-tn^2 zv>H$^Cix{(%*}APWM!4dI%`GiPxa%2g znUn3=j@FKrqp^I_@n&U5AUiiZ^COd+<6OO?^_=YKa5}g~xC8y~MCb~)&&j^*tlSaE zohA}n$l@3^4?Ktr-j2KR5L~QTWX+CB@!`@4H6yM}?_GQxV zvj2UY#gFhooX2A!Q^lrw<0R{+H)R}`$$dwau#Rs2qAq$j&fujM~;x1e~++)beU1k SkdBd_CCwpD-j$L^{Qm)guim8q literal 0 HcmV?d00001 diff --git a/calender/Calendar.java b/calender/Calendar.java new file mode 100644 index 00000000..ce9e0d59 --- /dev/null +++ b/calender/Calendar.java @@ -0,0 +1,217 @@ +import javax.swing.*; +import javax.swing.event.*; +import javax.swing.table.*; +import java.awt.*; +import java.awt.event.*; +import java.util.*; + +public class Calendar{ + static JLabel lblMonth, lblYear; + static JButton btnPrev, btnNext; + static JTable tblCalendar; + static JComboBox cmbYear; + static JFrame frmMain; + static Container pane; + static DefaultTableModel mtblCalendar; // Table model + static JScrollPane stblCalendar; // The scrollpane + static JPanel pnlCalendar; + static int realYear, realMonth, realDay, currentYear, currentMonth; + + public static void main(String args[]) { + // Look and feel + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (ClassNotFoundException e) { + } catch (InstantiationException e) { + } catch (IllegalAccessException e) { + } catch (UnsupportedLookAndFeelException e) { + } + + // Prepare frame + frmMain = new JFrame("Gestionnaire de clients"); // Create frame + frmMain.setSize(330, 375); // Set size to 400x400 pixels + pane = frmMain.getContentPane(); // Get content pane + pane.setLayout(null); // Apply null layout + frmMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Close when X is clicked + + // Create controls + lblMonth = new JLabel("January"); + lblYear = new JLabel("Change year:"); + cmbYear = new JComboBox(); + btnPrev = new JButton("<<"); + btnNext = new JButton(">>"); + mtblCalendar = new DefaultTableModel() { + public boolean isCellEditable(int rowIndex, int mColIndex) { + return false; + } + }; + tblCalendar = new JTable(mtblCalendar); + stblCalendar = new JScrollPane(tblCalendar); + pnlCalendar = new JPanel(null); + + // Set border + pnlCalendar.setBorder(BorderFactory.createTitledBorder("Calendar")); + + // Register action listeners + btnPrev.addActionListener(new btnPrev_Action()); + btnNext.addActionListener(new btnNext_Action()); + cmbYear.addActionListener(new cmbYear_Action()); + + // Add controls to pane + pane.add(pnlCalendar); + pnlCalendar.add(lblMonth); + pnlCalendar.add(lblYear); + pnlCalendar.add(cmbYear); + pnlCalendar.add(btnPrev); + pnlCalendar.add(btnNext); + pnlCalendar.add(stblCalendar); + + // Set bounds + pnlCalendar.setBounds(0, 0, 320, 335); + lblMonth.setBounds(160 - lblMonth.getPreferredSize().width / 2, 25, 100, 25); + lblYear.setBounds(10, 305, 80, 20); + cmbYear.setBounds(230, 305, 80, 20); + btnPrev.setBounds(10, 25, 50, 25); + btnNext.setBounds(260, 25, 50, 25); + stblCalendar.setBounds(10, 50, 300, 250); + + // Make frame visible + frmMain.setResizable(false); + frmMain.setVisible(true); + + // Get real month/year + GregorianCalendar cal = new GregorianCalendar(); // Create calendar + realDay = cal.get(GregorianCalendar.DAY_OF_MONTH); // Get day + realMonth = cal.get(GregorianCalendar.MONTH); // Get month + realYear = cal.get(GregorianCalendar.YEAR); // Get year + currentMonth = realMonth; // Match month and year + currentYear = realYear; + + // Add headers + String[] headers = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; // All headers + for (int i = 0; i < 7; i++) { + mtblCalendar.addColumn(headers[i]); + } + + tblCalendar.getParent().setBackground(tblCalendar.getBackground()); // Set background + + // No resize/reorder + tblCalendar.getTableHeader().setResizingAllowed(false); + tblCalendar.getTableHeader().setReorderingAllowed(false); + + // Single cell selection + tblCalendar.setColumnSelectionAllowed(true); + tblCalendar.setRowSelectionAllowed(true); + tblCalendar.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + + // Set row/column count + tblCalendar.setRowHeight(38); + mtblCalendar.setColumnCount(7); + mtblCalendar.setRowCount(6); + + // Populate table + for (int i = realYear - 100; i <= realYear + 100; i++) { + cmbYear.addItem(String.valueOf(i)); + } + + // Refresh calendar + refreshCalendar(realMonth, realYear); // Refresh calendar + } + + public static void refreshCalendar(int month, int year) { + // Variables + String[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", + "October", "November", "December" }; + int nod, som; // Number Of Days, Start Of Month + + // Allow/disallow buttons + btnPrev.setEnabled(true); + btnNext.setEnabled(true); + if (month == 0 && year <= realYear - 10) { + btnPrev.setEnabled(false); + } // Too early + if (month == 11 && year >= realYear + 100) { + btnNext.setEnabled(false); + } // Too late + lblMonth.setText(months[month]); // Refresh the month label (at the top) + lblMonth.setBounds(160 - lblMonth.getPreferredSize().width / 2, 25, 180, 25); // Re-align label with calendar + cmbYear.setSelectedItem(String.valueOf(year)); // Select the correct year in the combo box + + // Clear table + for (int i = 0; i < 6; i++) { + for (int j = 0; j < 7; j++) { + mtblCalendar.setValueAt(null, i, j); + } + } + + // Get first day of month and number of days + GregorianCalendar cal = new GregorianCalendar(year, month, 1); + nod = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH); + som = cal.get(GregorianCalendar.DAY_OF_WEEK); + + // Draw calendar + for (int i = 1; i <= nod; i++) { + int row = new Integer((i + som - 2) / 7); + int column = (i + som - 2) % 7; + mtblCalendar.setValueAt(i, row, column); + } + + // Apply renderers + tblCalendar.setDefaultRenderer(tblCalendar.getColumnClass(0), new tblCalendarRenderer()); + } + + static class tblCalendarRenderer extends DefaultTableCellRenderer { + public Component getTableCellRendererComponent(JTable table, Object value, boolean selected, boolean focused, + int row, int column) { + super.getTableCellRendererComponent(table, value, selected, focused, row, column); + if (column == 0 || column == 6) { // Week-end + setBackground(new Color(255, 220, 220)); + } else { // Week + setBackground(new Color(255, 255, 255)); + } + if (value != null) { + if (Integer.parseInt(value.toString()) == realDay && currentMonth == realMonth + && currentYear == realYear) { // Today + setBackground(new Color(220, 220, 255)); + } + } + setBorder(null); + setForeground(Color.black); + return this; + } + } + + static class btnPrev_Action implements ActionListener { + public void actionPerformed(ActionEvent e) { + if (currentMonth == 0) { // Back one year + currentMonth = 11; + currentYear -= 1; + } else { // Back one month + currentMonth -= 1; + } + refreshCalendar(currentMonth, currentYear); + } + } + + static class btnNext_Action implements ActionListener { + public void actionPerformed(ActionEvent e) { + if (currentMonth == 11) { // Foward one year + currentMonth = 0; + currentYear += 1; + } else { // Foward one month + currentMonth += 1; + } + refreshCalendar(currentMonth, currentYear); + } + } + + static class cmbYear_Action implements ActionListener { + public void actionPerformed(ActionEvent e) { + if (cmbYear.getSelectedItem() != null) { + String b = cmbYear.getSelectedItem().toString(); + currentYear = Integer.parseInt(b); + refreshCalendar(currentMonth, currentYear); + } + } + } +} \ No newline at end of file