Sample JAVA program to visualize the electron's distribution of the Fluorine (F) of Bohr model.

Back to the fluorine 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 Fus, so save this text editor as "Fus.java", and compile it.

In this program, the fluorine nucleus (gray color) is at (12500MM, 12500MM, 12500MM).
Here we use the new units, ( 1 MM = 10-14 meter).
Each coordinate of electrons (+X (MM), +Y (MM), +Z (MM)) in the text box means "relative" positions from this nucleus.
(You can change this coordinates by entering the values into the text boxes, and press the Enter key.)
"nuc (MM)" means the distance between the nucleus and each electron. (All are the same.)
(You can change this distance by entering the value into the last row, and press the Enter key.)

V (eV) and T (eV) mean the potential and kinetic energies of each electron.
CF means the force toward the nucleus acting on each electron.
(fx, fy, fz) mean the each component of the "remaining" force other than CF.
(FX, FY, FZ) of the last row mean each component of the force acting on the nucleus.
(The unit of force: 1000 = the force between +e nucleus and -e electron which are Bohr radius apart from each other)
tV of the last row is the total potential energy (eV).
Waves (wn) means the number of de Broglie's waves contained in one orbit of each electron.


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Scanner;
public class Fus extends JPanel     // virial theorem of F (fluorine)
 {
  public static void main(String arg[])
 {                                              // set frame
   JFrame frame = new JFrame("Fluorine (F)");
   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);  
  }
  }
 class J2DPanel extends JPanel implements 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
 
                            // elp[0-6][0-10] = each textbox parameter of electron (0-6)
    JTextField elp[][]=new JTextField[7][11];  JTextField impho=new JTextField(7); 
    JTextField mmpho[]=new JTextField[3];   JTextField imppo=new JTextField(7); 
   
    int marki[]=new int[3]; int mar=0;       // marking

    double rtw=Math.sqrt(2); double rth=Math.sqrt(3); 
   double rsi=Math.sqrt(6); double rfi=Math.sqrt(5);
    double hpr[][]=new double[7][11];  
    double den=7.3; double tene=658.835;    // tene= (+) fluorine atom energy (1-7th)
                                             // den= central positive charge  
     
    double nux[]={12500.0, 12500.0, 12500.0};   // nux[0-2]=nuclear coordinate
                                             
    double ina1=4004.0;      // ina1= distance between nucleus and electron
    
                              // te1=initial coodinate of each electron
    double te1[][]={{1003.34,-2774.06, 2707.37}, {1656.19, 2376.89, 2763.94}, 
    {-3137.21, 252.07, 2475.14}, {2567.49, -2408.64, -1907.46}, 
    {2552.08, 2277.65, -2081.14}, {-2256.87, 2721.27, -1879.68}, 
    {-2416.45, -2451.32, -2045.41}};

  public J2DPanel()
 {
  setBackground(Color.black);
  JPanel p=new JPanel();
  p.setLayout(new GridLayout(9,12));
  String vv,zww; int aaa=0; 
                               
  for (int el=0; el <=6; el++) {       // hpr[0-6][0-2] = coordinate of each electron (0-6)
  for (int pos=0; pos <=2; pos++) {
  elp[el][pos]=new JTextField(7); elp[el][pos].addActionListener(this);
  hpr[el][pos]=0.0;      
  }}
                                   
   for (int el=0; el <=6; el++) {       // other parameters of each electron
  for (int pos=3; pos <=10; pos++) {
  elp[el][pos]=new JTextField(7);     
  hpr[el][pos]=0.0; 
  }}

                                     // mmpho[0-2] = force components acting on the nucleus
   for (int pos=0; pos <=2; pos++) {
    mmpho[pos]=new JTextField(7);
   }

                                        // layout

   String sihy[]={"eNo. ", "+X (MM)", "+Y (MM)", "+Z (MM)", "nux (MM)", 
   "V (eV)", "T (eV)", "Force", "fx ", "fy", "fz", "Waves "};

  for (int el=0; el <=11; el++) {
   p.add(new Label(sihy[el]));
  }
 
  for (int el=0; el <=6; el++) {       
  p.add(new Label("ele "+el+" "));
  for (int pos=0; pos <=10; pos++) {
  p.add(elp[el][pos]);
  }}

   p.add(new Label("F nuc "));
  for (int pos=0; pos <=2; pos++) {
  p.add(mmpho[pos]);  
  }
                                      // imppo=textbox of ina1 (distance)
                                     // impho=textbox of total potential energy (tV)  

     p.add(imppo); p.add(impho);  imppo.addActionListener(this);
   for (int pos=0; pos <=5; pos++) {
  p.add(new Label(" -- "));
    }
 
  add(p,"South");
  
   for (int el=0; el <=6; 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); 
   elp[el][3].setText(Integer.toString(aaa)); // show distance between nuclei and electrons 
    for (int jou=0; jou <=2; jou++) {
    hpr[el][jou]=te1[el][jou]+nux[jou]; 
                                              // show initial coordinate
    elp[el][jou].setText(Integer.toString((int)(te1[el][jou])));
     }}
   imppo.setText(Double.toString(ina1));
  }     // public J2DPanel() end
 
  
  public void actionPerformed(ActionEvent e) {     // when textboxes change
    String ss;  ss=" ";
    double Rf1,Rf4;  mar=0; Rf4=0.0; Rf1=0.0;
    marki[0]=0; marki[1]=0;
    if (e.getSource()==imppo ) {mar=1;           // when radius changes
    ss=imppo.getText(); ina1=Double.parseDouble(ss);  
    if (ina1 > 9000.0) {ina1=9000.0;}    if (ina1 < 1000.0) {ina1=1000.0;}
     }

    for (int ett=0; ett <=6; ett++) {    
    for (int sws=0; sws <=2; sws++) {             // when each coordinate changes    

   if (e.getSource()==elp[ett][sws] ) {marki[0]=ett+1; marki[1]=sws+1; 

      Rf4=Math.sqrt(ina1*ina1-hpr[ett][2]*hpr[ett][2]);
     ss=elp[ett][sws].getText(); Rf1=Double.parseDouble(ss);
      if (Rf1 > ina1 && sws==2 ) {Rf1=ina1;}   if (Rf1 <-ina1 && sws==2 ) {Rf1=-ina1;}
      if (Rf1 > Rf4 && sws != 2 ) {Rf1=Rf4;}  if (Rf1 < -Rf4 && sws != 2 ) {Rf1=-Rf4;}
    hpr[ett][sws]=Rf1+nux[sws];
     }
    }}
   
   repaint();
  }

  public void update(Graphics g)
 {
  paint(g);
 }
 public void paintComponent(Graphics g)
 {
   
  double kro,gx,gy,gz,ggx,ggy,ggz,ttav,toav;
  kro=0.0; gx=0.0;gy=0.0;gz=0.0;ggx=0.0; ggy=0.0; ggz=0.0;
  int ex,ey,ez; String ww;
  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,0,0,0,0},{0,0,0,0,0,0}};
  
  double mmp[]={0,0,0};  
  
               // ---------------------  change radius

 if (mar==1) {         
     for (int yp=0; yp <=6; yp++) { 
      gx=Math.sqrt((hpr[yp][0]-nux[0])*(hpr[yp][0]-nux[0])+
  (hpr[yp][1]-nux[1])*(hpr[yp][1]-nux[1])+(hpr[yp][2]-nux[2])*(hpr[yp][2]-nux[2]));     
    for (int kj=0; kj <=2; kj++) { 
      gy=hpr[yp][kj]-nux[kj]; gy=(gy*ina1)/gx; hpr[yp][kj]=gy+nux[kj];
       elp[yp][kj].setText(Integer.toString((int)gy));
     }}  mar=0;
   }  
                       // --------------------  change coordinate                                               

 if (marki[0] !=0) {  ex=marki[0]-1;         // ex= electron number changed
   gy=Math.sqrt((hpr[ex][0]-nux[0])*(hpr[ex][0]-nux[0])+(hpr[ex][1]-nux[1])*(hpr[ex][1]-nux[1]));
   gx=Math.sqrt(ina1*ina1-(hpr[ex][2]-nux[2])*(hpr[ex][2]-nux[2]));

  if (marki[1]==3) {                 // when z coordinate is changed
   gz=((hpr[ex][0]-nux[0])*gx)/gy;  hpr[ex][0]=gz+nux[0];
   gz=((hpr[ex][1]-nux[1])*gx)/gy;  hpr[ex][1]=gz+nux[1];
    }
                                     // when x coordinate is changed
  if (marki[1] == 1) { gz=Math.sqrt(gx*gx-(hpr[ex][0]-nux[0])*(hpr[ex][0]-nux[0]));
   ggz=hpr[ex][1]-nux[1];
   if (ggz >= 0) {hpr[ex][1]=gz+nux[1];}   
   if (ggz < 0) {hpr[ex][1]=-gz+nux[1];}
    }
                                    // when y coordinate is changed
  if (marki[1] == 2) { gz=Math.sqrt(gx*gx-(hpr[ex][1]-nux[1])*(hpr[ex][1]-nux[1]));
     ggz=hpr[ex][0]-nux[0];
    if (ggz >= 0) {hpr[ex][0]=gz+nux[0];}   
    if (ggz < 0) {hpr[ex][0]=-gz+nux[0];}
    }
    for (int kj=0; kj <=2; kj++) {
    elp[ex][kj].setText(Integer.toString((int)(hpr[ex][kj]-nux[kj])));
     }
   }

   toav=0.0;                // toav=total potential energ

  double ppot;
   for (int yp=0; yp <=6; yp++) {          // ------ interaction between electrons       
    for (int kj=0; kj <=6; kj++) { 
    if (yp < kj ) {
                                        // kro=distance between electrons
    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;}
                                     // ppot=repulsive potential energy (eV) 
     ppot=(elc*elc*6.241509e18)/(4*pai*epsi*kro*1.0e-14); 
    toav=toav+ppot;
                                    // rhp[][3]= potential energy of each electron
   rhp[yp][3]=rhp[yp][3]+ppot/2.0; rhp[kj][3]=rhp[kj][3]+ppot/2.0;
    for (int jou=0; jou <=2; jou++) {
                                    // rhp[][0-2]=force component acting on each electron
   ggx=(suh*(hpr[yp][jou]-hpr[kj][jou]))/(kro*kro*kro);
   rhp[yp][jou]=rhp[yp][jou]+ggx; rhp[kj][jou]=rhp[kj][jou]-ggx;     
    } 
   }}}
                                   // ----- interaction between nucleus and each electron
    for (int rv=0; rv <=6; rv++) {  
                                   // kro=distance between nucleus and electron  
    kro=Math.sqrt((hpr[rv][0]-nux[0])*(hpr[rv][0]-nux[0])+
   (hpr[rv][1]-nux[1])*(hpr[rv][1]-nux[1])+
   (hpr[rv][2]-nux[2])*(hpr[rv][2]-nux[2]));
    if (kro == 0) {kro=5000.0;}   
     ex=(int)(kro);  elp[rv][3].setText("nuc "+Integer.toString(ex));
       ppot=-(elc*elc*den*6.241509e18)/(4*pai*epsi*kro*1.0e-14);
     toav=toav+ppot; 
     rhp[rv][3]=rhp[rv][3]+ppot; 
    for (int jou=0; jou <=2; jou++) {   // ggx=force component between nucleus and electron
     ggx=(suh*den*(hpr[rv][jou]-nux[jou]))/(kro*kro*kro);
     rhp[rv][jou]=rhp[rv][jou]-ggx;  mmp[jou]=mmp[jou]+ggx;
     }}

   ex=(int)(100*toav); ggx=ex/100.0;
   impho.setText("tV "+Double.toString(ggx));             // show total V
 
   
    for (int rv=0; rv <=6; rv++) {                // show forces acting on electrons       
    gx=Math.sqrt((hpr[rv][0]-nux[0])*(hpr[rv][0]-nux[0])+
  (hpr[rv][1]-nux[1])*(hpr[rv][1]-nux[1])+(hpr[rv][2]-nux[2])*(hpr[rv][2]-nux[2]));

                                               // gy=forces toward nucleus (CF)
    gy=-(rhp[rv][0]*(hpr[rv][0]-nux[0])+rhp[rv][1]*(hpr[rv][1]-nux[1])+rhp[rv][2]*(hpr[rv][2]-nux[2]))/gx;
    ex=(int)(1000*gy); ww="CF ";
    elp[rv][6].setText(ww+Integer.toString(ex));
                                             // show  forces other than CF
    for (int jou=0; jou <=2; jou++) {
    gz=rhp[rv][jou]-(gy*(nux[jou]-hpr[rv][jou]))/gx;
    ex=(int)(1000*gz); 
    elp[rv][jou+7].setText(Integer.toString(ex));
     }
    }

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


   double hiwa=0.0;double sa[]=new double[7];  double hiwa2=0.0;
                                  // sa[]=V differences between electron 0 and other
  for (int rv=1; rv <=6; rv++) { sa[rv]=rhp[rv][3]-rhp[0][3]; hiwa=hiwa+sa[rv]; }
   for (int rv=0; rv <=6; rv++) { hiwa2=hiwa2+rhp[rv][3]; }
                                  // rhp[][4] = kinetic energy of each electron
  rhp[0][4]=(-tene-hiwa2+hiwa)/7.0;
  for (int rv=1; rv <=6; rv++) {rhp[rv][4]=rhp[0][4]-sa[rv];}                        
                                                             
                                  // show potential and kinetic energy 
  for (int rv=0; rv <=6; rv++) {
   ex=(int)(100*rhp[rv][3]); ggx=ex/100.0;
   elp[rv][4].setText("V "+Double.toString(ggx)); 
    ex=(int)(100*rhp[rv][4]); ggx=ex/100.0;
   elp[rv][5].setText("T "+Double.toString(ggx));
   }

                                                                                             
   for (int rv=0; rv <=6; rv++) {         // -----   show de Broglie wave
   
   gz=Math.sqrt(rhp[rv][0]*rhp[rv][0]+rhp[rv][1]*rhp[rv][1]+rhp[rv][2]*rhp[rv][2]);
   
   gy=(gz*elc*elc)/(4*pai*epsi*suh*1.0e-28);    // gy=forces (N) acting on each electron
   gx=Math.sqrt((2*rhp[rv][4]*1.602177e-19)/me);  // gx=velocity (m/s) of each electron
   
   ggx=(me*gx*gx)/gy;                          // ggx="temporaly"radius (m)
   ggy=(2*pai*ggx*me*gx)/h;                     // ggy=number of de Broglie's waves
  ex=(int)(ggy*1000);  ggy=ex/1000.0;
  elp[rv][10].setText("wn "+Double.toString(ggy));  }

                  
   int nmx[]=new int[3]; int hpk[][]=new int[8][4]; 

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

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

  g.setColor(Color.lightGray);         // show nucleus
  g.fillOval(nmx[0]+10,650-nmx[1],20,20);g.fillOval(370+nmx[0],650-nmx[2],20,20);
  g.fillOval(730+nmx[1],650-nmx[2],20,20);
  
  g.setColor(Color.white);           // show electron 0 (particle)
  g.fillOval(hpk[0][0]+13,653-hpk[0][1],14,14); 
  g.fillOval(hpk[0][0]+373,653-hpk[0][2],14,14);
  g.fillOval(hpk[0][1]+733,653-hpk[0][2],14,14);
  
                                      // show electron 1
  g.fillOval(hpk[1][0]+13,653-hpk[1][1],14,14); 
  g.fillOval(hpk[1][0]+373,653-hpk[1][2],14,14);
  g.fillOval(hpk[1][1]+733,653-hpk[1][2],14,14);
                                     
  g.setColor(Color.red);              // show electron 2
  g.fillOval(hpk[2][0]+13,653-hpk[2][1],14,14);
  g.fillOval(hpk[2][0]+373,653-hpk[2][2],14,14);
  g.fillOval(hpk[2][1]+733,653-hpk[2][2],14,14);
  
                                      // show electron 3
  g.fillOval(hpk[3][0]+13,653-hpk[3][1],14,14);
  g.fillOval(hpk[3][0]+373,653-hpk[3][2],14,14);
  g.fillOval(hpk[3][1]+733,653-hpk[3][2],14,14);
    
                                       // show electron 4
  g.setColor(Color.green);
  g.fillOval(hpk[4][0]+13,653-hpk[4][1],14,14);
  g.fillOval(hpk[4][0]+373,653-hpk[4][2],14,14);
  g.fillOval(hpk[4][1]+733,653-hpk[4][2],14,14);
    
                                        // show electron 5
  g.fillOval(hpk[5][0]+13,653-hpk[5][1],14,14);
  g.fillOval(hpk[5][0]+373,653-hpk[5][2],14,14);
  g.fillOval(hpk[5][1]+733,653-hpk[5][2],14,14);
   
                                       // show electron 6
  g.setColor(Color.pink);
  g.fillOval(hpk[6][0]+13,653-hpk[6][1],14,14);
  g.fillOval(hpk[6][0]+373,653-hpk[6][2],14,14);
  g.fillOval(hpk[6][1]+733,653-hpk[6][2],14,14);
    
  for (int rw=0; rw <=6; 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]+377,665-hpk[rw][2] );
  g.drawString(Integer.toString(rw),hpk[rw][1]+737,665-hpk[rw][2] );
  }
   }
   }