修正这段代码package com.test1; import java.awt.; import javax.swing.; import java.time.*; import java.util.GregorianCalendar; public class CalendarPanel extends JPanel{ /** * */ private static final long serialVersionUID = 1L; GregorianCalendar calendar; LocalDate[]dataArrrays; public LocalDate currentDate; String name[]= {"日","一","二","三","四","五","六"}; public CalendarPanel() { calendar = new GregorianCalendar(); currentDate = LocalDate.now(); dataArrrays = calendar.getCalendarDate(currentDate); showCalendar(dataArrrays); } public void showCalendar(LocalDate[]dataArrays) { removeAll(); GridLayout grid = new GridLayout(7,7); setLayout(grid); JLabel[]titleWeek = new JLabel[7]; JLabel[][] newJLabel = null; @SuppressWarnings("null") JLabel[]showDay = newJLabel[42]; for(int i=0;i<7;i++) { titleWeek[i]=new JLabel(name[i],JLabel.CENTER); add(titleWeek[i]); } for(int i=0;i<42;i++) { showDay[i] = newJLabel("",JLabel.CENTER); } for(int k=7,i=0;k<49;k++,i++) { add(showDay[i]); } int space = printSpace(dataArrays[0].getDayOfWeek()); for(int i=0,j=space+i;i<dataArrays.length;i++,j++) { add(showDay[i]); } repaint(); } private JLabel newJLabel(String string, int center) { // TODO Auto-generated method stub return null; } public void setNext() { currentDate = currentDate.plusMonths(1); dataArrrays = calendar.getCalendarDate(currentDate); showCalendar(dataArrrays); } public void setPrevious() { currentDate = ((LocalDate) currentDate).plusMonths(-1); dataArrrays = ((Object) calendar).getCaledar(currentDate); showCalendar(dataArrrays); } public int printSpace(DayOfWeek x) { int n = 0; switch(x) { case SUNDAY: n=0; break; case MONDAY: n=1; break; case TUESDAY: n=2; break; case WEDNESDAY: n=3; break; case THURSDAY: n=4; break; case FRIDAY: n=5; break; case SATURDAY: n=6; break; } return n; } }
时间: 2024-04-27 08:23:23 浏览: 143
java爱心代码,非常漂亮,把妹必备.docx
这段代码存在一些错误,需要进行修改:
1. 第5行代码应该是`import java.util.Calendar;`而不是`java.time.*;`
2. 第17行代码应该是`dataArrrays = calendar.getCalendarDates(currentDate);`而不是`dataArrrays = calendar.getCalendarDate(currentDate);`
3. 第21行代码中应该是`newJLabel = new JLabel[6][7];`而不是`newJLabel = null;`
4. 第22行代码应该是`showDay[i] = new JLabel("",JLabel.CENTER);`而不是`showDay[i] = newJLabel("",JLabel.CENTER);`
5. 第31行代码中应该是`add(showDay[j]);`而不是`add(showDay[i]);`
6. 第44行代码中应该是`dataArrrays = calendar.getCalendarDates(currentDate);`而不是`dataArrrays = ((Object) calendar).getCaledar(currentDate);`
7. 第54行代码中应该是`printSpace(dataArrays[0].getDayOfWeek());`而不是`printSpace(dataArrays[0]);`
8. 第57行代码中应该是`add(showDay[j]);`而不是`add(showDay[i]);`
另外,第28行代码中的`newJLabel`方法未被实现,需要根据具体需求进行实现。
阅读全文