Sample JAVA program to visualize the electron's orbit of the Water (H2O) of Bohr model.

Back to the water page
Top page ( correct Bohr model including the two electron atom )

This program is a little long. So if you copy and paste the below program source code into a text editor, you can easily compile and run this.
This program's class file name is H2OW, so save this text editor as "H2OW.java", and compile it.

In this program, the oxygen nucleus (gray color) is at (9285.6 MM, 12499 MM, 7857 MM).
And O-H length and H-H lengths are 9584 MM and 15150 MM, respectively.
Here we use the new units, ( 1 MM = 10-14 meter, 1 SS = 10-21 second, 1 MM/SS = 107 m/s ).
Each coordinate of electrons (+X (MM), +Y (MM), +Z (MM)) in the textbox means "relative" position from this nucleus.
(e0-e5 are from the oxygen (O) nucleus, e6 is from hydrogen 0 (H0) nucleus, and e7 is from the H1 nucleus.)
"nuc (MM)" means the distance between these nuclei and each electron.
V (eV) and T (eV) are the potential and kinetic energies of each electron.
"VX: VY: VZ" means the ratio of each component of the electron's initial velocity vector.
So, (VX: VY; VZ)=(100:100;0) is the same as (VX: VY: VZ) = (10:10:0).
When you choose the number (= wn) of de Broglie's waves (0.1 -- 2.0) in the scrollbar, and click "orbit" button, this program starts to compute the electron's orbit until de Broglie's waves contained in the orbit becomes wn.
And then, if you click "retur" button, all electrons return to the starting points.
When you click "initi" button, all values of coordinates and velocities are initialized to the first ones.
You can change the coordinates and the direction of velocity vector freely.
(Enter the values into the textbox, and press the Enter key.)
And when you enter the value a (MM) into the textbox below "radiu" button and click this button, the size (radius) of the six electrons' octahedron changes as shown in Fig.1.
When you choose the electron's numbers (el0-el7) in the scrollobars in the last row, enter the value (eV) into the textbox next to them, and press the Enter key, the kinetic energy of this value is transferred between two designated electrons.


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Scanner;
public class H2OW extends JPanel     // visualization of H2O(water)
 {
  public static void main(String arg[])
 {
   JFrame frame = new JFrame("H2O (water)");
   J2DPanel j2dpanel = new J2DPanel();
   frame.getContentPane().add(j2dpanel); frame.setSize(1180,700);
   frame.setVisible(true); frame.setBackground(Color.black);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  // oxygen only
  }
  }
 class J2DPanel extends JPanel implements AdjustmentListener, ActionListener
  {
    
    double pai=3.141592653589793; double epsi=8.85418781787346e-12;
   double h=6.62606896e-34; double elc=1.60217653e-19;
   double me=9.1093826e-31;  double suh=5200.0*5200.0; // suh=(Bohr radius)^2
 
    JTextField elp[][]=new JTextField[8][9]; JTextField impho[]=new JTextField[2];  
    JTextField mmpho[]=new JTextField[3];    // elp=each electron's parameter
    
    JButton b1=new JButton("orbit"); JButton b2=new JButton("retur");
    JButton b3=new JButton("radiu");  JButton b4=new JButton("initi");
    
    String ope[]={"0.1","0.3","0.5","0.7","0.9","1.1","1.3","1.5","1.7","1.9","2.0"};
    String ompe[]={"el0","el1","el2","el3","el4","el5","el6","el7"};
    String oppe[]={"el0","el1","el2","el3","el4","el5","el6","el7"};
                                            // scrollbar
    JComboBox coom=new JComboBox(ope); JComboBox coom2=new JComboBox(ompe);
    JComboBox coom3=new JComboBox(oppe);
    
    double rtw=Math.sqrt(2); double rth=Math.sqrt(3); double rsi=Math.sqrt(6); double rfi=Math.sqrt(5);
    int marki[]={0,0,0,0,0,0,0};  double hpr[][]=new double[8][9]; double hhpr[][]=new double[8][9];
                           // marki=marking, hpr(hhpr)=parameters of each electron
                                        // nux=three nuclear coordinates and charge
                                  // nux[0][]=O nuc, nux[1][]=H0 nuc, nux[2][]=H1 nuc
    double nux[][]={{9285.64, 12499.9, 7857.08, 6.0},
    {5870.79/rth+9285.64, 12499.9-7575.40, (5870.79*rtw)/rth+7857.08, 1.0},
    {5870.79/rth+9285.64, 12499.90+7575.40,(5870.79*rtw)/rth+7857.08, 1.0}}; 
                                                     // te1=initial conditions of each electron
    double te1[][]={{1775.0,-3376.05, 2551.65,64.32,866,505,0}, {1875.0,2947.59,2951.62, 65.69, -866,500,0}, 
    {-1875.0,3247.59,-2651.66, 64.7, -866,-475.3,0}, {-1875.0,-3247.6,-2651.66, 63.11, 866,-484.4,0}, 
    {3700.0, 0, -2651.66, 64.6, 89.0,999,0}, {-3700.0, 0, 2651.62, 64.66, -20, -999,0}, 
    {-2700.0, 1100.0, 3705.59, 15.2, 10,35,-42}, {1947.5,-400.0,-4400.0, 13.7, 0, 67, 5}};


  public J2DPanel()
 {
  setBackground(Color.black);
  JPanel p=new JPanel();
  p.setLayout(new GridLayout(10,11));
  String vv,zww; int aaa=0; 
                               //elp[0-7][0-2]=each electron's relative coordinate from nucleus
  for (int el=0; el <=7; el++) {   
  for (int pos=0; pos <=2; pos++) {
  elp[el][pos]=new JTextField(7); elp[el][pos].addActionListener(this);
  hpr[el][pos]=0.0; hhpr[el][pos]=0.0;      // initialization of hpr,hhpr
  }}
                                    //elp[0-7][3-8]=other parameters of electrons
   for (int el=0; el <=7; el++) {
  for (int pos=3; pos <=8; pos++) {
  elp[el][pos]=new JTextField(7);     //elp[0-7][6-8]=velocity vector
  if (pos > 5) {elp[el][pos].addActionListener(this);}
  hpr[el][pos]=0.0; hhpr[el][pos]=0.0;
  }}

   for (int el=0; el <=2; el++) {
    mmpho[el]=new JTextField(7);
   }
  impho[0]=new JTextField(7);impho[0].addActionListener(this);
  impho[1]=new JTextField(7);
                                        // layout
  String sihy[]={"Electron","+ X (MM)","+ Y (MM)","+ Z (MM)","nuc (MM)",
  "V (eV)","T (eV)","VX :","VY :","VZ :"," --- "};
   for (int jou=0; jou <=10; jou++) {
   p.add(new Label(sihy[jou]));
   }
                                    // row of each electron 
  p.add(new Label("ele "+0+" "));
  for (int jou=0; jou <=8; jou++) { p.add(elp[0][jou]);}  p.add(b4);
  p.add(new Label("ele "+1+" "));
  for (int jou=0; jou <=8; jou++) { p.add(elp[1][jou]);}  p.add(b3);
  p.add(new Label("ele "+2+" "));
  for (int jou=0; jou <=8; jou++) { p.add(elp[2][jou]);}  p.add(impho[1]);
  p.add(new Label("ele "+3+" "));
  for (int jou=0; jou <=8; jou++) { p.add(elp[3][jou]);}  p.add(new Label(" --- "));

  for (int el=4; el <=7; el++) {
  p.add(new Label("ele "+el+" "));
  for (int jou=0; jou <=8; jou++) { p.add(elp[el][jou]);}
  p.add(new Label(" --- "));
  }
                                 // last row
   p.add(new Label("O nucleus")); 
    for (int jou=0; jou <=2; jou++) { p.add(mmpho[jou]);}
   p.add(b1); p.add(coom); p.add(b2); p.add(impho[0]); 
   p.add(coom2); p.add(new Label(" to ")); p.add(coom3);
   
       
         
  coom.setSelectedItem("1.9"); coom2.setSelectedItem("el0"); coom3.setSelectedItem("el1");
             
  b1.addActionListener(this);b2.addActionListener(this);
  b3.addActionListener(this);b4.addActionListener(this);

  add(p,"South");
  
  impho[0].setText("0.1"); impho[1].setText("3750.00");
                                       // set initial condition of each electron
   for (int el=0; el <=7; el++) {
   double nnuc=Math.sqrt(te1[el][0]*te1[el][0]+te1[el][1]*te1[el][1]+te1[el][2]*te1[el][2]);
   aaa=(int)(nnuc*100); nnuc=aaa/100.0; 
   elp[el][3].setText(Double.toString(nnuc)); // show distance between nuclei and electrons 
    for (int jou=0; jou <=2; jou++) {
    hpr[el][jou]=te1[el][jou]; 
    if (el < 6) {hpr[el][jou]=hpr[el][jou]+nux[0][jou];}
     if (el==6) {hpr[el][jou]=hpr[el][jou]+nux[1][jou];}
      if (el==7) {hpr[el][jou]=hpr[el][jou]+nux[2][jou];}
    hhpr[el][jou]=hpr[el][jou]; elp[el][jou].setText(Double.toString(te1[el][jou]));}
    for (int jou=3; jou <=6; jou++) {
    hpr[el][jou+2]=te1[el][jou]; hhpr[el][jou+2]=hpr[el][jou+2]; 
    elp[el][jou+2].setText(Double.toString(te1[el][jou])); }
   }
  }     // public J2DPanel() end
 
  
  public void adjustmentValueChanged(AdjustmentEvent e) { 
  repaint();  }

  public void actionPerformed(ActionEvent e) {  // change textfield or put button
    String ss;
    int RR, RRR; double Rf1,Rf2,Rf3,Rf4; int teis=0;

    for (int ett=0; ett <=7; ett++) {    // when electron's positions change
    for (int sws=0; sws <=2; sws++) {          
    if (e.getSource()==elp[ett][sws] && marki[2] !=2) {marki[4]=1;   
    
    ss=elp[ett][sws].getText(); Rf1=Double.parseDouble(ss); Rf2=0.0;  
                                      // change relative coordinate to absolute coordinate
   if (ett < 6) {Rf2=Rf1+nux[0][sws];}     
   if (ett==6) {Rf2=Rf1+nux[1][sws];}
   if (ett==7) {Rf2=Rf1+nux[2][sws];}
    Rf3=Rf2/71.428;                 // change MM to pixel
                               // upper and lower limits of coordinates
    if (Rf3 > 319 && sws==0) {Rf3=319; Rf2=Rf3*71.428; teis=1;}
    if (Rf3 > 349 && sws==2) {Rf3=349; Rf2=Rf3*71.428; teis=1;}
    if (Rf3 > 349 && sws==1) {Rf3=349; Rf2=Rf3*71.428; teis=1;}
    if (Rf3 < 1) {Rf3=1; Rf2=Rf3*71.428; teis=1;}
    hpr[ett][sws]=Rf2; hhpr[ett][sws]=Rf2;
   if (ett < 6) {Rf1=Rf2-nux[0][sws];}     
   if (ett==6) {Rf1=Rf2-nux[1][sws];}
   if (ett==7) {Rf1=Rf2-nux[2][sws];}
   if (teis==1) {RR=(int)(100*Rf1); Rf1=RR/100.0;elp[ett][sws].setText(Double.toString(Rf1));}
    }}}
                                      // marki[2] becomes 2 only after orbit calculation
   if (e.getSource() == b1 && marki[2] !=2 ) {marki[0]=1;} // put "orbit" button
   if (e.getSource() == b2 && marki[2]==2 ) {marki[1]=1;}   // put "return" button
  
   if (e.getSource() == b4 && marki[2] !=2) {   // put "initial" button
    marki[3]=1; 
    for (int el=0; el <=7; el++) {
    for (int jou=0; jou <=2; jou++) {
    hpr[el][jou]=te1[el][jou]; 
    if (el < 6) {hpr[el][jou]=hpr[el][jou]+nux[0][jou];}
     if (el==6) {hpr[el][jou]=hpr[el][jou]+nux[1][jou];}
      if (el==7) {hpr[el][jou]=hpr[el][jou]+nux[2][jou];}
    hhpr[el][jou]=hpr[el][jou]; elp[el][jou].setText(Double.toString(te1[el][jou]));}
    for (int jou=3; jou <=6; jou++) {
    hpr[el][jou+2]=te1[el][jou]; hhpr[el][jou+2]=hpr[el][jou+2]; 
    elp[el][jou+2].setText(Double.toString(te1[el][jou])); }
      }
     }           

   if (e.getSource()==impho[0] && marki[2] !=2) {marki[5]=1;}
   if (e.getSource()==b3 && marki[2] !=2 ) {
   marki[4]=1; ss=impho[1].getText(); Rf1=Double.parseDouble(ss); 
   Rf2=Rf1/rtw; Rf3=(rth*Rf1)/2.0; Rf4=Rf1/2.0;
  hpr[0][0]=Rf4+nux[0][0]; hpr[1][0]=hpr[0][0]; hpr[2][0]=nux[0][0]-Rf4; hpr[3][0]=hpr[2][0];
  hpr[0][1]=nux[0][1]-Rf3; hpr[3][1]=hpr[0][1]; hpr[1][1]=nux[0][1]+Rf3; hpr[2][1]=hpr[1][1];
  hpr[4][0]=nux[0][0]+Rf1; hpr[5][0]=nux[0][0]-Rf1; hpr[4][1]=nux[0][1]; hpr[5][1]=hpr[4][1];
  hpr[0][2]=nux[0][2]+Rf2; hpr[1][2]=hpr[0][2]; hpr[5][2]=hpr[0][2]; 
  hpr[2][2]=nux[0][2]-Rf2; hpr[3][2]=hpr[2][2]; hpr[4][2]=hpr[2][2];
    for (int ett=0; ett <=5; ett++) {
    for (int sws=0; sws <=2; sws++) {          // calculate the values to two decimal places
   RR=(int)(100*(hpr[ett][sws]-nux[0][sws])); Rf1=RR/100.0;
   elp[ett][sws].setText(Double.toString(Rf1)); hhpr[ett][sws]=hpr[ett][sws];
   }}
   }
   repaint();
  }

  public void update(Graphics g)
 {
  paint(g);
 }
 public void paintComponent(Graphics g)
 {
   

  double kro,krr,krk,pot,pota,potb,gx,gy,gz,ggx,ggy,ggz,ttav,toav;
  int ex,ey,ez,xk,yk,zk; String ww,pyw;
  double rhp[][]= {{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};
  double mmp[]={0,0,0};  
  
   if (marki[2] !=2 && marki[3] !=1) {       // get values from textfields
   for (int ett=0; ett <=7; ett++) {
    for (int sws=0; sws <=2; sws++) {
    ww=elp[ett][sws].getText(); hpr[ett][sws]=Double.parseDouble(ww);
   if (ett < 6) {hpr[ett][sws]=hpr[ett][sws]+nux[0][sws];}
   if (ett==6) {hpr[ett][sws]=hpr[ett][sws]+nux[1][sws];}
   if (ett==7) {hpr[ett][sws]=hpr[ett][sws]+nux[2][sws];} 
   hhpr[ett][sws]=hpr[ett][sws]; ww=elp[ett][sws+6].getText();
   hpr[ett][sws+6]=Double.parseDouble(ww);  hhpr[ett][sws+6]=hpr[ett][sws+6];
    }} }
  
   if (marki[1]==1) {              // return to the condition before orbiting
    for (int qz=0; qz <=7; qz++) {
   for (int ka=0; ka <=8; ka++)   { 
   hhpr[qz][ka]=hpr[qz][ka]; gx=hpr[qz][ka];
    ex=(int)(100*hpr[qz][ka]); gx=ex/100.0;
   if (qz < 6 && ka < 3) {ex=(int)(100*(hpr[qz][ka]-nux[0][ka])); gx=ex/100.0; }
   if (qz==6 && ka < 3) {ex=(int)(100*(hpr[qz][ka]-nux[1][ka])); gx=ex/100.0; }
   if (qz==7 && ka < 3) {ex=(int)(100*(hpr[qz][ka]-nux[2][ka])); gx=ex/100.0; }
   elp[qz][ka].setText(Double.toString(gx));
   marki[1]=0; marki[2]=0;
   }}}
  
   if (marki[2] !=2) {

   toav=0.0;                // toav=total potential energy
   for (int yp=0; yp <=7; yp++) {   
   for (int kj=0; kj <=7; kj++) {    // interaction between electrons
   if (yp < kj ) {
                                 // kro= distance between two electrons (yp and kj)
   kro=Math.sqrt((hpr[yp][0]-hpr[kj][0])*(hpr[yp][0]-hpr[kj][0])+
   (hpr[yp][1]-hpr[kj][1])*(hpr[yp][1]-hpr[kj][1])+
   (hpr[yp][2]-hpr[kj][2])*(hpr[yp][2]-hpr[kj][2]));
   if (kro==0) {kro=5000.0;}
                                 // pot=potential energy between electrons
   pot=(elc*elc*6.241509e18)/(4*pai*epsi*kro*1.0e-14); 
                                // rhp[][0]=potential energy of each electron
   rhp[yp][0]=rhp[yp][0]+pot/2;  rhp[kj][0]=rhp[kj][0]+pot/2;
   toav=toav+pot;
   } } }
  
   for (int rv=0; rv <=7; rv++) {         // kro=distance between electron and O nucleus
   kro=Math.sqrt((hpr[rv][0]-nux[0][0])*(hpr[rv][0]-nux[0][0])+
   (hpr[rv][1]-nux[0][1])*(hpr[rv][1]-nux[0][1])+
   (hpr[rv][2]-nux[0][2])*(hpr[rv][2]-nux[0][2])); 
    if (kro == 0) {kro=5000.0;}
    pot =-6.0/kro;                      // show kro (to two decimal place) in ele 0-5
   if (rv < 6) {ex=(int)(100*kro); gx=ex/100.0; elp[rv][3].setText(Double.toString(gx));}

                                       // krr=distance between electron and H0 nucleus
   krr=Math.sqrt((hpr[rv][0]-nux[1][0])*(hpr[rv][0]-nux[1][0])+
    (hpr[rv][1]-nux[1][1])*(hpr[rv][1]-nux[1][1])+
    (hpr[rv][2]-nux[1][2])*(hpr[rv][2]-nux[1][2]));
   if (krr ==0) {krr=5000.0;}
    pota=-1.0/krr;                   // show krr (to two decimal places) in ele 6
   if (rv==6) {ex=(int)(100*krr); gx=ex/100.0; elp[rv][3].setText(Double.toString(gx));}

                                     // krk=distance between electron and H1 nucleus
   krk=Math.sqrt((hpr[rv][0]-nux[2][0])*(hpr[rv][0]-nux[2][0])+
   (hpr[rv][1]-nux[2][1])*(hpr[rv][1]-nux[2][1])+
   (hpr[rv][2]-nux[2][2])*(hpr[rv][2]-nux[2][2]));
   if (krk ==0) {krk=5000.0;} 
    potb=-1.0/krk;                  // show krk (to two decimal places)  in ele 7
   if (rv==7) {ex=(int)(100*krk); gx=ex/100.0; elp[rv][3].setText(Double.toString(gx));}

                                // ttav=potential energy between one electron and three nuclei
   ttav= (elc*elc*6.241509e18*(pot+pota+potb))/(4*pai*epsi*1.0e-14);
   
   rhp[rv][0]=rhp[rv][0]+ttav;  toav=toav+ttav;  //rhp[rv][1]=interaction with other nuclei
   if (rv < 6) {rhp[rv][1]=(elc*elc*6.241509e18*(pota+potb))/(4*pai*epsi*1.0e-14);}
   if (rv > 5) {rhp[rv][1]=(elc*elc*6.241509e18*(pot))/(4*pai*epsi*1.0e-14);}
   
   for (int kj=0; kj <=2; kj++) {
   ggx=(suh*6*(hpr[rv][kj]-nux[0][kj]))/(kro*kro*kro); // ggx=force between electron and O nucleus

                                         // mmp[0-2]=each component of force acting on O nucleus
   mmp[kj]=mmp[kj]+ggx; 
   }}

   gx=0.0; 
  for (int rv=0; rv <=7; rv++) { gx=gx+rhp[rv][0]; }
  
                                  // kro=distance between O and H0 nuclei
  kro=Math.sqrt((nux[0][0]-nux[1][0])*(nux[0][0]-nux[1][0])+
  (nux[0][1]-nux[1][1])*(nux[0][1]-nux[1][1])+
   (nux[0][2]-nux[1][2])*(nux[0][2]-nux[1][2]));
                                        // forces between O and H0 nuclei
  ggx=(suh*6*(nux[1][0]-nux[0][0]))/(kro*kro*kro); ggy=(suh*6*(nux[1][1]-nux[0][1]))/(kro*kro*kro); 
  ggz=(suh*6*(nux[1][2]-nux[0][2]))/(kro*kro*kro); 
   mmp[0]=mmp[0]-ggx; mmp[1]=mmp[1]-ggy; mmp[2]=mmp[2]-ggz;
                                       // krr=distance between O and H1 nuclei
   krr=Math.sqrt((nux[0][0]-nux[2][0])*(nux[0][0]-nux[2][0])+
   (nux[0][1]-nux[2][1])*(nux[0][1]-nux[2][1])+
   (nux[0][2]-nux[2][2])*(nux[0][2]-nux[2][2]));
                                      // forces between O and H1 nuclei
  ggx=(suh*6*(nux[2][0]-nux[0][0]))/(krr*krr*krr); ggy=(suh*6*(nux[2][1]-nux[0][1]))/(krr*krr*krr); 
  ggz=(suh*6*(nux[2][2]-nux[0][2]))/(krr*krr*krr);
   mmp[0]=mmp[0]-ggx; mmp[1]=mmp[1]-ggy; mmp[2]=mmp[2]-ggz;

  for (int rv=0; rv <=2; rv++) {           // show forces acting on O nucleus
   ex=(int)(1000*mmp[rv]); ww=Integer.toString(ex);
   pyw="FX ";  if (rv==1) {pyw="FY ";}  if (rv==2) {pyw="FZ ";}
   mmpho[rv].setText(pyw+ww);
   }

    krk=(nux[2][1]-nux[1][1]);       // distance between two H nuclei
 
                                     // pot=total potential energy
   pot=toav+(elc*elc*6.241509e18*((6/kro)+(6/krr)+(1/krk)))/(4*pai*epsi*1.0e-14);
                            // distribute repulsive potential energy between nuclei to each electron
   double ohkan=(elc*elc*6.241509e18*((6/kro)+(6/krr)))/(4*pai*epsi*1.0e-14);
   double hhkan=(elc*elc*6.241509e18)/(4*pai*epsi*1.0e-14*krk);
  double hiwa=0.0;
  for (int rv=0; rv <=7; rv++) { hiwa=hiwa+rhp[rv][1]; }
  for (int rv=0; rv <=7; rv++) {
  rhp[rv][1]=rhp[rv][0]+(ohkan*rhp[rv][1])/hiwa;
  if (rv > 5) {rhp[rv][1]=rhp[rv][1]+hhkan/2.0;}
   }
   
  for (int rv=0; rv <=7; rv++) {      // calculate each V(eV) to two decimal places
  ex=(int)(100*rhp[rv][1]); gx=ex/100.0;
  hpr[rv][4]=rhp[rv][1]; hhpr[rv][4]=hpr[rv][4];   
  elp[rv][4].setText(Double.toString(gx)); }

   gx=0.0;                       // gx=sum of each potential energy
   for (int rv=0; rv <=7; rv++) { gx=gx+rhp[rv][1]; }
   
                                     //  calculate each kinetic energy from each V (eV)
   gy=-469.92-pot;               // -469.92 (eV)=energy of H2O, gy=total kinetic energy
   if (marki[4]==1) {
   for (int rv=0; rv <=7; rv++) {       
    gz=(gy*rhp[rv][1])/gx; hpr[rv][5]=gz; hhpr[rv][5]=gz;
   ex=(int)(100*gz); gz=ex/100.0; elp[rv][5].setText(Double.toString(gz)); 
   marki[4]=0; }                                            
   }

   if (marki[5] ==1 ) {         // transfer kinetic energies between electrons 
   String sswe; double RRWE,RRWD; int nmel1=0; int nmel2=0; 
   sswe=impho[0].getText(); RRWE=Double.parseDouble(sswe);
                                // transfer T from ele(nmel1) to ele(nmel2)
   sswe=(String)coom2.getSelectedItem();
   if (sswe == "el0") {nmel1=0;}  if (sswe == "el1") {nmel1=1;}
   if (sswe == "el2") {nmel1=2;}  if (sswe == "el3") {nmel1=3;}
   if (sswe == "el4") {nmel1=4;}  if (sswe == "el5") {nmel1=5;}
   if (sswe == "el6") {nmel1=6;}  if (sswe == "el7") {nmel1=7;}
   sswe=(String)coom3.getSelectedItem();
   if (sswe == "el0") {nmel2=0;}  if (sswe == "el1") {nmel2=1;}
   if (sswe == "el2") {nmel2=2;}  if (sswe == "el3") {nmel2=3;}
   if (sswe == "el4") {nmel2=4;}  if (sswe == "el5") {nmel2=5;}
   if (sswe == "el6") {nmel2=6;}  if (sswe == "el7") {nmel2=7;}
   hpr[nmel1][5]=hpr[nmel1][5]-RRWE; hhpr[nmel1][5]=hpr[nmel1][5];
   hpr[nmel2][5]=hpr[nmel2][5]+RRWE; hhpr[nmel2][5]=hpr[nmel2][5];
   ex=(int)(100*hpr[nmel1][5]); RRWD=ex/100.0;
   elp[nmel1][5].setText(Double.toString(RRWD));
   ex=(int)(100*hpr[nmel2][5]); RRWD=ex/100.0;
   elp[nmel2][5].setText(Double.toString(RRWD));
   marki[5]=0;
   }
   
  }  // if (marki !=2) end

                     // --------  start computing each electron's orbit  ----------
  if (marki[0]==1) {
  
  double sj[][]=new double[8][13]; double wn=0.0; double nvx[][]=new double[3][4];
  String pew=(String)coom.getSelectedItem();   //coom = number of de Broglie's waves 
   if (pew == "0.1") {wn=0.1;}  if (pew == "0.3") {wn=0.3;}
   if (pew == "0.5") {wn=0.5;}  if (pew == "0.7") {wn=0.7;}
   if (pew == "0.9") {wn=0.9;}  if (pew == "1.1") {wn=1.1;}
   if (pew == "1.3") {wn=1.3;}  if (pew == "1.5") {wn=1.5;}
   if (pew == "1.7") {wn=1.7;}  if (pew == "1.9") {wn=1.9;}
   if (pew == "2.0") {wn=2.0;}

    for (int yp=0; yp <=2; yp++) {     // change MM to meter in nuclei's coordinates
   for (int kj=0; kj <=2; kj++) {
    nvx[yp][kj]=nux[yp][kj]*1.0e-14; }  nvx[yp][3]=nux[yp][3]; }

  for (int yp=0; yp <=7; yp++) {
   sj[yp][9]=0.0;                 // sj[][9]=number of de Broglie's waves
   gx=Math.sqrt(hpr[yp][6]*hpr[yp][6]+hpr[yp][7]*hpr[yp][7]+hpr[yp][8]*hpr[yp][8]);
   gy=Math.sqrt((2.0*hpr[yp][5]*1.602177e-19)/me);  // gy=initial velocity (m/s)
                                       
   for (int kj=0; kj <=2; kj++) {              // sj[][0-2, 6-8] =electron's coordinate
   sj[yp][kj] =hpr[yp][kj]; sj[yp][kj+6]=sj[yp][kj];
   sj[yp][kj+3]=(gy*1.0e-7*hpr[yp][kj+6])/gx;  //sj[][3-5]=each component of velocity (MM/SS) 
   sj[yp][kj+10]=0.0;                         // sj[][10-12]=each component of acceleration 
   }}
 
      double ac=(elc*elc)/(4*pai*epsi*me);

   do {
   for (int yp=0; yp <=7; yp++) {
   for (int kj=0; kj <=2; kj++) {      
   sj[yp][kj]=sj[yp][kj+6]+sj[yp][kj+3];  // electron's position after 1 SS 
   sj[yp][10+kj]=0.0;
   }}

   for (int yp=0; yp <=7; yp++) {
   gx=sj[yp][3]*sj[yp][3]+sj[yp][4]*sj[yp][4]+sj[yp][5]*sj[yp][5];
   sj[yp][9]=sj[yp][9]+(me*gx*1.0e-7)/h;  // add de Broglie's waves
   for (int kj=0; kj <=2; kj++) {
   sj[yp][kj+6]=sj[yp][kj+6]*1.0e-14;    // change MM to meter
   }}

   for (int yp=0; yp <=7; yp++) {
   for (int kj=0; kj <=7; kj++) {        // interaction between electrons
   if (yp < kj) {
   gy=Math.sqrt((sj[yp][6]-sj[kj][6])*(sj[yp][6]-sj[kj][6])+
   (sj[yp][7]-sj[kj][7])*(sj[yp][7]-sj[kj][7])+(sj[yp][8]-sj[kj][8])*(sj[yp][8]-sj[kj][8]));
   for (int rv=0; rv <=2; rv++) {       // change velocity vector by other electrons
   gx=(1.0e-28*ac*(sj[yp][rv+6]-sj[kj][rv+6]))/(gy*gy*gy); 
   sj[yp][rv+10]=sj[yp][rv+10]+gx ;sj[kj][rv+10]=sj[kj][rv+10]-gx ;
   } } } }

    for (int yp=0; yp <=7; yp++) {       // interaction between electrons and nuclei
    for (int kj=0; kj <=2; kj++) {
   gy=Math.sqrt((sj[yp][6]-nvx[kj][0])*(sj[yp][6]-nvx[kj][0])+
   (sj[yp][7]-nvx[kj][1])*(sj[yp][7]-nvx[kj][1])+(sj[yp][8]-nvx[kj][2])*(sj[yp][8]-nvx[kj][2]));
   for (int rv=0; rv <=2; rv++) {        // change velocity vector by nuclei
   gx=(1.0e-28*nvx[kj][3]*ac*(sj[yp][rv+6]-nvx[kj][rv]))/(gy*gy*gy); 
   sj[yp][rv+10]=sj[yp][rv+10]-gx;
   }}}

   for (int yp=0; yp <=7; yp++) {
    for (int kj=0; kj <=2; kj++) {
   sj[yp][kj+6]=sj[yp][kj];
   sj[yp][kj+3]=sj[yp][kj+3]+sj[yp][kj+10];
    }}
    } while (sj[0][9] < wn );      // repeat above until de Broglie's waves = wn

   System.out.println("wn of e6 = " + sj[6][9]);  // show de Broglie's waves of electron 6
   marki[2]=2; marki[6]=1; marki[0]=0;
 
   for (int yp=0; yp <=7; yp++) {
     kro=Math.sqrt(sj[yp][3]*sj[yp][3]+sj[yp][4]*sj[yp][4]+sj[yp][5]*sj[yp][5]);
   for (int kj=0; kj <=2; kj++) { 
   hhpr[yp][kj]=sj[yp][kj]; ggx=sj[yp][kj]/71.428;  // change to pixel

   if (ggx > 319 && kj==0) {ggx=319; hhpr[yp][kj]=ggx*71.428;}
   if (ggx > 349 && kj==1) {ggx=349; hhpr[yp][kj]=ggx*71.428;}
   if (ggx > 349 && kj==2) {ggx=349; hhpr[yp][kj]=ggx*71.428;}
   if (ggx < 1) {ggx=1; hhpr[yp][kj]=ggx*71.428;}
   
   yk=(int)(100*(hhpr[yp][kj]-nux[0][kj]));  // change to relative coordinate
   if (yp==6) {yk=(int)(100*(hhpr[yp][kj]-nux[1][kj]));}
   if (yp==7) {yk=(int)(100*(hhpr[yp][kj]-nux[2][kj]));}   
                                             // show electron's coordinate
   gx=yk/100.0; elp[yp][kj].setText(Double.toString(gx));
                                             // show electron's velocity vector
   ggy=(1000*sj[yp][kj+3])/kro; ex=(int)ggy; hhpr[yp][kj+6]=ggy;
   elp[yp][kj+6].setText(Double.toString((double)ex));
   } 

   ggz=Math.sqrt((hhpr[yp][0]-nux[0][0])*(hhpr[yp][0]-nux[0][0])+
  (hhpr[yp][1]-nux[0][1])*(hhpr[yp][1]-nux[0][1])+(hhpr[yp][2]-nux[0][2])*(hhpr[yp][2]-nux[0][2])); 
 if (yp==6) {ggz=Math.sqrt((hhpr[yp][0]-nux[1][0])*(hhpr[yp][0]-nux[1][0])+
 (hhpr[yp][1]-nux[1][1])*(hhpr[yp][1]-nux[1][1])+(hhpr[yp][2]-nux[1][2])*(hhpr[yp][2]-nux[1][2]));}
 if (yp==7) {ggz=Math.sqrt((hhpr[yp][0]-nux[2][0])*(hhpr[yp][0]-nux[2][0])+
 (hhpr[yp][1]-nux[2][1])*(hhpr[yp][1]-nux[2][1])+(hhpr[yp][2]-nux[2][2])*(hhpr[yp][2]-nux[2][2]));}
  
   ex=(int)(100.0*ggz); ggz=ex/100.0;   // calculate to two decimal places
   elp[yp][3].setText(Double.toString(ggz));
   }
   }   // if (mark[0]==1) end
 
   int nmx[][]=new int[3][3]; int hpk[][]=new int[8][4]; int qpp[][]=new int[8][3];

  if (marki[2] != 2 || marki[6]==1 ) {   // show particle's picture on the screen
 
  for (int yp=0; yp <=7; yp++) {       // adjusting each velocity vector for printing
   pota=Math.sqrt(60)*4.25; 
  potb=Math.sqrt(hhpr[yp][6]*hhpr[yp][6]+hhpr[yp][7]*hhpr[yp][7]+hhpr[yp][8]*hhpr[yp][8]);   
    ggx=(pota*hhpr[yp][6])/potb; qpp[yp][0]=(int)ggx;
    ggx=(pota*hhpr[yp][7])/potb; qpp[yp][1]=(int)ggx;
    ggx=(pota*hhpr[yp][8])/potb; qpp[yp][2]=(int)ggx;
    }                      

  for (int yp=0; yp <=2; yp++) {
  for (int kj=0; kj <=2; kj++) {     // change MM to pixel in nuclei
  nmx[yp][kj]=(int)(nux[yp][kj]/71.428);
  }}
  for (int yp=0; yp <=7; yp++) {
  for (int kj=0; kj <=2; kj++) {     // change MM to pixel in electrons
  hpk[yp][kj]=(int)(hhpr[yp][kj]/71.428);
  }}

  g.clearRect(9,299,1170,699);
  g.setColor(Color.cyan); g.drawLine(345,310,345,660); g.drawLine(675,310,675,660);

  g.setColor(Color.lightGray);         // show three nuclei
  g.fillOval(nmx[0][0]+10,650-nmx[0][1],20,20);g.fillOval(340+nmx[0][0],650-nmx[0][2],20,20);
  g.fillOval(670+nmx[0][1],650-nmx[0][2],20,20);
  g.fillOval(13+nmx[1][0],653-nmx[1][1],14,14);g.fillOval(343+nmx[1][0],653-nmx[1][2],14,14);
  g.fillOval(673+nmx[1][1],653-nmx[1][2],14,14);
  g.fillOval(13+nmx[2][0],653-nmx[2][1],14,14);g.fillOval(343+nmx[2][0],653-nmx[2][2],14,14);
  g.fillOval(673+nmx[2][1],653-nmx[2][2],14,14); 

  g.setColor(Color.white);           // show electron 0 (particle and velocity line)
  g.fillOval(hpk[0][0]+13,653-hpk[0][1],14,14); 
  g.fillOval(hpk[0][0]+343,653-hpk[0][2],14,14);
  g.fillOval(hpk[0][1]+673,653-hpk[0][2],14,14);
  g.drawLine(hpk[0][0]+20,660-hpk[0][1], hpk[0][0]+20+qpp[0][0],660-hpk[0][1]-qpp[0][1]);
  g.drawLine(hpk[0][0]+350,660-hpk[0][2], hpk[0][0]+350+qpp[0][0],660-hpk[0][2]-qpp[0][2]);
  g.drawLine(hpk[0][1]+680,660-hpk[0][2],hpk[0][1]+680+qpp[0][1],660-hpk[0][2]-qpp[0][2]);  
                                      // show electron 1
  g.fillOval(hpk[1][0]+13,653-hpk[1][1],14,14); 
  g.fillOval(hpk[1][0]+343,653-hpk[1][2],14,14);
  g.fillOval(hpk[1][1]+673,653-hpk[1][2],14,14);
  g.drawLine(hpk[1][0]+20,660-hpk[1][1], hpk[1][0]+20+qpp[1][0],660-hpk[1][1]-qpp[1][1]);
 g.drawLine(hpk[1][0]+350,660-hpk[1][2], hpk[1][0]+350+qpp[1][0],660-hpk[1][2]-qpp[1][2]);
 g.drawLine(hpk[1][1]+680,660-hpk[1][2],hpk[1][1]+680+qpp[1][1],660-hpk[1][2]-qpp[1][2]);  
                                     
  g.setColor(Color.red);              // show electron 2
  g.fillOval(hpk[2][0]+13,653-hpk[2][1],14,14);
  g.fillOval(hpk[2][0]+343,653-hpk[2][2],14,14);
  g.fillOval(hpk[2][1]+673,653-hpk[2][2],14,14);
  g.drawLine(hpk[2][0]+20,660-hpk[2][1], hpk[2][0]+20+qpp[2][0],660-hpk[2][1]-qpp[2][1]);
  g.drawLine(hpk[2][0]+350,660-hpk[2][2], hpk[2][0]+350+qpp[2][0],660-hpk[2][2]-qpp[2][2]);
  g.drawLine(hpk[2][1]+680,660-hpk[2][2],hpk[2][1]+680+qpp[2][1],660-hpk[2][2]-qpp[2][2]);  
                                      // show electron 3
  g.fillOval(hpk[3][0]+13,653-hpk[3][1],14,14);
  g.fillOval(hpk[3][0]+343,653-hpk[3][2],14,14);
  g.fillOval(hpk[3][1]+673,653-hpk[3][2],14,14);
  g.drawLine(hpk[3][0]+20,660-hpk[3][1], hpk[3][0]+20+qpp[3][0],660-hpk[3][1]-qpp[3][1]);
  g.drawLine(hpk[3][0]+350,660-hpk[3][2], hpk[3][0]+350+qpp[3][0],660-hpk[3][2]-qpp[3][2]);
  g.drawLine(hpk[3][1]+680,660-hpk[3][2],hpk[3][1]+680+qpp[3][1],660-hpk[3][2]-qpp[3][2]);  
                                       // show electron 4
  g.setColor(Color.green);
  g.fillOval(hpk[4][0]+13,653-hpk[4][1],14,14);
  g.fillOval(hpk[4][0]+343,653-hpk[4][2],14,14);
  g.fillOval(hpk[4][1]+673,653-hpk[4][2],14,14);
  g.drawLine(hpk[4][0]+20,660-hpk[4][1], hpk[4][0]+20+qpp[4][0],660-hpk[4][1]-qpp[4][1]);
  g.drawLine(hpk[4][0]+350,660-hpk[4][2], hpk[4][0]+350+qpp[4][0],660-hpk[4][2]-qpp[4][2]);
  g.drawLine(hpk[4][1]+680,660-hpk[4][2],hpk[4][1]+680+qpp[4][1],660-hpk[4][2]-qpp[4][2]);  
                                        // show electron 5
  g.fillOval(hpk[5][0]+13,653-hpk[5][1],14,14);
  g.fillOval(hpk[5][0]+343,653-hpk[5][2],14,14);
  g.fillOval(hpk[5][1]+673,653-hpk[5][2],14,14);
  g.drawLine(hpk[5][0]+20,660-hpk[5][1], hpk[5][0]+20+qpp[5][0],660-hpk[5][1]-qpp[5][1]);
  g.drawLine(hpk[5][0]+350,660-hpk[5][2], hpk[5][0]+350+qpp[5][0],660-hpk[5][2]-qpp[5][2]);
  g.drawLine(hpk[5][1]+680,660-hpk[5][2],hpk[5][1]+680+qpp[5][1],660-hpk[5][2]-qpp[5][2]);  
                                       // show electron 6
  g.setColor(Color.pink);
  g.fillOval(hpk[6][0]+13,653-hpk[6][1],14,14);
  g.fillOval(hpk[6][0]+343,653-hpk[6][2],14,14);
  g.fillOval(hpk[6][1]+673,653-hpk[6][2],14,14);
  g.drawLine(hpk[6][0]+20,660-hpk[6][1], hpk[6][0]+20+qpp[6][0],660-hpk[6][1]-qpp[6][1]);
  g.drawLine(hpk[6][0]+350,660-hpk[6][2], hpk[6][0]+350+qpp[6][0],660-hpk[6][2]-qpp[6][2]);
  g.drawLine(hpk[6][1]+680,660-hpk[6][2],hpk[6][1]+680+qpp[6][1],660-hpk[6][2]-qpp[6][2]);  
                                        // show electron 7
  g.fillOval(hpk[7][0]+13,653-hpk[7][1],14,14);
  g.fillOval(hpk[7][0]+343,653-hpk[7][2],14,14);
  g.fillOval(hpk[7][1]+673,653-hpk[7][2],14,14);
  g.drawLine(hpk[7][0]+20,660-hpk[7][1], hpk[7][0]+20+qpp[7][0],660-hpk[7][1]-qpp[7][1]);
  g.drawLine(hpk[7][0]+350,660-hpk[7][2], hpk[7][0]+350+qpp[7][0],660-hpk[7][2]-qpp[7][2]);
  g.drawLine(hpk[7][1]+680,660-hpk[7][2],hpk[7][1]+680+qpp[7][1],660-hpk[7][2]-qpp[7][2]);  
    
  for (int rw=0; rw <=7; rw++) {         // show each electron's number
  g.setColor(Color.blue);
  g.drawString(Integer.toString(rw),hpk[rw][0]+17,665-hpk[rw][1]);
  g.drawString(Integer.toString(rw),hpk[rw][0]+347,665-hpk[rw][2] );
  g.drawString(Integer.toString(rw),hpk[rw][1]+677,665-hpk[rw][2] );
  }
   
  marki[6]=0; marki[3]=0;
  }  // if (marki[2] !=2 || marki[6]==1)  end
   }
   }