How does the brain function?

         I am not a neuroscientist or anything but just a guy who is curious to know how the brain functions. I know there is lots of research going in to this and lots of brilliant people are putting forward their theories of how the brain functions. So, here I am writing about, How our brain functions, based on conclusions drawn from carrying out some really simple experiments. (I could be wrong…But I do not think I am!). Here we will be discussing about the general working of the cerebral cortex, especially the frontal lobes, which are associated with executive functions such as self-control, planning, reasoning, and abstract thought.

stock-vector-head-and-brain-gears-in-progress-119930053

        So, here is the basic thing I found out in my first experiment; I have a friend named Jessica (name changed) whom I last saw when I was in my sixth grade. Back then she was some feet tall had big brown eyes, short black hairs, and fair colour. Now for some reasons she moved to a western country and returned back after seven years, for holidays. When I went to pick her up on the airport I found it hard to recognize her…she was now feet tall and she had blonde hairs and had a beautiful face with proportional eyes! Now lets us look from the perspective of our mind. When I first met, her, my mind kind of observed all the important features of her and stored that information. Now after that whenever I met her, my mind would recall all that information it has stored about her, which would help it to recognize her and compare it with the present information obtained from the present Jessica. It would update its information about Jessica if she would make any minor beauty makeovers, but that information would not serve a ground to identify her because my mind already knows that those beauty makeovers are temporary and are subjected to change, although they would help me to spot the difference.

         Now back to present, when I am driving to the airport, my mind meanwhile, gathers all the information it has about her and compiles it in a way that would help me to identify her at the airport. Based on that information it predicts her appearance as a white girl with black hairs and brown eyes. Here comes the tricky part, when she meets me in the parking lot, my mind notices that there has been a remarkable change in here appearance; her hairs are blonde, she is quite tall, her voice, body language has been changed. Since, this does not matches up the few predictions of her appearance made by my mind previously it gets confused for few seconds. Although, it comes back on track and again updates here information. Now as these changes were major but not major enough to make my mind believe that she is someone else; it updates its obsolete data about her and proceeds.

Therefore, from this we can say, that our mind constantly collects information from the all the bodies around us. In course of time, it modifies or removes some part of that information when changes are observed in them and it has the ability to recall and compare that information to check the validity of that particular body or the entire system.

         This above conclusion can also be checked; when we recognize that our friend has cold from the change in his voice over the phone. Our mind constantly gathers information, complies information, arranges it, or modifies it. It also derives some general theories or principles from this complied information and takes further action or decisions on its basis. These general theories or principles can be anything like when your friend speaks to you in a harsh voice he is probable angry or if he is being excessively polite probably he needs a favour from you. Alternatively, these principles can also be about other day-to-day stuff like sugar which looks something like small transparent cubes is sweet in taste. Now, if someone offers you something that looks almost like sugar but tastes bitter, your are surprised and confused and meanwhile your mind forces you to check the fact behind this thing.

           Now in the second scenario, lets us name orange juices as water and water as orange juice. When a small kid who has recently learnt that orange juices is something that has no taste and is colourless whereas water is something that is colourful and tastes awesome…is corrected by an adult that he has got confused with both the things. Now the kid will argue with that adult and try to prove that he is correct.

From this, we conclude that our mind labels information and tries to find a relation between things it has learnt and the facts it has observed and derives one single general principle from it, for better reasoning.

        This is the only reason that we have several theories from several scientists about extinction of dinosaurs; as our mind tries to derive a reasoning to it by finding a relation between things it has learnt and fact it knows (which are very less in this instance). But, when we consider this example, “Earth is circular in shape” everybody seems to agree to it because we have got lots of facts or photos to prove this statement; which provides a perfect reasoning to everybody’s mind. Now if in case some reputed scientists comes up and shows that, earth is in fact changing shape, with all sorts of proofs and photos we all will be confused and there will be a lots of theories to explain it, and this quest will continue unless and until someone comes up with a theory which will be having a perfect relation between facts and things we have learnt. A theory which will satisfy the sense, reasoning of everybody’s mind and thus there will be no further discussion.

         Therefore, I learnt these two things about the functioning of our brain from some easy day-to-day examples. If you have something to add or you completely disagree with what I have said above please let me know in the comment box below…!

 

Java Swing GUI–Currency Converter

       This is a Java Swing GUI program for currency conversion. So basically here we convert one currency to other or vise versa. For detailed explanation of how swing works checkout my previous post;

   Here as usual we create a JApplet class and implement an Action Listener. Here we require two text fields, two Combo box, two buttons and offcourse four labels. The rest are heard of but the JComboBox is new.Convc Conce

