Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Weird calendar.

  1. #1
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Smile Weird calendar.

    import java.awt.Font;
    import java.sql.Date;
    import java.util.Calendar;
    import java.util.TimeZone;
     
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
     
     
     
    public class Testing extends JFrame {
    private JMenu menu,menu2;
    private JMenuBar mBar;
    private JPanel panel;
     
    public Testing()
    {
    	setTitle("Testing");
    	panel = new JPanel();
    	panel.setVisible(true);
    	mBar = new JMenuBar();
    	setJMenuBar(mBar);
    	mBar.setVisible(true);
    	menu = new JMenu("");
    	mBar.add(menu);
    	menu2 = new JMenu("");
    	mBar.add(menu2);
     
     
    	Calendar c = Calendar.getInstance();
    int hour = c.get(Calendar.HOUR);
    int meridan = c.get(Calendar.AM_PM);
    int minute = c.get(Calendar.MINUTE);
    int second = c.get(Calendar.SECOND);
     
     
    	c.setFirstDayOfWeek(Calendar.SUNDAY);
    	System.out.println(c.getFirstDayOfWeek());
    	int weekday = c.get(Calendar.DAY_OF_WEEK);
    	System.out.println("Weekday " +weekday);
     
    	int monthDay = c.get(Calendar.DAY_OF_MONTH);
    	int month = c.get(Calendar.MONTH);
    	int year = c.get(Calendar.YEAR);
    	System.out.println(weekday);
    	TimeZone t2 = c.getTimeZone();
    	System.out.println(t2.toString());
    	menu.setToolTipText("This is the menu when the program was opened, which usually will be the same day as today.");
    	Font aFont= menu.getFont();
     
    	Font anotherFont = aFont.deriveFont(Font.BOLD);
    	menu.setFont(anotherFont);
    	if (month == Calendar.JANUARY)
    	{
    		if (weekday ==0)
    		{
    	     menu.setText("Sunday January " + monthDay + "," + year);
    		}
     
    		else if (weekday ==1)
    		{
    			menu.setText("Monday January " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Tuesday January " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Wednesday January " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Thursday January " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Friday January " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday January " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.FEBRUARY)
    	{
    		if (weekday ==0)
    		{
    	     menu.setText("Sunday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==1)
    		{
    			menu.setText("Monday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Tuesday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Wednesday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Thursday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Friday February " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday February " + monthDay + "," + year);
    	}
     
     
    	else if (month == Calendar.MARCH)
    	{
    		if (weekday ==0)
    		{
    	     menu.setText("Sunday March " + monthDay + "," + year);
    		}
     
    		else if (weekday ==1)
    		{
    			menu.setText("Monday March " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Tuesday March " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Wednesday March " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Thursday March " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Friday March " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday March " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.APRIL)
    	{
    		if (weekday ==0)
    		{
    	     menu.setText("Sunday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==1)
    		{
    			menu.setText("Monday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Tuesday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Wednesday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Thursday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Friday April " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday April " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.MAY)
    	{
    		if (weekday ==0)
    		{
    	     menu.setText("Sunday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==1)
    		{
    			menu.setText("Monday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Tuesday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Wednesday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Thursday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Friday May " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday May " + monthDay + "," + year);
    	}
     
    	else if (month== Calendar.JUNE)
    	{
    		if (weekday ==0)
    		{
    	     menu.setText("Sunday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==1)
    		{
    			menu.setText("Monday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Tuesday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Wednesday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Thursday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Friday June " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday June " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.JULY)
    	{
    		if (weekday ==0)
    		{
    	     menu.setText("Sunday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==1)
    		{
    			menu.setText("Monday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Tuesday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Wednesday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Thursday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Friday July " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday July " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.AUGUST)
    	{
    		if (weekday ==0)
    		{
    	     menu.setText("Sunday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==1)
    		{
    			menu.setText("Monday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Tuesday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Wednesday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Thursday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Friday August " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday August " + monthDay + "," + year);
    	}
     
    	else if (month ==Calendar.SEPTEMBER)
    	{
    		if (weekday ==0)
    		{
    	     menu.setText("Sunday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==1)
    		{
    			menu.setText("Monday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Tuesday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Wednesday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Thursday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Friday September " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday September " + monthDay + "," + year);
    	}
     
    	else if (month== Calendar.OCTOBER)
    	{
    		if (weekday ==0)
    		{
    	     menu.setText("Sunday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==1)
    		{
    			menu.setText("Monday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Tuesday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Wednesday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Thursday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Friday October " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday October " + monthDay + "," + year);
    	}
     
    	else if (month==Calendar.NOVEMBER)
    	{
    		if (weekday ==0)
    		{
    	     menu.setText("Sunday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==1)
    		{
    			menu.setText("Monday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Tuesday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Wednesday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Thursday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Friday November " + monthDay + "," + year);
    			JOptionPane.showMessageDialog(null, "Year is:" + year);
    		}
     
    		else
    			menu.setText("Saturday November " + monthDay + "," + year);
    	}
     
    	else
    	{
    		if (weekday ==0)
    		{
    	     menu.setText("Sunday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==1)
    		{
    			menu.setText("Monday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Tuesday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Wednesday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Thursday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Friday December " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday December " + monthDay + "," + year);
    	}
     
    	setContentPane(panel);
    }
     
    public static void main(String[] args)
    {
    	Testing t = new Testing();
    	t.setVisible(true);
    }
    }

    It works a lot better than it used to, but I don't know why it thinks today is Monday.

    Also, how come it seems that even after I ext, the program still runs? Am I running both the JFrame class and the JPanel object at the same time?

    Also, just out of curiosity, if you

    object.setVisible(false);

    will it still take up memory even though invisible until program is closed?

    I mean, I have a window that will ask if you want to exit and since it's not the main window, I don't want
    System.exit(0);
    but tried setVisible(false) instead if yes is selected.
    Would that make it possible for a large amount of invisible windows to be running or am I worrying too much?

    Also, how do you update the time thing? I think I can get it to get the time on my own, but I've no clue how to get it, plus the date in the odd chance that it hits midnight, to update.


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Weird calendar.

    Ok, I've dealt with some of the problems.

    Now the date will work.

    However, though I did check for it, it still looks weird with my minutes and seconds when it's say 12:03:07 it'll say 12:3:7

    Also, minutes aren't updating. I thought what I did would help to do that.

    import java.awt.Font;
    import java.sql.Date;
    import java.util.Calendar;
    import java.util.TimeZone;
     
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
     
    import org.xml.sax.Locator;
     
     
     
    public class Testing extends JFrame {
    private JMenu menu,menu2,menu3;
    private JMenuBar mBar;
    private JPanel panel;
     
    public Testing()
    {
    	setTitle("Testing");
    	panel = new JPanel();
    	panel.setVisible(true);
    	mBar = new JMenuBar();
    	setJMenuBar(mBar);
    	mBar.setVisible(true);
    	menu = new JMenu("");
    	mBar.add(menu);
    	menu2 = new JMenu("");
    	mBar.add(menu2);
    menu3 = new JMenu("");
    mBar.add(menu3);
     
    	Calendar c = Calendar.getInstance();
    int hour = c.get(Calendar.HOUR);
    int meridan = c.get(Calendar.AM_PM);
    int minute = c.get(Calendar.MINUTE);
    int second = c.get(Calendar.SECOND);
     
    if (meridan == Calendar.AM)
    {
    	menu2.setText(hour + ":" + minute+ ":" + second + " A.M.");
    }
     
    else
    {
    	menu2.setText(hour + ":" + minute+ ":" + second + " P.M.");
    }
     
    while (this.isVisible())
    {
    	if (meridan == Calendar.AM)
    	{
    		if (minute < 10 && second < 10)
     
    		menu2.setText(hour + ":" + "0" + minute+ ":" + "0" + second + " A.M.");
    		else if (minute < 10 && second >=10)
     
    			menu2.setText(hour + ":" +  "0" +  minute+ ":" + second + " A.M.");
    		else if (second < 10 && minute >=10)
    			menu2.setText(hour + ":" +    minute+ ":" + "0" + second + " A.M.");
    		else
    			menu2.setText(hour + ":" +    minute+ ":"  + second + " A.M.");
    	}
     
    	else
    	{
    		if (minute < 10 && second < 10)
     
    			menu2.setText(hour + ":" + "0" + minute+ ":" + "0" + second + " P.M.");
    			else if (minute < 10 && second >=10)
     
    				menu2.setText(hour + ":" +  "0" +  minute+ ":" + second + " P.M.");
    			else if (second < 10 && minute >=10)
    				menu2.setText(hour + ":" +    minute+ ":" + "0" + second + " P.M.");
    			else
    				menu2.setText(hour + ":" +    minute+ ":"  + second + " P.M.");
    	}
    }
    System.out.println(Calendar.SATURDAY);
     
    String str = "Time Zone is: " + c.getTimeZone().getID();
     
    menu3.setText(str);
    	c.setFirstDayOfWeek(Calendar.SUNDAY);
    	System.out.println(c.getFirstDayOfWeek());
    	int weekday = c.get(Calendar.DAY_OF_WEEK);
    	System.out.println("Weekday " +weekday);
     
    	int monthDay = c.get(Calendar.DAY_OF_MONTH);
    	int month = c.get(Calendar.MONTH);
    	int year = c.get(Calendar.YEAR);
    	System.out.println(weekday);
    	TimeZone t2 = c.getTimeZone();
    	System.out.println(t2.toString());
    	menu.setToolTipText("This is the menu when the program was opened, which usually will be the same day as today.");
    	Font aFont= menu.getFont();
     
    	Font anotherFont = aFont.deriveFont(Font.BOLD);
    	menu.setFont(anotherFont);
    	if (month == Calendar.JANUARY)
    	{
    		if (weekday ==1 )
    		{
    	     menu.setText("Sunday January " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2 )
    		{
    			menu.setText("Monday January " + monthDay + "," + year);
    		}
     
    		else if (weekday == 3)
    		{
    			menu.setText("Tuesday January " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4 )
    		{
    			menu.setText("Wednesday January " + monthDay + "," + year);
    		}
     
    		else if (weekday == 5)
    		{
    			menu.setText("Thursday January " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday January " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday January " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.FEBRUARY)
    	{
    		if (weekday == 1)
    		{
    	     menu.setText("Sunday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday February " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday February " + monthDay + "," + year);
    	}
     
     
    	else if (month == Calendar.MARCH)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday March " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday March " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday March " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday March " + monthDay + "," + year);
    		}
     
    		else if (weekday == 5)
    		{
    			menu.setText("Thursday March " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday March " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday March " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.APRIL)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday April " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday April " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.MAY)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday May " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday May " + monthDay + "," + year);
    	}
     
    	else if (month== Calendar.JUNE)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday June " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday June " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.JULY)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday July " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday July " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.AUGUST)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday August " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday August " + monthDay + "," + year);
    	}
     
    	else if (month ==Calendar.SEPTEMBER)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday September " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday September " + monthDay + "," + year);
    	}
     
    	else if (month== Calendar.OCTOBER)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday October " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday October " + monthDay + "," + year);
    	}
     
    	else if (month==Calendar.NOVEMBER)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday November " + monthDay + "," + year);
     
    		}
     
    		else
    			menu.setText("Saturday November " + monthDay + "," + year);
    	}
     
    	else
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday December " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday December " + monthDay + "," + year);
    	}
     
    	setContentPane(panel);
    }
     
    public static void main(String[] args)
    {
    	Testing t = new Testing();
    	t.setVisible(true);
    }
    }

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Weird calendar.

    That's how Java displays integers. You'll need to use a number format to get it to display 03. See: DecimalFormat (Java 2 Platform SE v1.4.2)

  4. The Following User Says Thank You to helloworld922 For This Useful Post:

    javapenguin (January 2nd, 2011)

  5. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Weird calendar.

    Quote Originally Posted by helloworld922 View Post
    That's how Java displays integers. You'll need to use a number format to get it to display 03. See: DecimalFormat (Java 2 Platform SE v1.4.2)
    I know that, though I'm not sure what a decimal format could do, though I haven't looked at the link yet. However, I tried this:

    f (meridan == Calendar.AM)
    {
    	menu2.setText(hour + ":" + minute+ ":" + second + " A.M.");
    }
     
    else
    {
    	menu2.setText(hour + ":" + minute+ ":" + second + " P.M.");
    }
     
    while (this.isVisible())
    {
    	if (meridan == Calendar.AM)
    	{
    		if (minute < 10 && second < 10)
     
    		menu2.setText(hour + ":" + "0" + minute+ ":" + "0" + second + " A.M.");
    		else if (minute < 10 && second >=10)
     
    			menu2.setText(hour + ":" +  "0" +  minute+ ":" + second + " A.M.");
    		else if (second < 10 && minute >=10)
    			menu2.setText(hour + ":" +    minute+ ":" + "0" + second + " A.M.");
    		else
    			menu2.setText(hour + ":" +    minute+ ":"  + second + " A.M.");
    	}
     
    	else
    	{
    		if (minute < 10 && second < 10)
     
    			menu2.setText(hour + ":" + "0" + minute+ ":" + "0" + second + " P.M.");
    			else if (minute < 10 && second >=10)
     
    				menu2.setText(hour + ":" +  "0" +  minute+ ":" + second + " P.M.");
    			else if (second < 10 && minute >=10)
    				menu2.setText(hour + ":" +    minute+ ":" + "0" + second + " P.M.");
    			else
    				menu2.setText(hour + ":" +    minute+ ":"  + second + " P.M.");
    	}
    }

  6. #5
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Unhappy Running out of memory!! :(



    package McWoo;
     
    import java.awt.Font;
    import java.sql.Date;
    import java.util.Calendar;
    import java.util.TimeZone;
     
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
     
    import org.xml.sax.Locator;
     
     
     
    public class Testing extends JFrame {
    private JMenu menu,menu2,menu3;
    private JMenuBar mBar;
    private JPanel panel;
     
    public Testing()
    {
    	setTitle("Testing");
    	panel = new JPanel();
    	panel.setVisible(true);
    	mBar = new JMenuBar();
    	setJMenuBar(mBar);
    	mBar.setVisible(true);
    	menu = new JMenu("");
    	mBar.add(menu);
    	menu2 = new JMenu("");
    	mBar.add(menu2);
    menu3 = new JMenu("");
    mBar.add(menu3);
    	 this.setVisible(true);
    	Calendar c = Calendar.getInstance();
     
     
     
    System.out.println("Is Visible:" + this.isVisible());
    while(panel.isVisible())
    {
     
    	int hour = c.get(Calendar.HOUR);
    	int meridan = c.get(Calendar.AM_PM);
    	int minute = c.get(Calendar.MINUTE);
    	int second = c.get(Calendar.SECOND);
    	if (meridan == Calendar.AM)
    	{
    		if (minute < 10 && second < 10)
     
    		menu2.setText(hour + ":" + "0" + minute+ ":" + "0" + second + " A.M.");
    		else if (minute < 10 && second >=10)
     
    			menu2.setText(hour + ":" +  "0" +  minute+ ":" + second + " A.M.");
    		else if (second < 10 && minute >=10)
    			menu2.setText(hour + ":" +    minute+ ":" + "0" + second + " A.M.");
    		else
    			menu2.setText(hour + ":" +    minute+ ":"  + second + " A.M.");
    	}
     
    	else
    	{
    		if (minute < 10 && second < 10)
     
    			menu2.setText(hour + ":" + "0" + minute+ ":" + "0" + second + " P.M.");
    			else if (minute < 10 && second >=10)
     
    				menu2.setText(hour + ":" +  "0" +  minute+ ":" + second + " P.M.");
    			else if (second < 10 && minute >=10)
    				menu2.setText(hour + ":" +    minute+ ":" + "0" + second + " P.M.");
    			else
    				menu2.setText(hour + ":" +    minute+ ":"  + second + " P.M.");
    	}
    }
    System.out.println(Calendar.SATURDAY);
     
    String str = "Time Zone is: " + c.getTimeZone().getID();
     
    menu3.setText(str);
    	c.setFirstDayOfWeek(Calendar.SUNDAY);
    	System.out.println(c.getFirstDayOfWeek());
    	int weekday = c.get(Calendar.DAY_OF_WEEK);
    	System.out.println("Weekday " +weekday);
     
    	int monthDay = c.get(Calendar.DAY_OF_MONTH);
    	int month = c.get(Calendar.MONTH);
    	int year = c.get(Calendar.YEAR);
    	System.out.println(weekday);
    	TimeZone t2 = c.getTimeZone();
    	System.out.println(t2.toString());
    	menu.setToolTipText("This is the menu when the program was opened, which usually will be the same day as today.");
    	Font aFont= menu.getFont();
     
    	Font anotherFont = aFont.deriveFont(Font.BOLD);
    	menu.setFont(anotherFont);
    	if (month == Calendar.JANUARY)
    	{
    		if (weekday ==1 )
    		{
    	     menu.setText("Sunday January " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2 )
    		{
    			menu.setText("Monday January " + monthDay + "," + year);
    		}
     
    		else if (weekday == 3)
    		{
    			menu.setText("Tuesday January " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4 )
    		{
    			menu.setText("Wednesday January " + monthDay + "," + year);
    		}
     
    		else if (weekday == 5)
    		{
    			menu.setText("Thursday January " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday January " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday January " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.FEBRUARY)
    	{
    		if (weekday == 1)
    		{
    	     menu.setText("Sunday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday February " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday February " + monthDay + "," + year);
    	}
     
     
    	else if (month == Calendar.MARCH)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday March " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday March " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday March " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday March " + monthDay + "," + year);
    		}
     
    		else if (weekday == 5)
    		{
    			menu.setText("Thursday March " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday March " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday March " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.APRIL)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday April " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday April " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.MAY)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday May " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday May " + monthDay + "," + year);
    	}
     
    	else if (month== Calendar.JUNE)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday June " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday June " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.JULY)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday July " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday July " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.AUGUST)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday August " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday August " + monthDay + "," + year);
    	}
     
    	else if (month ==Calendar.SEPTEMBER)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday September " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday September " + monthDay + "," + year);
    	}
     
    	else if (month== Calendar.OCTOBER)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday October " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday October " + monthDay + "," + year);
    	}
     
    	else if (month==Calendar.NOVEMBER)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday November " + monthDay + "," + year);
     
    		}
     
    		else
    			menu.setText("Saturday November " + monthDay + "," + year);
    	}
     
    	else
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday December " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday December " + monthDay + "," + year);
    	}
     
    	setContentPane(panel);
    }
     
    public static void main(String[] args)
    {
    	Testing t = new Testing();
    	t.setVisible(true);
    }
    }

    Any way for that to get the time to continually update without running me so low that I have to turn off the computer so that I don't suffer memory or data loss?

    It's not working as it is, though it should be.

    Also, how do I fix it so that it will terminate the program when I hit the X button in the corner?

    Right now it goes on after.

    Probably because both panel and this are both visible but I can't see any way around it. If panel isn't, it won't show it, if this isn't, then it won't show anything and the program will probably terminate.


  7. #6
    Junior Member
    Join Date
    Jan 2011
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Weird calendar.

    one small improvement would be to use a switch statement for this code,,,,

    Also you could try using a new thread Eg.

    // This class extends Thread
    class whileThread extends Thread {
        // This method is called when the thread runs
        public void run() {
     
          //PUT WHILE LOOP IN HERE...
     
        }
    }
     
    // Create and start the thread
    Thread thread = new whileThread();
    thread.start();

    if (month == Calendar.JANUARY)
        {
            if (weekday ==1 )
            {
             menu.setText("Sunday January " + monthDay + "," + year);
            }
     
            else if (weekday ==2 )
            {
                menu.setText("Monday January " + monthDay + "," + year);
            }
     
            else if (weekday == 3)
            {
                menu.setText("Tuesday January " + monthDay + "," + year);
            }
     
            else if (weekday ==4 )
            {
                men
    Last edited by Orthidax; January 3rd, 2011 at 01:42 AM.

  8. The Following User Says Thank You to Orthidax For This Useful Post:

    javapenguin (January 3rd, 2011)

  9. #7
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Weird calendar.

    I don't see what you saying. I'm not making an Applet.

    Why won't it work? Why is the memory running low?

  10. #8
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Weird calendar.

    package McWoo;
     
    import java.awt.Font;
    import java.sql.Date;
    import java.sql.Time;
    import java.util.Calendar;
    import java.util.Locale;
    import java.util.TimeZone;
     
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.xml.stream.Location;
     
    import org.xml.sax.Locator;
     
     
     
    public class Testing extends JFrame {
    private JMenu menu,menu2,menu3, menu4;
    private JMenuBar mBar;
    private JPanel panel;
     
    public Testing()
    {
    	setTitle("Testing");
    	panel = new JPanel();
    	panel.setVisible(true);
    	mBar = new JMenuBar();
    	setJMenuBar(mBar);
    	mBar.setVisible(true);
    	menu = new JMenu("");
    	mBar.add(menu);
    	menu2 = new JMenu("");
    	mBar.add(menu2);
    menu3 = new JMenu("");
    mBar.add(menu3);
    menu4 = new JMenu("");
    mBar.add(menu4);
     
    	Calendar c = Calendar.getInstance();
    Locale[] loc = c.getAvailableLocales() ;
     
    System.out.println(loc[0].getDisplayName());
    System.out.println(Locale.getDefault().getDisplayName());
     
    menu4.setText("Language(Country): " + Locale.getDefault().getDisplayName());
    System.out.println("Is Visible:" + this.isVisible());
    if(panel.isVisible())
    {
     
     
     
     
     
    	int hour = c.get(Calendar.HOUR);
    	int meridan = c.get(Calendar.AM_PM);
    	int minute = c.get(Calendar.MINUTE);
    	int second = c.get(Calendar.SECOND);
    	if (meridan == Calendar.AM)
    	{
    		if (minute < 10 && second < 10)
     
    		menu2.setText(hour + ":" + "0" + minute+ ":" + "0" + second + " A.M.");
    		else if (minute < 10 && second >=10)
     
    			menu2.setText(hour + ":" +  "0" +  minute+ ":" + second + " A.M.");
    		else if (second < 10 && minute >=10)
    			menu2.setText(hour + ":" +    minute+ ":" + "0" + second + " A.M.");
    		else
    			menu2.setText(hour + ":" +    minute+ ":"  + second + " A.M.");
    	}
     
    	else
    	{
    		if (minute < 10 && second < 10)
     
    			menu2.setText(hour + ":" + "0" + minute+ ":" + "0" + second + " P.M.");
    			else if (minute < 10 && second >=10)
     
    				menu2.setText(hour + ":" +  "0" +  minute+ ":" + second + " P.M.");
    			else if (second < 10 && minute >=10)
    				menu2.setText(hour + ":" +    minute+ ":" + "0" + second + " P.M.");
    			else
    				menu2.setText(hour + ":" +    minute+ ":"  + second + " P.M.");
    	}
    }
    System.out.println(Calendar.SATURDAY);
     
    String str = "Time Zone is: " + c.getTimeZone().getID();
     
    menu3.setText(str);
    	c.setFirstDayOfWeek(Calendar.SUNDAY);
    	System.out.println(c.getFirstDayOfWeek());
    	int weekday = c.get(Calendar.DAY_OF_WEEK);
    	System.out.println("Weekday " +weekday);
     
    	int monthDay = c.get(Calendar.DAY_OF_MONTH);
    	int month = c.get(Calendar.MONTH);
    	int year = c.get(Calendar.YEAR);
    	System.out.println(weekday);
    	TimeZone t2 = c.getTimeZone();
    	System.out.println(t2.toString());
    	menu.setToolTipText("This is the menu when the program was opened, which usually will be the same day as today.");
    	Font aFont= menu.getFont();
     
    	Font anotherFont = aFont.deriveFont(Font.BOLD);
    	menu.setFont(anotherFont);
    	if (month == Calendar.JANUARY)
    	{
    		if (weekday ==1 )
    		{
    	     menu.setText("Sunday January " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2 )
    		{
    			menu.setText("Monday January " + monthDay + "," + year);
    		}
     
    		else if (weekday == 3)
    		{
    			menu.setText("Tuesday January " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4 )
    		{
    			menu.setText("Wednesday January " + monthDay + "," + year);
    		}
     
    		else if (weekday == 5)
    		{
    			menu.setText("Thursday January " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday January " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday January " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.FEBRUARY)
    	{
    		if (weekday == 1)
    		{
    	     menu.setText("Sunday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday February " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday February " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday February " + monthDay + "," + year);
    	}
     
     
    	else if (month == Calendar.MARCH)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday March " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday March " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday March " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday March " + monthDay + "," + year);
    		}
     
    		else if (weekday == 5)
    		{
    			menu.setText("Thursday March " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday March " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday March " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.APRIL)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday April " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday April " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday April " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.MAY)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday May " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday May " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday May " + monthDay + "," + year);
    	}
     
    	else if (month== Calendar.JUNE)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday June " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday June " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday June " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.JULY)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday July " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday July " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday July " + monthDay + "," + year);
    	}
     
    	else if (month == Calendar.AUGUST)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday August " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday August " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday August " + monthDay + "," + year);
    	}
     
    	else if (month ==Calendar.SEPTEMBER)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday September " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday September " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday September " + monthDay + "," + year);
    	}
     
    	else if (month== Calendar.OCTOBER)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday October " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday October " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday October " + monthDay + "," + year);
    	}
     
    	else if (month==Calendar.NOVEMBER)
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday November " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday November " + monthDay + "," + year);
     
    		}
     
    		else
    			menu.setText("Saturday November " + monthDay + "," + year);
    	}
     
    	else
    	{
    		if (weekday ==1)
    		{
    	     menu.setText("Sunday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==2)
    		{
    			menu.setText("Monday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==3)
    		{
    			menu.setText("Tuesday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==4)
    		{
    			menu.setText("Wednesday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==5)
    		{
    			menu.setText("Thursday December " + monthDay + "," + year);
    		}
     
    		else if (weekday ==6)
    		{
    			menu.setText("Friday December " + monthDay + "," + year);
    		}
     
    		else
    			menu.setText("Saturday December " + monthDay + "," + year);
    	}
     
    	setContentPane(panel);
    }
     
    public void update(JMenu menu2)
    {
    	Calendar c2 = Calendar.getInstance();
    	int hour = c2.get(Calendar.HOUR);
    	int meridan = c2.get(Calendar.AM_PM);
    	int minute = c2.get(Calendar.MINUTE);
    	int second = c2.get(Calendar.SECOND);
    	if (meridan == Calendar.AM)
    	{
    		if (minute < 10 && second < 10)
     
    		menu2.setText(hour + ":" + "0" + minute+ ":" + "0" + second + " A.M.");
    		else if (minute < 10 && second >=10)
     
    			menu2.setText(hour + ":" +  "0" +  minute+ ":" + second + " A.M.");
    		else if (second < 10 && minute >=10)
    			menu2.setText(hour + ":" +    minute+ ":" + "0" + second + " A.M.");
    		else
    			menu2.setText(hour + ":" +    minute+ ":"  + second + " A.M.");
    	}
     
    	else
    	{
    		if (minute < 10 && second < 10)
     
    			menu2.setText(hour + ":" + "0" + minute+ ":" + "0" + second + " P.M.");
    			else if (minute < 10 && second >=10)
     
    				menu2.setText(hour + ":" +  "0" +  minute+ ":" + second + " P.M.");
    			else if (second < 10 && minute >=10)
    				menu2.setText(hour + ":" +    minute+ ":" + "0" + second + " P.M.");
    			else
    				menu2.setText(hour + ":" +    minute+ ":"  + second + " P.M.");
    	}
    }
    public static void main(String[] args)
    {
    	Testing t = new Testing();
    	t.setVisible(true);
    }
    }

Similar Threads

  1. ClassNotFoundException (bit weird)
    By chronoz13 in forum Exceptions
    Replies: 1
    Last Post: April 26th, 2011, 02:15 AM
  2. Weird thing with JFrame
    By Brt93yoda in forum AWT / Java Swing
    Replies: 2
    Last Post: August 23rd, 2010, 05:00 PM
  3. Simple Input/Output program Acting weird
    By drexasaurus in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 19th, 2010, 02:15 PM
  4. Jsp weird problem
    By johniem in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: February 5th, 2010, 06:46 AM
  5. Weird issue with while loop ending/being skipped
    By ang3c0 in forum Loops & Control Statements
    Replies: 4
    Last Post: December 25th, 2009, 12:09 PM