使用逻辑更改布局

时间:2016-03-18 09:06:06

标签: java

我的日历项目遇到问题。我目前拥有所有我需要的东西,它是完整的,除了它在列表中而不是像日历那样列出。我不想使用swing或任何导入,而是使用逻辑来创建一个好的布局,因为我被告知这是可能的。

目前我的代码是:

public static String[] teamJedi = {"Andrew", "Sanjay", "Austen", "Rob"};

    public static String[] daysOfWeek = {"| SUN | MON | TUE | WED | THUR | FRI | SAT |"};

    public static void main(String[] args) {

        System.out.println(Arrays.toString(daysOfWeek));

        Calendar calendar = getMonthCalendar(args);


        int month = calendar.get(MONTH);


        // int teamSize = teamJedi.length;

        int counter = findOffSetToStart(teamJedi, args[2]);

        while (calendar.get(MONTH) == month) {
            System.out.println(calendar.getTime());

            if (!isWeekEnd(calendar)) {
                System.out.println(teamJedi[counter++ % 4]);
            }

            calendar.add(DATE, 1);

        }
    }

    private static int findOffSetToStart(String[] teamJedi, String args) {
        return Arrays.asList(teamJedi).indexOf(args);
    }

    private static Calendar getMonthCalendar(String[] args) {

        Calendar calendar = getInstance();

        int year = Integer.parseInt(args[0]);
        int month = Integer.parseInt(args[1]);
        calendar.set(year, month, 1);

        calendar.set(DAY_OF_MONTH, 1);
        calendar.set(HOUR_OF_DAY, 0);
        calendar.set(MINUTE, 0);
        calendar.set(SECOND, 0);
        calendar.set(MILLISECOND, 0);


        return calendar;
    }

    private static boolean isWeekEnd(Calendar calendar) {
        return (calendar.get(DAY_OF_WEEK)) == SATURDAY || (calendar.get(DAY_OF_WEEK) == SUNDAY);
    }


}

这是一个列表的输出,那么我该怎么做才能获得传统的日历布局?

0 个答案:

没有答案