views:

118

answers:

1

Hello guys,

I'm trying to replicate a UI like a gcalendar (only the layout not any of its functions) how to build a loop with a calendar to build a cute layout like that? with saturdays marked and holidays too.

Thx

A: 

the 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);

     }

    }


the output with correct indent of days in months (example given 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 ]
Kamia
now basically, change the print tags, its possible to ouput the correct html for the UI.
Kamia