It is quite similar to a dropdown list only we have to specify the elements included in it, as String array.Here is how you will initialize them;

JComboBox c1,c2;

    String[] currency={"US Dollar","Indian Rupee","British Pound","Euro","Canadian Dollar","Emirati Driham","Chinese Yuan"};
  c1=new JComboBox(currency);
  c1.setSelectedIndex(0);
  c2=new JComboBox(currency);
  c2.setSelectedIndex(1);

 

     Now as you seen in the String array we have all the elements to be shown in the combo box that is the seven currencies. Then we initialize the combo box to String array ‘currency’ and set its index to 0, that is by default it will show up the element at index zero, in this case ‘US Dollar’.

    Here also, to design the GUI we use the GridBagLayout. We position the components as per our requirement and add them on the frame and lastly assign Action Listener to the components with which we are going to interact.

    Now when we complete our GUI we go for action performed; where we specify what happens when the user interacts with a particular component. We first get the amount from the first text field that has to be converted. Very important thing here is that any text field stores the data within it as a string so, to perform mathematical operation on the value we need to convert it from string to double.

    a=Double.valueOf(t1.getText());

 

    This step here is quite important where we need to decide from which currency to which currency we need to convert the amount. The string array here comes in handy. As we read the string array on the basis of index lets us consider; if the user selects index 2 at the combo box c1 and selects index 5 at the combo box c2; that means we need to convert British pounds to Emirati Dirham; so it performs that mathematical operation within the if condition. For example,

if(c1.getSelectedIndex()==2 & c2.getSelectedIndex()==5){
c= a*6.170453;}

 

Similarly to perform all the currency conversion we need to consider all the combinations of the currencies with each other except with itself, that is have to consider almost forty-two combinations. Then again to display this result in the second text field we need to convert the double value to string.

     t2.setText(String.valueOf(c));

 

You can also add the Clear button to clear the text fields;

if(ae.getSource()==b2){
  t1.setText("0000");
  t2.setText("0000");}

Note: The conversion rates were dated on 19th of April 2014 and obviously must have changed the very next day so you need to tinker with that formula if you want accuracy. Conversion rates were obtained from X-Rates.

  • Download the source code of this program here:

Download

     If you have any improvements in this program to make it short and simple or have any doubts regarding this program please let me know by commenting below.

Java Swing GUI- Chemical Properties of Elements

      In one of my previous posts, I made a C program, which would find the atomic number of an element from a text file and display it. Here today I have an upgraded version of that same program which is far more efficient than the C program. It is written in Java and when you search an element in the search box, it shows the atomic number, atomic radius, electronic configuration, electronegativity, first ionization energy and its chemical name in a beautiful graphical user interface.

swing

Atomic Properties

swingpane

J panel/ Message box

       Now let us look it to this program. This Java program is using the Swing GUI Components, which works far more better and looks better than the AWT. It includes everything from buttons to split panes to tables. Many components are capable of sorting, printing, and drag and drop, to name a few of the supported features. So, basically any Java GUI program gets divide in to three section; the first is your Action listener, second your main method and the third Action performed section. First we need to import the necessary packages like awt, swing, io, etc. To run the program use this method;

public void init(){
    {   
      (new Runnable(){
            public run(){
                makeGUI();}
                            });
            }catch(Exception exc){ System.out.println("Error occured due to"+exc);}
   }

