Re: Need help with 2D array
From: Bryan Boone (Bryan.Boone_at_sas.com)
Date: 05/17/04
- Previous message: Silvio Bierman: "Re: how to set an http request header used in HttpURLConnection ?"
- In reply to: Mark McConnell: "Re: Need help with 2D array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 17 May 2004 14:28:44 -0400
Mark McConnell wrote:
> "Khanh Le" <lekhanh88@earthlink.net> wrote in message news:<2fhoc.16965$Hs1.845@newsread2.news.pas.earthlink.net>...
>
>>Would someone shows me the java syntax to create a 2D array of a calendar,
>>where the rows represents months, such as: Jan, Feb... and columns represent
>>days; assuming that there are 29 days in Feb? I don't know whether to
>>declare this 2D array in String or int, since the months are string while
>>days are int. Thanks
>
>
> I don't think an array is the best approach. You could read about the
> class java.util.Calendar at
> http://java.sun.com/j2se/1.4.2/docs/api/
> That will let you compute that 29 is the last day of Calendar.FEBRUARY
> in 2004, 31 is the last day of Calendar.MARCH in 2003, etc.
>
> To look up an array of int's, starting from a String, you could use a
> Hashtable. This is awkward, so I don't recommend it, but I'll show it
> to you.
>
> import java.util.Hashtable;
>
> Hashtable h = new Hashtable();
> int[] daysJan = new int[31];
> for (int i = 0; i < 31; ++i) {
> daysJan[i] = i+1;
> }
> h.put("January", daysJan);
> // Do the same for the other months.
> // Later...
> String nameOfMonth = "January";
> int[] daysOfMonth = (int[])h.get(nameOfMonth);
> // daysOfMonth is now the int array {1,2,...,31}
I implemented a TableModel backed by a Calendar object and it _greatly_
facilitated the viewing of Date in a JTable. All I was left with was
concentrating the data (that is, the method implentation of TableModel)
and the View (JTable) was going to be taken care of.
No layouts, no custom painting, no custom components, etc, no problem;)
-Bryan
- Previous message: Silvio Bierman: "Re: how to set an http request header used in HttpURLConnection ?"
- In reply to: Mark McConnell: "Re: Need help with 2D array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|