package awtweather;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.util.*;
import java.text.SimpleDateFormat;
import javax.swing.*;
public class awtweather extends Applet implements Runnable{
wm918 w = null;
Thread runner;
SimpleDateFormat sdf = new SimpleDateFormat( "hh:mm:ss aa EEEE yyyy/MM/dd" );
String sunrise = null;
String sunset = null;
boolean isStandalone = false;
String HostName;
Panel panel1 = new Panel();
BorderLayout borderLayout1 = new BorderLayout();
BorderLayout borderLayout2 = new BorderLayout();
Panel panel2 = new Panel();
GridLayout gridLayout1 = new GridLayout();
Panel panel3 = new Panel();
Label label1 = new Label();
Label label2 = new Label();
Label label3 = new Label();
Label label4 = new Label();
TextField Temperature = new TextField();
TextField Humidity = new TextField();
TextField Barometer = new TextField();
Label label5 = new Label();
Label label6 = new Label();
Label label7 = new Label();
TextField MinMax = new TextField();
TextField Wind = new TextField();
TextField Trend = new TextField();
Label DateTime = new Label();
Label label8 = new Label();
Label label9 = new Label();
Label label10 = new Label();
TextField Rain = new TextField();
TextField Direction = new TextField();
TextField Prediction = new TextField();
Label label11 = new Label();
Label label12 = new Label();
Label label13 = new Label();
TextField SunRise = new TextField();
TextField textField2 = new TextField();
TextField SunSet = new TextField();
/**Get a parameter value*/
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
/**Construct the applet*/
public awtweather() {
}
/**Initialize the applet*/
public void init() {
try {
HostName = this.getParameter("HostName", "");
}
catch(Exception e) {
e.printStackTrace();
}
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
panel1.setLayout(borderLayout1);
this.setLayout(borderLayout2);
panel2.setLayout(gridLayout1);
gridLayout1.setRows(8);
gridLayout1.setColumns(3);
label1.setBackground(Color.white);
label1.setFont(new java.awt.Font("Dialog", 1, 24));
label1.setText("Holiwill Weather");
label2.setBackground(Color.white);
label2.setFont(new java.awt.Font("Dialog", 1, 16));
label2.setText("Temperature");
label3.setBackground(Color.white);
label3.setFont(new java.awt.Font("Dialog", 1, 16));
label3.setText("Humidity");
label4.setBackground(Color.white);
label4.setFont(new java.awt.Font("Dialog", 1, 16));
label4.setText("Barometer");
Temperature.setEditable(false);
Temperature.setFont(new java.awt.Font("Dialog", 0, 24));
Temperature.setForeground(Color.blue);
Temperature.setText("0.0C");
Humidity.setEditable(false);
Humidity.setFont(new java.awt.Font("Dialog", 0, 24));
Humidity.setForeground(Color.blue);
Humidity.setText("100%");
Barometer.setEditable(false);
Barometer.setFont(new java.awt.Font("Dialog", 0, 24));
Barometer.setForeground(Color.blue);
Barometer.setText("1111mb");
label5.setBackground(Color.white);
label5.setFont(new java.awt.Font("Dialog", 1, 16));
label5.setText("Min/Max");
label6.setBackground(Color.white);
label6.setFont(new java.awt.Font("Dialog", 1, 16));
label6.setText("Wind");
label7.setBackground(Color.white);
label7.setFont(new java.awt.Font("Dialog", 1, 16));
label7.setText("Trend");
MinMax.setEditable(false);
MinMax.setFont(new java.awt.Font("Dialog", 0, 20));
MinMax.setForeground(Color.blue);
MinMax.setText("0.0C/0.0C");
Wind.setEditable(false);
Wind.setFont(new java.awt.Font("Dialog", 0, 24));
Wind.setForeground(Color.blue);
Wind.setText("0.0kph");
Trend.setEditable(false);
Trend.setFont(new java.awt.Font("Dialog", 0, 24));
Trend.setForeground(Color.blue);
Trend.setText("Steady");
DateTime.setBackground(Color.white);
DateTime.setFont(new java.awt.Font("Dialog", 1, 24));
DateTime.setForeground(Color.blue);
DateTime.setText(" ");
label8.setBackground(Color.white);
label8.setFont(new java.awt.Font("Dialog", 1, 16));
label8.setText("Rain Today");
label9.setBackground(Color.white);
label9.setFont(new java.awt.Font("Dialog", 1, 16));
label9.setText("Direction");
label10.setBackground(Color.white);
label10.setFont(new java.awt.Font("Dialog", 1, 16));
label10.setText("24hr Prediction");
Rain.setEditable(false);
Rain.setFont(new java.awt.Font("Dialog", 0, 24));
Rain.setForeground(Color.blue);
Rain.setText("0mm");
Direction.setEditable(false);
Direction.setFont(new java.awt.Font("Dialog", 0, 24));
Direction.setForeground(Color.blue);
Direction.setText("N");
Prediction.setEditable(false);
Prediction.setFont(new java.awt.Font("Dialog", 0, 24));
Prediction.setForeground(Color.blue);
Prediction.setText("Sunny");
this.setBackground(Color.white);
label11.setBackground(Color.white);
label11.setFont(new java.awt.Font("Dialog", 1, 16));
label11.setText("Sun Rise");
label13.setBackground(Color.white);
label13.setFont(new java.awt.Font("Dialog", 1, 16));
label13.setText("Sun Set");
SunRise.setFont(new java.awt.Font("Dialog", 0, 24));
SunRise.setForeground(Color.blue);
SunRise.setText("00:00");
textField2.setEditable(false);
textField2.setFont(new java.awt.Font("Dialog", 0, 24));
textField2.setVisible(false);
SunSet.setFont(new java.awt.Font("Dialog", 0, 24));
SunSet.setForeground(Color.blue);
SunSet.setText("00:00");
panel2.setBackground(Color.white);
panel1.setBackground(Color.white);
label12.setBackground(Color.white);
this.add(panel1, BorderLayout.CENTER);
panel1.add(label1, BorderLayout.NORTH);
panel1.add(panel2, BorderLayout.CENTER);
panel2.add(label2, null);
panel2.add(label3, null);
panel2.add(label4, null);
panel2.add(Temperature, null);
panel2.add(Humidity, null);
panel2.add(Barometer, null);
panel2.add(label5, null);
panel2.add(label6, null);
panel2.add(label7, null);
panel2.add(MinMax, null);
panel2.add(Wind, null);
panel2.add(Trend, null);
panel2.add(label8, null);
panel2.add(label9, null);
panel2.add(label10, null);
panel2.add(Rain, null);
panel2.add(Direction, null);
panel2.add(Prediction, null);
panel2.add(label11, null);
panel2.add(label12, null);
panel2.add(label13, null);
panel2.add(SunRise, null);
panel2.add(textField2, null);
panel2.add(SunSet, null);
panel1.add(DateTime, BorderLayout.SOUTH);
}
/**Start the applet*/
public void start() {
if (runner == null)
{
runner = new Thread(this);
runner.start();
}
}
public void run()
{
w = new wm918(HostName, 2);
w.start();
//=====
SunRise s = new SunRise();
/* Observation place - Endeavour Hills*/
s.longitude = 145.0163;
s.latitude = -37.9733;
/* set time zone offset (min) - EDT */
s.tzOffset = 11 * 60;
Date now = new Date();
s.year = now.getYear() + 1900;
s.month = now.getMonth() + 1;
s.day = now.getDate();
if (now.getHours()*60 + now.getMinutes() + now.getTimezoneOffset() + s.tzOffset > 60 * 24)
s.day++;
double jd = s.getJulianDay(s.year, s.month, s.day);
s.getDate(jd);
//System.out.println(s.year + "-" + s.month + "-" + s.day + " ");
s.caliculate();
if (s.sunFlag == false)
{
if (s.sunriseHour < 0)
System.out.println("The Sun does not appear all the day.");
else
if (s.sunsetHour < 0)
{
/* sunrise only */
sunrise = s.sunriseHour + ":" + s.sunriseMin;
sunset = "";
}
else
{