/* applet manufactured by J. Giesen, www.GeoAstro.de, 2006 Feb 13 */ import java.awt.*; public class map03 extends java.applet.Applet { Scrollbar scrollDec, scrollTau; double dec=23.5; // declination of the Sun double tau=0; // Hour Angle of the Sun int valueTau=45; final char deg = (char)176; Label decLabel, tauLabel; Image map; public void init() { map = getImage(getDocumentBase(),"applet/map.gif"); setLayout(new BorderLayout()); Panel p = new Panel(); p.setLayout(new GridLayout(0, 2)); scrollDec = new Scrollbar(Scrollbar.HORIZONTAL); decLabel = new Label(" Declination "+dec+deg); p.add(decLabel); p.add(scrollDec); scrollTau = new Scrollbar(Scrollbar.HORIZONTAL); tauLabel = new Label(" Noon + 0 h"); scrollTau.setValue(valueTau); p.add(tauLabel); p.add(scrollTau); add("North", p); repaint(); } public boolean handleEvent(Event e) { if (e.target instanceof Scrollbar) { if (e.target == scrollDec) { int value = ((Scrollbar)e.target).getValue(); dec=23.5-47.0*value/90.0; decLabel.setText(" Declination "+Math.round(10*dec)/10.0+deg); repaint(); return true; } if (e.target == scrollTau) { valueTau = ((Scrollbar)e.target).getValue(); tau = 360*(valueTau-45)/90.0; double t = tau/15.0; // time=hours from noon if (t>=0) tauLabel.setText(" Noon + "+Math.round(10*t)/10.0 + " h"); else tauLabel.setText(" Noon - "+Math.round(10*Math.abs(t))/10.0 + " h"); repaint(); return true; } } return true; } public void paint (Graphics g) { double K = Math.PI/180.0; // to convert degrees into arc angle double tanLat, arctanLat; int left=30; // left margin // the size of the world map is 360x180 pix. int y0=135, x0=left+180; // the center of the map is at x0, y0 int y1, y2; double longitude; g.drawImage(map,left,y0-90,this); // the size of the world map is 360x180 pix. g.setColor(Color.gray); g.drawLine(left,y0,left+360,y0); // equator g.drawLine(x0,y0-90,x0,y0+90); // Greenwich meridian g.setColor(Color.black); g.drawRect(left,y0-90,360,180); g.setFont(new Font("Helvetica",Font.PLAIN,10)); g.drawString("www.GeoAstro.de", 165,size().height-10); g.drawRect(1,1,size().width-2,size().height-2); for (int i=-180; i<=180; i++) { longitude=i+tau; tanLat = - Math.cos(longitude*K)/Math.tan(dec*K); arctanLat = Math.atan(tanLat)/K; y1 = y0-(int)Math.round(arctanLat); longitude=longitude+1; tanLat = - Math.cos(longitude*K)/Math.tan(dec*K); arctanLat = Math.atan(tanLat)/K; y2 = y0-(int)Math.round(arctanLat); g.drawLine(x0+i,y1,x0+i+1,y2); } // draw the Sun g.setColor(Color.yellow); g.fillOval(x0-(int)Math.round(tau)-5,y0-(int)Math.round(dec)-5,10,10); g.setColor(Color.red); g.drawOval(x0-(int)Math.round(tau)-5,y0-(int)Math.round(dec)-5,10,10); } }