Now we create our frame, which holds all the GUI components on the frame, and implement an Action Listener to it. The Action Listener listens to the activities of our components.

    public class swin extends JApplet implements ActionListener {

We now initialize all the text fields, buttons and labels required in this program so; here particularly we require seven text fields, four buttons, 7 labels. Then we write a main method that runs this program. To code the buttons, text fields, labels, etc. we write a constructor to the class, in this case makeGUI() and design the GUI in it. We specify the buttons and name them, then the labels and the text fields. For the proper arrangement and look of these components, we select a layout, GridBagLayout. GridBagLayout is one of the most flexible and complex layout managers the Java platform provides. A GridBagLayout places components in a grid of rows and columns, allowing specified components to span multiple rows or columns. Not all rows necessarily have the same height. Similarly, not all columns necessarily have the same width. Here is how to initialize the GridBagLayout;

    GridBagLayout gbag=new GridBagLayout();
    GridBagConstraints gbc=new GridBagConstraints();      
    setLayout(gbag);

Essentially, GridBagLayout places components in rectangles (cells) in a grid, and then uses the components’ preferred sizes to determine how big the cells should be.The way the program specifies the size and position characteristics of its components is by specifying constraints for each component.Specify the number of columns (for gridwidth) or rows (for gridheight) in the component’s display area. These constraints specify the number of cells the component uses, not the number of pixels it uses. The default value is one. Use GridBagConstraints.REMAINDER to specify that the component be the last one in its row (for gridwidth) or column (for gridheight). Use GridBagConstraints.RELATIVE to specify that the component be the next to last one in its row (for gridwidth) or column (for gridheight).Anchor is used when the component is smaller than its display area to determine where (within the area) to place the component. Specifying weights is an art that can have a significant impact on the appearance of the components a GridBagLayout controls. Weights are used to determine how to distribute space among columns (weightx) and among rows (weighty); this is important for specifying resizing behavior. A sample of how to design the layout;

       gbc.weighty=1.0;
       gbc.gridwidth=GridBagConstraints.REMAINDER;
       gbc.anchor=GridBagConstraints.NORTH;
       gbag.setConstraints(h, gbc);
       gbc.anchor=GridBagConstraints.EAST;
       gbc.gridwidth=GridBagConstraints.;
       gbag.setConstraints(l1, gbc);
       gbc.gridwidth=GridBagConstraints.REMAINDER;
       gbag.setConstraints(t1, gbc);

After positioning all the components, we add them on our frame sequentially one by one. In addition, we add action listener to the components with which we are going to interact.

       add(l1);add(t1);add(l2);add(l2);
          t1.addActionListener(this);
          t2.addActionListener(this);

An action event occurs, whenever an action is performed by the user. When the user clicks a button, chooses a menu item, presses Enter in a text field. The result is that an actionPerformed message is sent to all action listeners that are registered on the relevant component. Therefore, we create an Action performed class and specify what happens when the user interacts with a particular component.

       public void actionPerformed(ActionEvent ae){

Therefore, the trick here is to create a method in which we write the working of the program, return the result, and when required, call the method and display the result. For example, here we read the element entered by the user in a text filed and store it in a variable. Then we call a method, which we are going to create in the following step and display their results or the returned value in other text field. Now in these methods we import the data of the variable, which stores the input. We read a particular text file line by line and compare it with the input and if it matches, we return the matched string to the method, which later displays the string in the text filed. This is particularly done for the atomic number similar process can be done for other atomic properties and their outputs can be displayed in to separate text fields. Below is code of one of the atomic properties, we got the input from the text fields in variable ‘a’ then we store the result of the method atomicnumber() in string ‘atmno’ and set the text of text field ‘t2′ to it. Then method atomicnumber() is created and value of ‘a’ is imported along with it, we use Boolean to check the condition. Then file in which all the atomic numbers are stored is read line by line (readLine) and the starting of the string is compared with the input string (startsWith) stored in variable ‘a’. Its found value of Boolean is ‘true’ and the found string is returned to the method and displayed in the text field.

     String a=t1.getText();
     String atmno="";
       try{
          atmno=atomicnumber(a);
          t2.setText(atmno);}
             catch(Exception x){System.out.println("Error");}
     public static String atomicnumber(String a){
       try{
          boolean found=false;      
          FileReader f=new FileReader("C:/Users/DELL/Periodic/text/AtomicNumber.txt");          String e;  
          BufferedReader new BufferedReader(f);
              while((e=sc.readLine()) != null){
                    if (e.startsWith(a)){            
                          found=true;
                          return e;}         
                               }
                      return("Invalid Input");} 
              (Exception e){e.printStackTrace();}

 

     As you can see I have also used ‘if’ and ‘getsource’, which performs a particular operation, specified within when the specified button is pressed. This gives me the feature to clear the text fields or to display a message box. Displaying a message box can be done by the JOptionPane. There are lots of others features that you can add like colors, borders, fonts, etc. in the swing to make your program work effectively and look better. You can also use different designs of the following is the message dialog box

             if(ae.getSource()==b2){       
                   JOptionPane.showMessageDialog(this,"Your Message");}

 

 If you have problem with any function or step of this program please let me know in the comment box below. Download the source code of this program below.

Download

Note: Please change the file paths to your current destination folders.

Follow

Get every new post delivered to your Inbox.

Join 476 other followers