Create html-js HTML calendar in java

I am trying to replicate a UI like gcalendar (only the layout does not do any of its functionality) how to build a calendar loop to build a nice layout like this? with marked days and holidays.

thanks

0


a source to share


1 answer


java code:

public class CalendarUI {
    public static String Dias[] = { "", "DOM", "SEG", "TER", "QUA", "QUI", "SEX", "SAB" };
    public static String Meses[] = { "JAN", "FEV", "MAR", "ABR", "MAI", "JUN", "JUL", "AGO", "SET", "OUT", "NOV", "DEZ" };

    public static void printCalendar(int currMonth){
        int i = 1;      
        Calendar c = Calendar.getInstance();
        NumberFormat formatter = new DecimalFormat("##00");


        c.set(Calendar.YEAR, 2009);
        c.set(Calendar.MONTH, currMonth);
        c.set(Calendar.DATE, i);

        // cabecalho com o mes
        System.out.println(" - " + Meses[currMonth] + " - ");

        // ajuste para o primeiro dia
        for (; i < c.get(Calendar.DAY_OF_WEEK); i++) {
            System.out.print("           ");
        }

        // principal
        for (i = 1; i <= 31; i++) {
            c.set(Calendar.DATE, i);

            if (c.get(Calendar.MONTH) == currMonth) {       
                if (c.get(Calendar.DAY_OF_WEEK) == 1)
                    System.out.println("");

                System.out.print("[ " + Dias[c.get(Calendar.DAY_OF_WEEK)]
                        + ", " + formatter.format(i) + " ]");
            }
        }       

        System.out.println("\n\n");
    }

    public static void main(String[] args) {
        for (int j = 0; j < 12; j++) {
            CalendarUI.printCalendar(j);

        }

    }

      




output with the correct indentation of days in months (example provided for may):

 - MAI - 
                                                       [ SEX, 01 ][ SAB, 02 ]
[ DOM, 03 ][ SEG, 04 ][ TER, 05 ][ QUA, 06 ][ QUI, 07 ][ SEX, 08 ][ SAB, 09 ]
[ DOM, 10 ][ SEG, 11 ][ TER, 12 ][ QUA, 13 ][ QUI, 14 ][ SEX, 15 ][ SAB, 16 ]
[ DOM, 17 ][ SEG, 18 ][ TER, 19 ][ QUA, 20 ][ QUI, 21 ][ SEX, 22 ][ SAB, 23 ]
[ DOM, 24 ][ SEG, 25 ][ TER, 26 ][ QUA, 27 ][ QUI, 28 ][ SEX, 29 ][ SAB, 30 ]
[ DOM, 31 ]

      

0


a source







All Articles