The Artima Developer Community
Sponsored Link

Java Answers Forum
java calendar

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
will weston

Posts: 1
Nickname: willw
Registered: Jan, 2007

java calendar Posted: Jan 22, 2007 8:46 AM
Reply to this message Reply
Advertisement
hello, i was wondering if anyone out there would be able to help me with my java program, i just cant seem to get it to work! i know its a simple program, i want it to work without using the calendar class

here is my code:

/**
* @(#)javaCalendar.java
*
* javaCalendar Applet application
*
* @author will weston
* @version 1.00 2007/1/15
*/

import java.awt.*;
import java.util.*;
import java.applet.*;
import javax.swing.*;


public class javaCalendar extends JApplet {
JPanel top;
JPanel bottom;
JButton view;
TextField year;
TextField year3;
TextField selectedYear;
int j, f;
int monthIn1, monthIn2;
String thisDay;
int dayOne;
int thisMonth;
int thisYear;
int yearTwo;
int selectedMonth;
Choice mnthChoice;

int numValue;
int numValueAdd;
int DayOfWeek;
int c, d;
int z;
int m;
int mnthDays;

//formula for working out start position, CHANGE TO BOOLEAN ACTION

public void init() {

setSize (new Dimension (1200,500));
Container container = getContentPane();
container.setLayout(new BorderLayout());
top = new JPanel();
//grid layout
bottom = new JPanel(new GridLayout(7, 7, 2, 2));
//get month from user
mnthChoice = new Choice();
mnthChoice.add("January");
mnthChoice.add ("February");
mnthChoice.add("March");
mnthChoice.add ("April");
mnthChoice.add ("May");
mnthChoice.add ("June");
mnthChoice.add ("July");
mnthChoice.add ("August");
mnthChoice.add ("September");
mnthChoice.add ("October");
mnthChoice.add ("November");
mnthChoice.add ("December");
top.add(mnthChoice);
//assigns numbers to months
monthIn1 = mnthChoice.getSelectedIndex();
//text field and view button

selectedYear = new TextField ("2007");
top.add(selectedYear);

top.add(view = new JButton ("view"));
container.add(top, "North");
//calendar day headings
bottom.add(new JLabel("Mon", 0));
bottom.add(new JLabel("Tue", 0));
bottom.add(new JLabel("Wed", 0));
bottom.add(new JLabel("Thur", 0));
bottom.add(new JLabel("Fri", 0));
bottom.add(new JLabel("Sat", 0));
bottom.add(new JLabel("Sun", 0));
container.add(bottom, "South");


}//init end
public boolean action (Event e, Object o){


if (e.target == view)
{
thisYear = Integer.parseInt(year.getText());
monthIn1 = mnthChoice.getSelectedIndex();

if (monthIn1 <= 1)
{
monthIn2 = monthIn1 +10;
thisYear = thisYear - 1;
monthIn2 ++;
}
else if (monthIn1 > 1)
{
monthIn2 = monthIn1 - 2;
monthIn2 ++;
}
//array
switch (monthIn1)
{
case 2: mnthDays = 30; break;
case 4: mnthDays = 30; break;
case 7: mnthDays = 30; break;
case 9: mnthDays = 30; break;
case 12: mnthDays = 28; break;
default: mnthDays = 31; break;
}
int thisYear = Integer.parseInt(year.getText());
c = thisYear / 100;
d = thisYear % 100;


f = 1 + ((13*monthIn1 - 1)/5) + d + (d/4) + (c/4) - 2*c;
dayOne = f % 7;
if (dayOne < 0){ dayOne = dayOne + 7; }

if (monthIn1 == 12)
{
byte byte0 = 2;
int k = 1;
boolean flag = false;
for(j = 0; j < byte0; j++)
bottom.add(new JButton(""));

for(j = 0; j < 28; j++)
bottom.add(new JButton(Integer.toString(k++)));

for(; j < 42 - byte0; j++)
bottom.add(new JButton(""));

if (((thisYear+1)%4 == 0) && (((thisYear+1)%100 != 0) || ((thisYear+1)%400 == 0)))
{mnthDays = 29;}
else
{mnthDays = 28;}
}
for(int i = 1; i<(dayOne) +1; ++i)
{j.setLabel("");}
for(int i = dayOne+1; i<(mnthDays + dayOne) +1; ++i)
{j.setLabel(Integer.toString(i - dayOne));}
for(int i = mnthDays + dayOne + 1; i<(43); ++i)
{j.setLabel("");}
}
return true;
}
return false;
}

any help whatsoever would be greatly appreciated
Will

Topic: java calendar Previous Topic   Next Topic Topic: 'dataSource' is not writable in bean class [org.springframework.orm.ibatis.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use