// de_Broglie wavelength calculator. (Java 1.1 or later version) import java.awt.*; import java.awt.event.*; import java.applet.*; import java.lang.String.*; import java.lang.Double.*; public class de_Broglie extends Applet implements ActionListener { TextField massField, velocityField; String message = ""; // String containing system messages double mass; // Mass of the particle double velocity; // Velocity of the particle double momentum; // Momentum of the particle double plancks_constant = 6.625E-34; // Planck's Constant double wavelength; // de Broglie wavelength of the particle public void init() { Label massLabel = new Label( "mass(10^-33g): ", Label.RIGHT ); Label velocityLabel = new Label( "velocity(m/sec): ", Label.RIGHT ); massField = new TextField( 12 ); velocityField = new TextField( 12 ); // Add controls add( massLabel ); add( massField ); add( velocityLabel ); add( velocityField ); // Register ActionListeners to receive action events. massField.addActionListener( this ); velocityField.addActionListener( this ); } // ActionListeners. public void actionPerformed( ActionEvent ae ) { repaint(); } public void paint( Graphics g ) { message = ""; try { mass = (10E-34) * (double)Long.parseLong( massField.getText() ); } catch( NumberFormatException exceptionText ) { message = "\"mass\" field must contain a number: " + exceptionText; mass = 1.0; } try { velocity = 1 * (double)Long.parseLong( velocityField.getText() ); } catch( NumberFormatException exceptionText ) { message = "\"velocity\" field must contain a number: " + exceptionText; velocity = 1.0; } // Calculate momentum for a particle momentum = mass * velocity; // Calculate de Broglie wavelength for a particle wavelength = plancks_constant / momentum; g.drawString( "mass(g): " + mass, 6 ,200 ); g.drawString( "velocity(m/sec): " + velocity, 6, 225 ); g.drawString( "momentum(g*m/sec): " + momentum, 6, 250 ); g.drawString( "Planck's Constant: " + plancks_constant, 6, 275 ); g.drawString( "wavelength(Angstroms) = " + (wavelength * 10E9), 6, 300 ); g.drawString( "Message: " + message, 6, 325 ); } // main() is the entry point when called as an application. // main() is not used when run as an applet. public static void main ( String args[] ) { Frame mainWindow = new Frame ( "de_Broglie" ); de_Broglie application = new de_Broglie (); mainWindow.setSize ( 400, 400 ); mainWindow.add ( "Center", application ); mainWindow.show (); application.init(); } }