2 yjkup yjkup 于 2016.04.07 17:59 提问

java谁能告诉我怎么改

import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Calendar;
import PCalendar.PCalendar;
public class CalendarFrame extends JFrame {
int i;
private PCalendar model;
private JLabel yearAndMonth;
private JLabel[] days=new JLabel[42];
public CalendarFrame(PCalendar model){
this.model=model;
model.setView(this);
setTitle("万年历");
setSize(400,400);
init();
this.setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
}
private void init(){
Container contentPane=getContentPane();
contentPane.setLayout(null);
JLabel weeks[]={new JLabel("周日"),new JLabel("周一"),new JLabel("周二"),new JLabel("周三"),new JLabel("周四"),new JLabel("周五"),new JLabel("周六")};
for(int i=0;i {
weeks[i].setBounds(40+50*i, 50, 50, 30);
contentPane.add(weeks[i]);
JLabel monthRec=new JLabel(" monthRec.setBounds(130, 20, 20, 20);
contentPane.add(monthRec);
JLabel monthInc=new JLabel(">>");
monthInc.setBounds(250, 20, 20, 20);
contentPane.add(monthInc);
yearAndMonth=new JLabel("");
yearAndMonth.setBounds(165, 20, 80, 20);
contentPane.add(yearAndMonth);
for(int i=0;i<days.length;i++){
days[i]=new JLabel("");
days[i].setBounds(40+(i%7)*50, 90+(i/7*50), 20, 20);
contentPane.add(days[i]);
}
monthRec.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
model.recMonth();
}
});
monthInc.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
model.incMonth();
}
});

}
public void showCalendar() {
    for(int i=0;i<days.length;i++){
        days[i].setText("");
        days[i].setForeground(Color.black);
    }
    String str=model.getYearAndMonth();
    int firstDayOfWeek=model.getFirstDayOfWeek();
    int maxday=model.getMaxDay();
    yearAndMonth.setText(str);
    Calendar calendar=Calendar.getInstance();
    int currDay=calendar.get(Calendar.MONTH)+1;
    int m=model.getCurrMonth(yearAndMonth.getText());
    for(int i=0;i<maxDay;i++){
        days[i+firstDayOfWeek-1].setText(""+(i+1));
        int day=Integer.parseInt(days[i+firstDayOfWeek-1].getText());
        int currMonth;
        if(day==currDay&&currMonth==m){
            days[i+firstDayOfWeek-1].setForeground(Color.red);
        }
    }
}

public static void main(String[] args){
PCalendar pCalendar=new PCalendar();
CalendarFrame frame=new CalendarFrame(pCalendar);
frame.setVisible(true);
frame.showCalendar();
}
}
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class PCalendar {
private Calendar calendar;
private CalendarFrame view;
public PCalendar(){
calendar=Calendar.getInstance();
}
public void recMonth(){
int month=calendar.get(Calendar.MONTH);
calendar.set(Calendar.MONTH, month-1);
view.showCalendar();
}
public void incMonth(){
int month=calendar.get(Calendar.MONTH);
calendar.set(Calendar.MONTH, month+1);
view.showCalendar();
}
public void setView(CalendarFrame view){
this.view=view;
}
public String getYearAndMonth(){
Date date=calendar.getTime();
SimpleDateFormat sdf=new SimpleDateFormat("yyy-MM");
return sdf.format(date);
}
public int getFirstDayOfWeek(){
calendar.set(Calendar.DATE,1);
int dayOfWeek=calendar.get(Calendar.DAY_OF_WEEK);
return dayOfWeek;
}
public int getMaxDay(){
return calendar.getActualMaximum(Calendar.DATE);
}
public int getCurrMonth(String yearAndMonth){
String[] ss=yearAndMonth.split("-");
int month =-1;
if(ss[1].indexOf("0")==0){
month=Integer.parseInt(ss[1].substring(1));
}
else{
month=Integer.parseInt(ss[1]);
}
return month;
}

}
1.calendarFrame为什么无法解析类型。
2.描述 资源 路径 位置 类型
maxDay cannot be resolved to a variable CalendarFrame.java /wan/src 第 70 行 Java 问题
3.描述 资源 路径 位置 类型
局部变量 i 重复 CalendarFrame.java /wan/src 第 41 行 Java 问题

2个回答

caozhy
caozhy   Ds   Rxr 2016.04.08 05:48

CalendarFrame定义在CalendarFrame.java文件中了么?
Main所在的源代码有imports它么

u011225629
u011225629   2016.04.08 11:30

CalendarFrame.java无法应用!maxDay就不会用到了!
引入的路径是否正确呢?

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!