problem with "import java.util.Calendar"
in
Programming Questions
•
1 years ago
Hi everyone,
I'm new in all this programming stuff, and I have some problems/questions. I am trying to display a calendar using some java libraries. When I run the program from a new sketch (without saving or giving it a name) the program runs, but when I save it in a directory I get: "The import java.util.Calendar conflicts with a type defined in the same file". Maybe a problem of the sketch directory?
Thanks
Here's the code:
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
Date date;
SimpleDateFormat sdf;
Calendar cal;
Cell[][] grid;
Cell[][] gridDays;
int cols=7;
int rows=6;
String date_;
int _date;
int _month;
int _year;
void setup(){
size(400,400);
grid=new Cell[cols][rows];
for(int i=0;i<cols;i++){
for(int j=0;j<rows;j++){
grid[i][j]=new Cell(30+i*20,30+j*20,20,20);
}
}
cal = Calendar.getInstance();
_date=1;
_month=1;
_year=2011;
sdf = new SimpleDateFormat("M/d/y");
date_=(nf(_month,2,0)+"/"+nf(_date,2,0)+"/"+_year);
println((nf(_month,2,0)+"/"+nf(_date,2,0)+"/"+_year));
cal.set(_month,_date,_year);
try{
date = sdf.parse(date_);
} catch(ParseException e){
println(e);
}
cal.setTime(date);
gridDays=new Cell[8][6];
for(_date=1;_date<=cal.getActualMaximum(Calendar.DAY_OF_MONTH);_date++){
date_=(nf(_month,2,0)+"/"+nf(_date,2,0)+"/"+_year);
//println((nf(_month,2,0)+"/"+nf(_date,2,0)+"/"+_year));
cal.set(_month,_date,_year);
try{
date = sdf.parse(date_);
} catch(ParseException e){
println(e);
}
cal.setTime(date);
int i=cal.get(Calendar.DAY_OF_WEEK);
int j;
if(i==1) j=cal.get(Calendar.WEEK_OF_MONTH)+1;
else j=cal.get(Calendar.WEEK_OF_MONTH);
println("i- "+i+" j- "+j);
gridDays[i][j]=new Cell(15+i*20,45+j*20,20,20);
}
println("Day Of Week: " + cal.get(Calendar.DAY_OF_WEEK));
println("Day Of Month: " + cal.get(Calendar.DAY_OF_MONTH));
println("Week Of Month: " + cal.get(Calendar.WEEK_OF_MONTH));
println("Days Of Month: " + cal.getActualMaximum(Calendar.DAY_OF_MONTH));
}//end of setup
void draw(){
background(255);
for(int i=0;i<cols;i++){
for(int j=0;j<rows;j++){
grid[i][j].display();
}
}
for(_date=1;_date<=cal.getActualMaximum(Calendar.DAY_OF_MONTH);_date++){
date_=(nf(_month,2,0)+"/"+nf(_date,2,0)+"/"+_year);
//println((nf(_month,2,0)+"/"+nf(_date,2,0)+"/"+_year));
cal.set(_month,_date,_year);
try{
date = sdf.parse(date_);
} catch(ParseException e){
println(e);
}
cal.setTime(date);
int i=cal.get(Calendar.DAY_OF_WEEK);
int j;
if(i==1) j=cal.get(Calendar.WEEK_OF_MONTH)+1;
else j=cal.get(Calendar.WEEK_OF_MONTH);
println("i- "+i+" j- "+j);
println(cal.get(Calendar.DAY_OF_MONTH));
gridDays[i][j].displayDays(cal.get(Calendar.DAY_OF_MONTH));
}
}//end of draw
class Cell {
// A cell object knows about its location in the grid as well as its size with the variables x,y,w,h.
float x,y; // x,y location
float w,h; // width and height
float angle; // angle for oscillating brightness
// Cell Constructor
Cell(float tempX, float tempY, float tempW, float tempH) {
x = tempX;
y = tempY;
w = tempW;
h = tempH;
}
void display(){
stroke(0);
rect(x,y,w,h);
}//end of display
void displayDays(int dayTxt){
fill(0);
stroke(0);
text(dayTxt,x,y);
fill(255);
}//end of display
}//end Class Cell
1