import java.applet.*; import java.awt.*; public class deBroglie_wave extends Applet implements Runnable { Thread deBroglie = null; // public boolean running = false; private Font font; private Font titleFont; private FontMetrics fm; private FontMetrics titleFm; private Graphics ringGraphics; private Image ring; private Image Electron; private atom electron = new atom(); private double realRadiusScale = 52.9/50; //pm per pixel private Image Nucleus; private int[] sineWave = new int[37]; //data points for wave // private int[] nWaveSum = new int[82]; // private int pass; private double trialRadius; private int pixRadius; private double lambda; //in degrees around the orbit // private double lambdaScale = 24.748; //to get wave length in degrees! private double velocity = 0.50; private double velocityScale = 0.5; private double circumference; private double realCircumference; private double stepSize; private double stepScale = 2.0; private double waveStepSize; private boolean showWave = false; private atom wavePoint1 = new atom(); private atom wavePoint2 = new atom(); private String m_ProfPass = "Qatg1yh"; private Scrollbar radiusScrollbar = new Scrollbar(Scrollbar.HORIZONTAL,200,5,10,1000); private Label scrollbarLabel = new Label("Select radius - "); private Label scrollbarValue = new Label(""); private Button tryItButton = new Button("Show Wave"); private Panel panel = new Panel(); // Parameter names. To change a name of a parameter, you need only make // a single change. Simply modify the value of the parameter string below. //-------------------------------------------------------------------------- private final String PARAM_ProfPass = "ProfPass"; public deBroglie_wave() { } public String getAppletInfo() { return "Name: deBroglie_wave\r\n" + "Author: Dr. P. Bird, Concordia University, Montreal\r\n" + "Copyright, September 1997 \r\n" + "Created with Microsoft Visual J++ Version 1.0"; } public String[][] getParameterInfo() { String[][] info = { { PARAM_ProfPass, "String", "Debugging password" }, }; return info; } public void init() { String param; System.out.println("Entering init"); setBackground(Color.white); param = getParameter(PARAM_ProfPass); if (param != null) m_ProfPass = param; // resize(550, 350); setLayout(new BorderLayout()); panel.setLayout(new GridLayout(1,4,5,5)); panel.add(scrollbarLabel); panel.add(radiusScrollbar); panel.add(scrollbarValue); panel.add(tryItButton); add("South",panel); // font = new Font("Courier",Font.BOLD,14); // titleFont = new Font("TimesRoman",Font.BOLD,16); // titleFm = getFontMetrics(titleFont); // setFont(titleFont); setBackground(Color.white); setForeground(Color.black); ring = createImage(550,280); //Create off screen images ringGraphics = ring.getGraphics(); MediaTracker tracker = new MediaTracker(this); //Get .gifs Electron = getImage(getDocumentBase(), "electron.gif"); tracker.addImage(Electron,1); Nucleus = getImage(getDocumentBase(), "nucleus.gif"); tracker.addImage(Nucleus,2); try { tracker.waitForAll(); if (tracker.isErrorAny()) { showStatus("Error loading the images"); stop(); } } catch(InterruptedException e) { showStatus("InterruptedException (Tracker)"); stop(); } trialRadius = (double)radiusScrollbar.getValue(); atom.pathRadius1 = trialRadius/4.0; //in pixels pixRadius = (int)(atom.pathRadius1+0.5); //in pixels (fixed) atom.pathRadius2 = trialRadius/(4.0*3.0); //in pixels atom.realRadius = realRadiusScale*trialRadius; //in pm circumference = 2.0*Math.PI*trialRadius/4.0; //in pixels realCircumference = 2.0*Math.PI*atom.realRadius; //in pm stepSize = 360.0*stepScale/circumference; //in pixels // System.out.println("About to calculate Velocity"); velocity = radiusToVelocity(atom.realRadius); // System.out.println("done it!"); lambda = 2.0*Math.PI*7.27324*Math.sqrt(atom.realRadius); //in pm waveStepSize = 10.0*lambda/realCircumference; //in degrees around orbit scrollbarValue.setText ("Radius: "+ Float.toString((float)atom.realRadius)+ " pm"); // scrollbarValue.setText // ("Radius: "+ Double.toString(atom.realRadius)+ " pm"); for (int i = 0; i <=36; i++) sineWave[i]= electron.rint(20.0*Math.sin(2.0*Math.PI*((double)i/36.0))); } public void destroy() { } public void paint() { } public void update(Graphics g) { g.setColor(Color.gray); g.drawString("Copyright 1998, P.H. Bird",380,12); g.setColor(Color.black); g.drawImage(ring,0,25,null); g.setColor(Color.black); // g.drawString("Fig 2. An Electron - Wave in its Orbit",20,20); } public void start() { if (deBroglie == null) { deBroglie = new Thread(this); deBroglie.start(); // try deBroglie.setPriority(Thread.MAX_PRIORITY); catch (SecurityException e) {} } } public void stop() { if (deBroglie != null) { deBroglie.stop(); deBroglie = null; } } public void run() { double angle = 0.0; double waveAngle0; double waveAngle1; double waveAngle2; int i; while (true) { try { Thread.sleep((int)(1.0/velocity)); ringGraphics.setColor(Color.white); ringGraphics.clearRect(0,0,550,280); ringGraphics.setColor(Color.red); electron.atomPosition(angle); ringGraphics.drawOval (275-pixRadius,140-(pixRadius+1)/3, 2*pixRadius,-1+2*(pixRadius+1)/3); ringGraphics.drawOval (275-pixRadius,140-(pixRadius+1)/3, 2*pixRadius,2*(pixRadius+1)/3); ringGraphics.drawOval (275-pixRadius,140-(pixRadius+1)/3, 2*pixRadius,1+2*(pixRadius+1)/3); if (!showWave) { if (electron.ypos < 0) { ringGraphics.drawImage(Electron,electron.xpos+275-6,electron.ypos+140-5,null); ringGraphics.drawImage(Nucleus,275-6,140-5,null); } else { ringGraphics.drawImage(Nucleus,275-6,140-5,null); ringGraphics.drawImage(Electron,electron.xpos+275-6,electron.ypos+140-5,null); } } else { waveAngle0 = 0; waveAngle1 = angle; waveAngle2 = angle + waveStepSize; ringGraphics.setColor(Color.red.darker().darker()); i = 0; wavePoint1.atomPosition(waveAngle1+waveStepSize); ringGraphics.drawString ("x",wavePoint1.xpos+270,wavePoint1.ypos+175); ringGraphics.drawString ("o",wavePoint1.xpos+277,wavePoint1.ypos+178); ringGraphics.drawLine(wavePoint1.xpos+275,wavePoint1.ypos+165, wavePoint1.xpos+275,wavePoint1.ypos+150); ringGraphics.drawLine(wavePoint1.xpos+273,wavePoint1.ypos+155, wavePoint1.xpos+275,wavePoint1.ypos+150); ringGraphics.drawLine(wavePoint1.xpos+277,wavePoint1.ypos+155, wavePoint1.xpos+275,wavePoint1.ypos+150); ringGraphics.setColor(Color.blue); while (waveAngle0 <= 360.0) { ringGraphics.drawImage(Nucleus,275-6,140-5,null); waveAngle0 = waveAngle0 + waveStepSize; waveAngle1 = waveAngle1 + waveStepSize; wavePoint1.atomPosition(waveAngle1); waveAngle2 = waveAngle2 + waveStepSize; wavePoint2.atomPosition(waveAngle2); ringGraphics.drawLine(wavePoint1.xpos+275,wavePoint1.ypos+140+sineWave[i], wavePoint2.xpos+275,wavePoint2.ypos+140+sineWave[i+1]); ringGraphics.drawLine(wavePoint1.xpos+275,wavePoint1.ypos+140, wavePoint1.xpos+275,wavePoint1.ypos+140+sineWave[i]); i++; if (i > 35) i = 0; } } angle = angle + stepSize; if (angle >= 36000.0) angle = 0.0; repaint(0,0,550,310); } catch (InterruptedException e) { stop(); } } } public boolean mouseDown(Event evt, int x, int y) { return true; } public boolean mouseUp(Event evt, int x, int y) { return true; } public double radiusToVelocity(double radius) { double velocity; velocity = velocityScale/Math.sqrt(radius); return velocity; } public double radiusToWaveLength(double radius) { double waveLength; waveLength = 7.270/radiusToVelocity(radius); return waveLength; } public boolean handleEvent (Event event) { if (event.target == radiusScrollbar) { trialRadius = (double)radiusScrollbar.getValue(); atom.pathRadius1 = trialRadius/4.0; //in pixels pixRadius = (int)(atom.pathRadius1+0.5); //in pixels (fixed) atom.pathRadius2 = trialRadius/(4.0*3.0); //in pixels atom.realRadius = realRadiusScale*trialRadius; //in pm circumference = 2.0*Math.PI*trialRadius/4.0; //in pixels realCircumference = 2.0*Math.PI*atom.realRadius; //in pm stepSize = 360.0*stepScale/circumference; //in degrees velocity = radiusToVelocity(atom.realRadius); lambda = 2.0*Math.PI*7.27324*Math.sqrt(atom.realRadius); //in pm waveStepSize = 10.0*lambda/realCircumference; //in degrees around orbit scrollbarValue.setText ("Radius: "+Double_toString(atom.realRadius,3)+ " pm"); return true; } else return super.handleEvent(event); // return true; } public boolean action (Event event, Object obj) { if (event.target instanceof Button) { if (!showWave) { showWave = true; tryItButton.setLabel("Show particle"); } else { showWave = false; tryItButton.setLabel("Show wave"); } repaint(); return true; } else return super.action(event,obj); // return true; } public String Double_toString(double x, int dp) //Round to dp decimal places { int i = 0; double mul = 1; while (i < dp) { mul = mul*10.0; i = i + 1; } return Double.toString((double)(Math.rint(x*mul))/mul); } }