1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
public class Calendrier_test {
//clendrier_test attribute
private Locale loc;
private TimeZone zone;
private DateFormatSymbols dfs;
//Methods added for calendrier_test class
//default contructor
public Calendrier_test(Locale loc, TimeZone zone, DateFormatSymbols dfs) {
super();
// TODO Auto-generated constructor stub
this.loc = loc;
this.zone = zone;
this.dfs = dfs;
}
public String ShowCalendar()
{
GregorianCalendar gc = new GregorianCalendar(this.zone,this.loc);
//String output= "";
GregorianCalendar gc_ref =new GregorianCalendar(this.zone,this.loc);
String[] mois = this.dfs.getMonths();
String[] jours = this.dfs.getWeekdays();
final int t = Calendar.getInstance().get(Calendar.YEAR);
final int k = Calendar.getInstance().get(Calendar.MONTH);
String output = "";
output = output + "current Year is "+ t+ "\n" ;
//this code is usefull to full parcours of the YEAR on month
for (int i = 0; i < mois.length - 1; i++) {
//for show present,pass and future month
if ((i == k))
//||(i == k-1 )||(i == k+1) )
{
gc.set(t, i, 1);
gc_ref.set(t, i + 1, 1);
output =output + mois[gc.get(Calendar.MONTH)].toUpperCase()+ "\n";
for (int j = 1; j < jours.length; j++) {
output = output + jours[j].toUpperCase() + " ";
}
output=output + "\n";
int premier = gc.get(Calendar.DAY_OF_WEEK);
if(premier > 1) {
for (int j = 1; j < premier; j++) {
output=output +"\t";
}
}
while(gc.before(gc_ref)) {
output = output + gc.get(Calendar.DAY_OF_MONTH) + "\t";
if(gc.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)
output=output + "\n";
gc.add(Calendar.DAY_OF_MONTH, +1);
}
output=output +"\n";
}
}
return output;
}
} |
Partager