easter...

package celebrate;


/**

* @author Marc Heiligenstein

*

* Easter ,Acension and Pentecost after good old Gauss

*/


import java.applet.*;

import java.awt.*;

import java.awt.event.*;


public class Easter extends Applet implements ActionListener{


private Thread easterThread;


private Button knopf;


private int jahr, m, n;


//Textfields for getting and showing text

private TextField eingabe, ostern, himmel, pfingsten;


//Labels for showing text

private Label leingabe, lostern, lhimmel, lpfingsten;


//Some color

private Color blue = new Color(25, 0, 240),

red = new Color(150, 0, 50),

green = new Color(0, 100, 100);


// A mark for calculating Acension and Pentecost

private int merken = 0;


//Starting the applet

public void start() {


easterThread = new Thread();

easterThread.start();


}


public void init() {


//The Layout-Manager

GridBagLayout gridbag = new GridBagLayout();

GridBagConstraints c = new GridBagConstraints();

setFont(new Font("Arial", Font.PLAIN, 15));

setLayout(gridbag);


//Label for the year

c.weighty = 0.25;

c.weightx = 1.0;

leingabe = new Label("Year: ");

gridbag.setConstraints(leingabe, c);

add(leingabe);


//Text-Field for the submission of the year


c.weighty = 0.25;

c.gridwidth = GridBagConstraints.REMAINDER;

eingabe = new TextField("2005", 15);

eingabe.setFont(new Font("Monospaced", Font.PLAIN, 15));

gridbag.setConstraints(eingabe, c);

add(eingabe);


//The button which causes the calculation

c.gridwidth = 1;

knopf = new Button("Easter");

knopf.setBackground(green);

c.anchor = GridBagConstraints.CENTER;

c.gridwidth = GridBagConstraints.REMAINDER;

gridbag.setConstraints(knopf, c);

add(knopf);

//When the button is pressed

knopf.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(ActionEvent h) {

knopf_actionPerformed(h);

}

});


//For the output,at first for Easter

c.gridwidth = 1;

lostern = new Label("Date of Easter: ");

gridbag.setConstraints(lostern, c);

add(lostern);


//Output Easter

c.gridwidth = GridBagConstraints.REMAINDER;

ostern = new TextField(15);

ostern.setEditable(false);

ostern.setForeground(blue);

gridbag.setConstraints(ostern, c);

add(ostern);


//Acension

c.gridwidth = 1;

lhimmel = new Label("Date of Acension: ");

gridbag.setConstraints(lhimmel, c);

add(lhimmel);


//Output Acension

c.gridwidth = GridBagConstraints.REMAINDER;

himmel = new TextField(15);

himmel.setEditable(false);

himmel.setForeground(green);

gridbag.setConstraints(himmel, c);

add(himmel);


//Pentecost

c.gridwidth = 1;

lpfingsten = new Label("Date of Pentecost: ");

gridbag.setConstraints(lpfingsten, c);

add(lpfingsten);


//Output Pentecost

c.gridwidth = GridBagConstraints.REMAINDER;

pfingsten = new TextField(15);

pfingsten.setEditable(false);

pfingsten.setForeground(red);

gridbag.setConstraints(pfingsten, c);

add(pfingsten);

}


//Is needed, because the ActionPerformed-Class is used as inner-class

public void actionPerformed(ActionEvent l) {

}


//When the button is pushed.....action!

void knopf_actionPerformed(ActionEvent h) {


//import of the year

jahr = Integer.parseInt(eingabe.getText());


//if the year is in the allowed range...go on

if (jahr >= 1800 && jahr <= 2199) {


//at first m and n have to be calculated

if (jahr >= 1800 && jahr <= 1899) {

n = 4;

m = 23;

} else if (jahr >= 1900 && jahr <= 2099) {

n = 5;

m = 24;

} else if (jahr >= 2100 && jahr <= 2199) {

n = 6;

m = 24;

}


//Calculating Easter*********************************************************

int a = jahr % 19; // The year modulo 19 , etc

int b = jahr % 4;

int c = jahr % 7;

int d = ((19 * a) + m) % 30;

int e = ((2 * b) + (4 * c) + (6 * d) + n) % 7;


//Only the 31. March is allowed. Otherwise we go to April

if ((22 + d + e) < 32) {

ostern.setText(22 + d + e + ". March " + jahr);

merken = 1;

}

//The 26. April is substitute for the 19. April

else if ((d + e - 9) == 26) {

ostern.setText("19. April " + jahr);

merken = 2;

}

//The 25. April is substitute for the 18. April

else if (((d + e - 9) == 25) && d == 28 && e == 6 && a >= 10) {

ostern.setText("18. April " + jahr);

merken = 3;

} else {

ostern.setText(d + e - 9 + ". April " + jahr);

merken = 0;

}


//Calculating Acension ****************************************************


//if Easter is in March

if (merken == 1) {

int tag = 22 + d + e + 40 - 62;

himmel.setText(tag + ". May " + jahr);

}

//if Easter is in April

else if (merken == 2) {

int tag = 19 + 40 - 31;

himmel.setText(tag + ". May " + jahr);

} else if (merken == 3) {

int tag = 18 + 40 - 31;

himmel.setText(tag + ". May " + jahr);

} else {

if ((d + e - 9) < 23) {

int tag = d + e - 9 + 40 - 31;

himmel.setText(tag + ". May " + jahr);

} else {

int tag = d + e - 9 + 40 - 62;

himmel.setText(tag + ". June " + jahr);

}

}


//Calculating Pentecost*********************************************************

// if Easter is in March

if (merken == 1) {

int tag = 22 + d + e + 50 - 62;

pfingsten.setText(tag + ". May " + jahr);

}

//if Easter is in April

else if (merken == 2) {

int tag = 19 + 50 - 62;

pfingsten.setText(tag + ". June " + jahr);

} else if (merken == 3) {

int tag = 18 + 50 - 62;

pfingsten.setText(tag + ". June " + jahr);

} else if (merken == 0) {

if ((d + e - 9) < 13) {

int tag = d + e - 9 + 50 - 31;

pfingsten.setText(tag + ". May " + jahr);

} else {

int tag = d + e - 9 + 50 - 62;

pfingsten.setText(tag + ". June " + jahr);

}

}


} else {

//if the year is not in the allowed range...

ostern.setText("False year");

himmel.setText("only from 1800");

pfingsten.setText("to 2199");

}

}


//stopping the applet

public void stop() {

easterThread = null;

}

//destroying the applet

public void destroy() throws NullPointerException {

try {

easterThread.destroy();

} catch (NullPointerException e) {

}

}

}