Application that display the electronic configurations of the elements from Periodic Table with GUI Graphic User Interface

I rewrote the java source code of the application with periodic table and now it has an GUI (Graphic User Interface).
-------------------------------------------------------------------------------------------------------------

/**
 * Application created by 23Ars! For more application in java or c++ visit:
 * http://23ars.blogspot.com.
 */
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class periodic_table extends JFrame
{
    private static final int WIDTH = 500;
    private static final int HEIGHT = 300 ;
    private JLabel zL, confL;
    private JTextField zTF, confTF;
    private JButton calculateB, exitB;
    //Button handlers:
    private CalculateButtonHandler cbHandler;
    private ExitButtonHandler ebHandler;
    public periodic_table()
    {
        zL = new JLabel("Enter Z: ", SwingConstants.LEFT);
        confL = new JLabel("Configuration: ", SwingConstants.LEFT);
        zTF = new JTextField(10);
        confTF = new JTextField(10);
        //SPecify handlers for each button and add (register) ActionListeners to each button.
        calculateB = new JButton("Calculate");
        cbHandler = new CalculateButtonHandler();
        calculateB.addActionListener(cbHandler);
        exitB = new JButton("Exit");
        ebHandler = new ExitButtonHandler();
        exitB.addActionListener(ebHandler);
        setTitle("Sample Title: Electronic configuration");
        Container pane = getContentPane();
        pane.setLayout(new GridLayout(4, 2));
        //Add things to the pane in the order you want them to appear (left to right, top to bottom)
        pane.add(zL);
        pane.add(zTF);
        pane.add(confL);
        pane.add(confTF);
        pane.add(calculateB);
        pane.add(exitB);
        setSize(WIDTH, HEIGHT);
        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
    private class CalculateButtonHandler implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            int z;
            z =Integer.parseInt(zTF.getText()); //We use the getText & setText methods to manipulate the data entered into those fields.
            switch(z)
            {
            case 1:confTF.setText("The element is H and it has the configuration 1s`1");break;
            case 2:confTF.setText("The element is He and it has the configuration 1s`2");break;
            case 3:confTF.setText("The element is Li and it has the configuration 1s`2 2s`1");break;
           // and 115 cases.
            default: confTF.setText("The number is to high!");
            }        
      }
    }
    public class ExitButtonHandler implements ActionListener
    {
        public void actionPerformed(ActionEvent e)
        {
            System.exit(0);
        }
    }
    public static void main(String[] args)
    {
    periodic_table rectObj = new periodic_table();
    }
}
-------------------------------------------------------------------------------------------------------------
The full source code and the executable .jar file you can find HERE. Dont panic, there is no virus in the archive!

Related Posts by Categories

0 comments:

Post a Comment


Blog Archive

Powered by Blogger.