Below is the java code for getting a calendar for current date. I have to reuse it for the month and year entered by user..* My query is how to pass month and year from user and in which format to the below java code... -
package com.cj.htmlcal;
-
-
import java.text.SimpleDateFormat;
-
import java.util.*;
-
-
public class HtmlCalendar
-
{
-
-
-
private static String NEWLINE = "\n";
-
public static final int MONDAY_FIRST = 1;
-
public static final int SUNDAY_FIRST = 2;
-
private Hashtable cnf;
-
private static final String Mnth[] = {
-
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
-
"Nov", "Dec"
-
};
-
private int year;
-
private int month;
-
private int style;
-
private String sFont;
-
private Locale loc;
-
-
public HtmlCalendar()
-
{
-
sFont = null;
-
GregorianCalendar gregoriancalendar = new GregorianCalendar();
-
cnf = new Hashtable();
-
NEWLINE = System.getProperty("line.separator");
-
style = 2;
-
month = gregoriancalendar.get(2) + 1;
-
year = gregoriancalendar.get(1);
-
loc = Locale.US;
-
}
-
-
public void setLocale(Locale locale)
-
{
-
loc = locale;
-
}
-
-
public Locale getLocale()
-
{
-
return loc;
-
}
-
-
public void setYear(int i)
-
{
-
if(i > 0)
-
{
-
year = i;
-
cnf.clear();
-
}
-
}
-
-
public int getYear()
-
{
-
return year;
-
}
-
-
public void setMonth(int i)
-
{
-
if(i >= 1 && i <= 12)
-
{
-
month = i;
-
cnf.clear();
-
}
-
}
-
-
public int getMonth()
-
{
-
return month;
-
}
-
-
public void setStyle(int i)
-
{
-
style = i;
-
}
-
-
public int getStyle()
-
{
-
return style;
-
}
-
-
private int getDay(Calendar calendar)
-
{
-
if(style == 2)
-
return calendar.get(7) - 1;
-
else
-
return (calendar.get(7) + 5) % 7;
-
}
-
-
public void setActions(String s, String s1)
-
{
-
for(int i = 1; i <= 31; i++)
-
setAction(i, s, s1);
-
-
}
-
-
public void setAction(int i, String s, String s1)
-
{
-
if(s != null)
-
{
-
cnf.put("" + i, s);
-
if(s1 != null && s1.length() > 0)
-
cnf.put(i + "target", s1);
-
}
-
}
-
-
public String getHtml()
-
{
-
GregorianCalendar gregoriancalendar = new GregorianCalendar(year, month - 1, 1);
-
GregorianCalendar gregoriancalendar1 = new GregorianCalendar(2001, 0, 14);
-
SimpleDateFormat simpledateformat = new SimpleDateFormat("EEE", loc);
-
int i = month - 1;
-
int j = 0;
-
StringBuffer stringbuffer = new StringBuffer("");
-
stringbuffer.append("<table><tr>\n");
-
if(style == 2)
-
{
-
stringbuffer.append("<th align=right>" + formatObject(sFont, simpledateformat.format(gregoriancalendar1.getTime())) + "</th>\n");
-
gregoriancalendar1.add(5, 1);
-
for(int k = 1; k < 7; k++)
-
{
-
stringbuffer.append("<th align=right>" + formatObject(sFont, simpledateformat.format(gregoriancalendar1.getTime())) + "</th>\n");
-
gregoriancalendar1.add(5, 1);
-
}
-
-
} else
-
{
-
gregoriancalendar1.add(5, 1);
-
stringbuffer.append("<th align=right>" + formatObject(sFont, simpledateformat.format(gregoriancalendar1.getTime())) + "</th>\n");
-
for(int l = 2; l < 8; l++)
-
{
-
gregoriancalendar1.add(5, 1);
-
stringbuffer.append("<th align=right>" + formatObject(sFont, simpledateformat.format(gregoriancalendar1.getTime())) + "</th>\n");
-
}
-
-
}
-
stringbuffer.append("</tr>\n");
-
int i1 = 0;
-
j = 0;
-
if(getDay(gregoriancalendar) > 0)
-
{
-
stringbuffer.append("<tr>");
-
for(; i1 < getDay(gregoriancalendar); i1++)
-
{
-
stringbuffer.append("<td align=right>");
-
if(sFont != null)
-
stringbuffer.append(sFont + " ");
-
else
-
stringbuffer.append(" ");
-
stringbuffer.append("</td>\n");
-
j++;
-
}
-
-
}
-
for(; gregoriancalendar.get(2) == i; gregoriancalendar.add(5, 1))
-
{
-
int j1 = gregoriancalendar.get(5);
-
int k1 = (i1 + j1) % 7;
-
/*if(k1 == 1)
-
{
-
stringbuffer.append("<tr>" + NEWLINE);
-
j = 0;
-
}*/
-
stringbuffer.append("<td align=right>");
-
j++;
-
if(sFont != null)
-
stringbuffer.append(sFont);
-
String s;
-
if((s = (String)cnf.get(j1 + "")) != null)
-
{
-
stringbuffer.append("<a href=\"");
-
if(s.toUpperCase().startsWith("HTT") || s.indexOf(".") > 0)
-
{
-
stringbuffer.append(s);
-
if(s.indexOf("?") < 0)
-
-
-
stringbuffer.append("?date=" + stringDate(gregoriancalendar));
-
else
-
stringbuffer.append("&date=" + stringDate(gregoriancalendar));
-
-
}
-
else
-
{
-
stringbuffer.append("javascript:" + s + "('" + stringDate(gregoriancalendar) + "');");
-
}
-
stringbuffer.append("\"");
-
if((s = (String)cnf.get(j1 + "target")) != null)
-
stringbuffer.append(" target=\"" + s + "\"");
-
stringbuffer.append(">");
-
stringbuffer.append(gregoriancalendar.get(5));
-
stringbuffer.append("</a>\n");
-
} else
-
{
-
stringbuffer.append(j1 + "");
-
}
-
if(sFont != null)
-
stringbuffer.append("");
-
//stringbuffer.append("</td>\n");
-
if(k1 == 0)
-
stringbuffer.append("</tr>\n");
-
}
-
-
if(j < 7)
-
{
-
for(; j < 7; j++)
-
{
-
stringbuffer.append("<td align=right>");
-
if(sFont != null)
-
stringbuffer.append(sFont);
-
stringbuffer.append(" ");
-
if(sFont != null)
-
stringbuffer.append("");
-
stringbuffer.append("</td>\n");
-
}
-
-
stringbuffer.append("</tr>\n");
-
}
-
stringbuffer.append("</table>\n");
-
return stringbuffer.toString();
-
}
-
-
private String stringDate(Calendar calendar)
-
{
-
String s = "" + calendar.get(1);
-
//return s + twoDigits(calendar.get(2) + 1) + twoDigits(calendar.get(5));
-
return s + twoDigits(calendar.get(2) + 1);
-
}
-
-
private String twoDigits(int i)
-
{
-
String s = "" + i;
-
if(s.length() == 1)
-
return "0" + s;
-
else
-
return s;
-
}
-
-
private String formatObject(String s, Object obj)
-
{
-
String s1 = "";
-
if(obj != null)
-
s1 = "" + obj;
-
if(s == null)
-
return s1;
-
else
-
return s + s1 + "";
-
}
-
-
}
-
-
4 2067
Did you write this code?
Have you worked with Java before?
Did you write this code?
Have you worked with Java before?
No i am new to java.. the working of this current code is that when we call this java calss from jsp page it displays dates of the current month.. i want to use it for month and year ented bu user.
Please explain your problem clearly.
Please explain your problem clearly.
Currently I have two files 1 is a jaa bean class file poted in the question and the other is jsp file which is calling the java bean class.
Currently when I execute this code it genrates calendar of current month and year . It takes the current month and year from system.
But I want to modify tis code in a way so that I can pass values of month and year from a jsp to this java file and then this java file will genrate calendar of that particular year.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: vigi98 |
last post by:
Hello all,
I do the following :
SimpleDateFormat df = new
SimpleDateFormat("yyyy-MM-dd");
Calendar d = new GregorianCalendar(2004,11,30);
d.add(Calendar.DATE, 7);
dt=d.getTime();...
|
by: cg_news |
last post by:
In short, what I am trying to do is, based on a date, calculate the week of
year (as described in ISO 8601), then calculate the first and last date in
this week period and return them in the format...
|
by: chennakeshava_ramesh |
last post by:
hi,
I have a problem, I am not able to find out which day of the week it
is using the calendar class.
I am using set() function to set the date
and want to find out which day i.e mon,tue etc of...
|
by: COmbined |
last post by:
Does anyone know of a control (freeware or commercial) that has a swing
based implementation of a calendar control that I can use for recording
bookings for objects
Thanks Combined
|
by: skyblue |
last post by:
//can somebody help me with this please. i need to create a //calendar on the frame. i got the frame but the calendar is not //woking.
import jpb.*;
import java.awt.*;
import...
|
by: Rajkishore Kumar |
last post by:
We have a piece of code written in Java Script in an ASP.Net appln in Visual Studio 2003 and it works fine. What it does is , when you press a date icon , it would open up a calendar(prepared by...
|
by: Larry C |
last post by:
Hello,
Not a programmer at all so I apologize if this makes no sense.
We have an old app that runs on Windows Server 2003 and uses OC4J. We
wanted to add a calendar to the app that we could...
|
by: basm101 |
last post by:
Hi,
I have a java Calendar object, observationDate.
java.util.Calendar observationDate=subsequentSub.getObservationDate();
I want to trigger a javascript function upon clicking a radio...
|
by: abhishekbrave |
last post by:
Hi, I have to reuse the code given below for displaying a calendar according to the month and year specified by user ...currently this code is fetching systme date and genrating calendar for that......
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |