// Hydrogen.java (for JDK 1.0) // /************************************************************************* * * * Copyright (c) 1998 Greg W. Anderson * * * * This program is free software. You can copy, modify, or redistribute * * this software under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version, provided that both * * the above copyright notice appears in all copies and that this * * permission notice appear in any supporting documentation. * * * * This software is provided "as is" in the hope that it will be useful, * * but WITHOUT any expressed or implied warranty of merchantability or * * fitness for any particular purpose. * * See the GNU General Public License for more details. * * Your milage may vary. * *************************************************************************/ // Modification History // Date Initials Change // 2/01/98 GWA Initial release // Abstract: /* * * @author Greg Anderson * @version 0.1, 21 Feb 1998 */ import java.awt.Graphics; import java.awt.*; import java.applet.*; import java.lang.Math; public class HydrogenLevels extends java.applet.Applet { HydrogenCanvas c; HydrogenControls controls; HydrogenLevelsBanner banner; Label appletName = new Label ("The Virtual Physics Laboratory"); Label department = new Label ("Department of Physics and Astronomy"); Label university = new Label ("Northwestern University"); public void init(){ setLayout(new BorderLayout()); banner = new HydrogenLevelsBanner (2,2); banner.add("Center",department); banner.add(appletName); banner.add("Center",university); banner.add("South", new Label ("G.Anderson")); add ("North",banner); c = new HydrogenCanvas(); add("Center",c); add("South", controls = new HydrogenControls(c)); } public void start(){ controls.enable(); } public void stop(){ controls.disable(); } public boolean handleEvent(Event e){ if (e.id == Event.WINDOW_DESTROY){ System.exit(0); } return false; } public String getAppletInfo(){ return "HydrogenLevels by Greg Anderson"; } } class HydrogenCanvas extends Canvas { public boolean displayLabels = true; public boolean trueColor = false; public boolean displayBalmer = true; public boolean displayPaschen = true; public boolean displayLyman = true; public boolean displayBrackett = true; public boolean displayElectricDipole = true; public boolean displayMagneticDipole = true; public boolean displayElectricQuadrupole = true; public boolean allowedTransition = true; public int displayModel = 0; Color darkMagenta = new Color(150,0,150); Color darkdarkGray = new Color(32,32,32); int leftSpace = 30; int rightSpace = 10; int hSpace = 10; int topMargin = 40; int bottomMargin = 10; int plotWidth; int halfWidth; int plotHeight; int halfHeight; int levelSpacing; int Z; int nmax = 8; // The number of radial orbitals displayed int lmax = 7; // The number of angular momentum states displayed public void initSizes(){ plotWidth = size().width - leftSpace -rightSpace; halfWidth = plotWidth/2; plotHeight = size().height - bottomMargin; halfHeight = plotHeight/2; levelSpacing = plotWidth/(lmax+1); Z = 1; // the number of protons } double Energy(int n){ return Energy(n,0); } double Energy(int n, int j){ double E0; double alpha = 1./137.; double En; double dE; // note, this fine structure is too small to see here E0 = size().height - topMargin - bottomMargin; // 13.6 eV En = E0*Math.pow(Z,2)/Math.pow(n,2); dE = En*( Math.pow(Z*alpha/n,2)*(n/(j+0.5) - 3./4.) ); En = En + dE; return En; } void drawLevel(Graphics g, int n, int l){ // and (n,l) level g.drawLine(leftSpace + l*levelSpacing + hSpace/2, topMargin + (int) Energy(n), leftSpace + (l+1)*levelSpacing - hSpace/2, topMargin + (int) Energy(n)); } void drawLevel(Graphics g, int n){ // Bohr levels only g.drawLine(leftSpace + hSpace/2, topMargin + (int) Energy(n), leftSpace + plotWidth - hSpace/2, topMargin + (int) Energy(n)); } public void displayTransition(Graphics g, int ni, int li, int nf, int lf){ if(trueColor){ g.setColor(Color.gray); if(ni==3 && nf ==2)g.setColor(Color.red); // Balmer Red = 3->2 if(ni==4 && nf ==2)g.setColor(Color.blue); // Balmer blue = 4->2 if(ni==5 && nf ==2)g.setColor(darkMagenta); // Balmer violet = 5->2 } // try to keep displayed lines from crossing if (lf <= li){ g.drawLine(leftSpace - hSpace/2 - 5*ni + (li+1)*levelSpacing, topMargin + (int) Energy(ni), leftSpace - hSpace/2 - 5*ni + (lf+1)*levelSpacing, topMargin + (int) Energy(nf)); } else{ g.drawLine(leftSpace + hSpace/2 + 5*ni + li*levelSpacing, topMargin + (int) Energy(ni), leftSpace + hSpace/2 + 5*ni + lf*levelSpacing, topMargin + (int) Energy(nf)); } } public boolean IsAllowedTransition(int li, int ji, int lf, int jf){ // ED (dl = +/-1 ), (dj = 0,+/-1 , ! 0->0) if(displayElectricDipole){ if ( Math.abs(li-lf)==1 && Math.abs(ji-jf)==1){ return true; } if ( Math.abs(li-lf)==1 && Math.abs(ji-jf)==0 && jf !=0){ return true; } } // MD (dl = 0), (dj = 0,+/- 1 !0->0) if(displayMagneticDipole){ } // EQ (dl = 0,+/-2), (no l= 0->0) if(displayElectricQuadrupole){} return allowedTransition; } public void displaySeries(Graphics g, int nf, int lf){ if(displayModel ==0){ for (int ni=nf+1; ni