我的程序中似乎有一个错误,我无法解决我的生活问题。
以下是代码:
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
import java.util.*;
public class CalendarGUI extends JPanel {
ProgramCalendar currentCalendar;
GregorianCalendar sideCalendar;
String[] month = {"January", "February", "March", "April", "May", "June", "July", "August",
"September", "October", "November", "December"};
public CalendarGUI(ProgramCalendar pc){
currentCalendar = pc;
sideCalendar = new GregorianCalendar();
JPanel calendarSidePanel = new JPanel();
calendarSidePanel.setSize(400,400);
calendarSidePanel.setLayout(new BorderLayout());
//sets month
JTextPane monthText = new JTextPane();
monthText.setText(month[sideCalendar.get(Calendar.MONTH)]);
calendarSidePanel.add(monthText, BorderLayout.NORTH);
//main part of error
JPanel sideCalendarMain = new JPanel(new GridLayout(6, 7, 5, 5));
JTextPane sun = new JTextPane();
sun.setText("Sun");
sideCalendarMain.add(sun);
JTextPane mon = new JTextPane();
mon.setText("Mon");
sideCalendarMain.add(mon);
JTextPane tues = new JTextPane();
tues.setText("Tues");
sideCalendarMain.add(tues);
JTextPane wed = new JTextPane();
wed.setText("Wed");
sideCalendarMain.add(wed);
JTextPane thurs = new JTextPane();
thurs.setText("Thur");
sideCalendarMain.add(thurs);
JTextPane fri = new JTextPane();
fri.setText("Fri");
sideCalendarMain.add(fri);
JTextPane sat = new JTextPane();
sat.setText("Sat");
sideCalendarMain.add(sat);
calendarSidePanel.add(sideCalendarMain, BorderLayout.CENTER);
add(calendarSidePanel);
setSize(1000,1000);
}
}
问题在于我认为它会显示为:
April
Sun Mon Tues Wed Thurs Fri Sat
而不是
April
Sun Mon
Tues Wed
Thurs Fri
Sat
目前正在显示。
我是否只是在滥用GridLayout,或者是否存在其他一些我遗漏的基本错误,或者是一些随机错误。 感谢