24 Jun 2015

Notes on Database Management System (DBMS) and Business Information System (BIS)

Follow the link to download the notes:


                Content of DBMS notes comprises of basic concepts of DBMS, Join, Normalization, etc. and also comprises of lab work which includes basic queries and procedures and much more.

                
                BIS notes comprises content related to Business Process, Business Levels and its Forms, Data System, Introduction to Artificial Intelligence, System Investigation, System Design and Implementation, Payroll and Inventory Management Systems.

16 May 2015

Amazing Random Class Variables



Playing Android Games is an amazing experience as every time one plays the game, s/he comes across new obstacles, new villains of different sizes, different colors, different numbers, new backgrounds and much more. This feature retains the interest of the player in the game by preventing the boredom which is created when the player plays the games which loads the same components every time.

This amazing feature is achieved with the help of Random class variables. These variables generate random values restricted to the limit specified every time they are executed.

Let us learn the use of Random class variables with simple example. Let us create an Android application which will generate random colors in the 3 x 3 grid every time the “Play” button is pressed.

Code:

package com.example.randomcolorsgenerator;

import java.util.Random;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.widget.*;

public class MainActivity extends Activity {

TextView t[] = new TextView [9];
Button b1;
int i,red,green,blue;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        t[0] = (TextView)findViewById(R.id.tv1);
        t[1] = (TextView)findViewById(R.id.tv2);
        t[2] = (TextView)findViewById(R.id.tv3);
        t[3] = (TextView)findViewById(R.id.tv4);
        t[4] = (TextView)findViewById(R.id.tv5);
        t[5] = (TextView)findViewById(R.id.tv6);
        t[6] = (TextView)findViewById(R.id.tv7);
        t[7] = (TextView)findViewById(R.id.tv8);
        t[8] = (TextView)findViewById(R.id.tv9);
        b1 = (Button)findViewById(R.id.button);
   
            b1.setOnClickListener(new View.OnClickListener() {
               
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    try{
                    Random r = new Random();
                    for(i=0;i<9;i++){
                        red = r.nextInt(256);
                        green = r.nextInt(256);
                        blue = r.nextInt(256);
                        t[i].setBackgroundColor(Color.rgb(red,green,blue));
                        t[i].setText(red+","+green+","+blue);
                    }
                    }
                   
                    catch(Exception e){}
                }
           
            });
  
    }
   
}

Layout file:


Snapshots:


15 May 2015

Are you a Java Programmer – If yes, aren’t you an Android Developer?



Developing Android Applications is easier if you are a java programmer. Android Developer Tools comes with a pack of numerous classes which enables you to develop Android Applications. Before starting you should have the basic idea about how you would set up your android development environment. You will require:

  • Java JDK
  • Eclipse IDE
  • Android ADT
  • Android SDK

 I recommend Android Application Development Tutorials playlist (200 videos) by thenewboston on YouTube to learn developing android applications:
               

Here you will learn about:

  • Setting up your android development environment in detail
  • Layouts
  • Use of various inbuilt classes and its methods
And much more..!  

12 May 2015

Solution to the problem faced while syncing data with excel using java applet

In previous posts, we saw java programs in which we used applet to sync the entered data in the excel sheet. But when you run the program, you would face problem while writing the data to the file and opening of the file using applet's button. So add:

grant{
permission java.security.AllPermission;
}


statement in java.policy (C:\Program Files\Java\jdk1.8.0_05\jre\lib\security)
file.



17 Oct 2014

Age Calculator using Java Applet

This program demonstrates:
  • The use of various layouts and panels in Java Applet
  • The use of User defined Exceptions
  • The use of Thread
  • The use of GregorianCalendar Class

Code:

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

/*
<applet code="AgeCalc.class" height=150 width=500>
</applet>
*/

class FieldEmptyException extends Exception
{
    FieldEmptyException()
    {
    }
}

public class AgeCalc extends Applet implements Runnable,ActionListener
{
Choice ch1,ch2;
TextField tf1;
Button b1,b2;
Panel p1,p2,p3,p4;
Label l0,l1,l2;
int x=0;
    public void init()
    {
    Thread t=new Thread(this);
    t.start();
    setLayout(new BorderLayout());
    p1=new Panel(new GridLayout(3,1));
    p2=new Panel(new FlowLayout(FlowLayout.CENTER));
    p3=new Panel(new FlowLayout(FlowLayout.CENTER));
    p4=new Panel(new FlowLayout(FlowLayout.CENTER));
    add("South",p1);
    p1.add(p2);
    p1.add(p3);
    p1.add(p4);
    l1=new Label("The program assumes that every month is of 30 days.");
    l0=new Label("Enter Date of Birth:");
    ch1=new Choice();
        for(int i=1;i<31;i++)
        {
        String str=String.valueOf(i);
        ch1.add(str);
        }
    ch2=new Choice();
    ch2.add("Jan");
    ch2.add("Feb");
    ch2.add("March");
    ch2.add("April");
    ch2.add("May");
    ch2.add("June");
    ch2.add("July");
    ch2.add("Aug");
    ch2.add("Sept");
    ch2.add("Oct");
    ch2.add("Nov");
    ch2.add("Dec");
    tf1=new TextField(4);
    p2.add(l0);
    p2.add(ch1);
    p2.add(ch2);
    p2.add(tf1);
    b1=new Button("Calculate Age");
    b2=new Button("Reset");
    p3.add(b1);
    p3.add(b2);
    l2=new Label(".......................................................................................................",Label.CENTER);
    p4.add(l2);
    b1.addActionListener(this);
    b2.addActionListener(this);
    }
   
    public void actionPerformed(ActionEvent ae)
    {
        if(ae.getSource()==b1)
        {
        int ds,ms,ys,dg,mg,yg,dans,mans,yans;
        String str1,str2,str3;
        GregorianCalendar gcalendar=new GregorianCalendar();
        str1=ch1.getSelectedItem();
        str3=tf1.getText();
        dg=gcalendar.get(Calendar.DATE);
        try
        {
        if(str3.length()==0)
        {
        throw new FieldEmptyException();
        }
       
        else
        {
        dg=gcalendar.get(Calendar.DATE);
            if(dg==31)
            {
            dg=30;
            showStatus("Today is thirty first but the program will consider thirtieth.");
            }
        ds=Integer.parseInt(str1);
        ms=ch2.getSelectedIndex()+1;
        ys=Integer.parseInt(str3);
        mg=gcalendar.get(Calendar.MONTH)+1;
        yg=gcalendar.get(Calendar.YEAR);
        System.out.println("Your Date of Birth is:"+ds+"/"+ms+"/"+ys);
        System.out.println("Today's Date is:"+dg+"/"+mg+"/"+yg);
            if(ms>mg)
            {
            yans=((yg-1)-ys);
            mans=(12-(ms-mg));
            dans=(ds-dg);
                if(dans<0)
                {
                dans=(dg-ds);
                }
                    if(ds>dg)
                    {
                    mans--;
                    dans=30-dans;
                    }
            l2.setText("Today, your approx. age is "+yans+" year/s,"+mans+" month/s,"+dans+" day/s.");
            }
            else
            {
            yans=yg-ys;
            mans=mg-ms;
            dans=(ds-dg);
                if(dans<0)
                {
                dans=(dg-ds);
                }
                    if(ds>dg)
                    {
                    mans--;
                    dans=30-dans;
                    }
            l2.setText("Today, your approx. age is "+yans+" year/s,"+mans+" month/s,"+dans+" day/s.");
            }
        }
        }
        catch(FieldEmptyException fee)
        {
        showStatus("Year textfield empty.");
        }
       
        }
        else if(ae.getSource()==b2)
        {
        ch1.select(0);
        ch2.select(0);
        tf1.setText("");
        l2.setText(".......................................................................................................");
        }
    }
   
    public void run()
    {
        try
        {
        while(true)
        {
            for(int i=0;i<20;i++)
            {
            Thread.sleep(250);
            repaint();
            }
        x=0;
        }
        }
        catch(Exception e)
        {
        }
    }
   
    public void paint(Graphics g)
    {
    String strHead=l1.getText();
    g.setColor(Color.RED);
    g.drawString(strHead,x,30);
    x+=10;
    }
}

Snapshots:



10 Oct 2014

Program demonstrating Java Applet

This program will help you to understand:
  • Using various Layouts in Applet
  • Use of Threads to do simple 2D animations
  • User defined Exception Handling (Exception generated when user clicks the button and the required text fields are kept empty)

Code:

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.io.*;

/*
<applet code="BizzApp1.class" height=250 width=500>
</applet>
*/

class FieldZeroException extends Exception
{
String strE2;
    FieldZeroException()
    {
    }
    FieldZeroException(String strE1)
    {
    strE2=strE1;
    }
   
    public String toString()
    {
    return strE2+" TextField/s empty.";
    }
}

public class BizzApp1 extends Applet implements Runnable,ActionListener,ItemListener
{
Panel p2,pn,ps;
Choice ch;
Label l1,l2,l3,l4,l5,l6,fl;
Button b1,b2,b3,b4,b5;
TextField tf1,tf2,tf3,tf4;
Frame f;
int x=-190,a=0,b=0,d=0;
double pm=0.15,tm=0.1,wm=0.05;
String str1,str2,str3,str4,str5,str6;
double sal,fsal;
    public void init()
    {
    Thread t=new Thread(this);
    t.start();
    setLayout(new BorderLayout());
    Color c1=new Color(253,210,154);
    setBackground(c1);
    Color c2=new Color(81,44,30);
    setForeground(c2);
    f=new Frame("BizzApp Version");
    f.setSize(250,100);
    Color cf1=new Color(225,186,143);
    Color cf2=new Color(220,96,22);
    f.setBackground(cf1);
    f.setForeground(cf2);
    fl=new Label("BizzApp v1.1");
    Font flabel=new Font("Times New Roman",Font.BOLD,30);
    fl.setFont(flabel);
    f.setLayout(new FlowLayout(FlowLayout.CENTER));
    f.add(fl);
    p2=new Panel(new BorderLayout());
    pn=new Panel(new GridLayout(5,2,0,10));
    ps=new Panel(new FlowLayout(FlowLayout.CENTER));
    ch=new Choice();
    l1=new Label("BizzApp");
    l2=new Label("ID:");
    l3=new Label("Name:");
    l4=new Label("Designation:");
    l5=new Label("Salary:");
    l6=new Label("Calculated Salary:");
    b1=new Button("Calculate");
    b2=new Button("Save");
    b3=new Button("Reset");
    b4=new Button("View");
    b5=new Button("About");
    tf1=new TextField(20);
    tf2=new TextField(20);
    tf3=new TextField(20);
    tf4=new TextField(20);
    tf4.setText("--------auto--------");
    add("South",p2);
    p2.add("North",pn);
    p2.add("South",ps);
    pn.add(l2);
    pn.add(tf1);
    pn.add(l3);
    pn.add(tf2);
    pn.add(l4);
    pn.add(ch);
    ch.add("Project Manager");
    ch.add("Team Member");
    ch.add("Work Man");
    pn.add(l5);
    pn.add(tf3);
    pn.add(l6);
    pn.add(tf4);
    ps.add(b1);
    ps.add(b2);
    ps.add(b3);
    ps.add(b4);
    ps.add(b5);
        try
        {
        File file1=new File("BizzApp.xls");
            if(!file1.exists())
            {
            file1.createNewFile();
            FileWriter fw1=new FileWriter("BizzApp.xls",true);
            String header="ID\tName\tDesignation\tSalary\tBonus(%)\tCalculated Salary\n";
            fw1.write(header);
            fw1.close();
            }
        }
        catch(Exception e)
        {
        }
    b1.addActionListener(this);
    b2.addActionListener(this);
    b3.addActionListener(this);
    b4.addActionListener(this);
    b5.addActionListener(this);
    ch.addItemListener(this);
    f.addWindowListener(new WindowAdapter(){
        public void windowClosing(WindowEvent we)
        {
        f.dispose();
        }
    });
    }
   
    public void itemStateChanged(ItemEvent ie)
    {
    }
   
    public void run()
    {
    while(true)
    {
    for(int i=0;i<70;i++)
    {
        try
        {
        repaint();
        Thread.sleep(250);
        }
        catch(Exception e)
        {
        }
    }
    x=-190;
    }
    }
    public double getBonus()
    {
    Double bonus=0.0;
            if(str3=="Project Manager")
                bonus=(pm*100);
            else if(str3=="Team Member")
                bonus=(tm*100);
            else if(str3=="Work Man")
                bonus=(wm*100);
    return bonus;
    }
   
   
    public void actionPerformed(ActionEvent ae)
    {
       
        if(ae.getSource()==b1)
        {
        str3=ch.getSelectedItem();
        str4=tf3.getText();
        d=str4.length();
            try
            {
                if(d==0)
                {
                String salEmpty="Salary";
                throw new FieldZeroException(salEmpty);
                }
                else
                {
                sal=Double.parseDouble(str4);
                    if(str3=="Project Manager")
                    {
                    fsal=sal+(sal*pm);
                    }
                    else if(str3=="Team Member")
                    {
                    fsal=sal+(sal*tm);
                    }
                    else if(str3=="Work Man")
                    {
                    fsal=sal+(sal*wm);
                    }
                String ans=String.valueOf(fsal);
                tf4.setText(ans);
                showStatus("Final Salary calculated with bonus of "+Math.round(((fsal-sal)/sal)*100)+"%.");
                }
            }
            catch(FieldZeroException fze1)
            {
            showStatus(fze1.toString());
            }
        }
       
        else if(ae.getSource()==b2)
        {
        str1=tf1.getText();
        str2=tf2.getText();
        str3=ch.getSelectedItem();
        str4=tf3.getText();
        str5=String.valueOf(this.getBonus());
        str6=tf4.getText();
        a=str1.length();
        b=str2.length();
        d=str4.length();
            try
            {
                if(a==0 && b==0 && d==0)
                {
                String all="All";
                throw new FieldZeroException(all);
                }
                else if(a==0 || b==0 || d==0)
                {
                String any="Any";
                throw new FieldZeroException(any);
                }
                else
                {
                    try
                    {
                    FileWriter fw2=new FileWriter("BizzApp.xls",true);
                    String row=str1+"\t"+str2+"\t"+str3+"\t"+str4+"\t"+str5+"\t"+str6+"\n";
                    fw2.write(row);
                    fw2.close();
                    showStatus("Saved Successfully.");
                    }
                    catch(Exception e)
                    {
                    }
                }
            }
            catch(FieldZeroException fze2)
            {
            showStatus(fze2.toString());
            }
       
        }
       
        else if(ae.getSource()==b3)
        {
        tf1.setText("");
        tf2.setText("");
        tf3.setText("");
        tf4.setText("--------auto--------");
        }
       
        else if(ae.getSource()==b4)
        {
            try
            {
            Runtime.getRuntime().exec("cmd /c start BizzApp.xls");
            }
            catch(Exception e)
            {
            }
        }
       
        else if(ae.getSource()==b5)
        {
        f.setVisible(true);
        }
    }
   
    public void paint(Graphics g)
    {
    String strHead=l1.getText();
    Font f=new Font("Courier",Font.BOLD+Font.ITALIC,45);
    g.setFont(f);
    Color cg=new Color(91,74,38);
    g.setColor(cg);
    g.drawString(strHead,x,40);
    x+=10;
    }
}

7 Oct 2014

Resume Builder [Java Applet]

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

/*
<applet code="ResumeBuilder.class" height=600 width=500>
</applet>
*/

public class ResumeBuilder extends Applet implements ActionListener
{
Button b1,b2;
Label l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14,l15;
TextField tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8,tf9,tf10;
TextArea ta1,ta2,ta3,ta4;
Panel p1,p2;
String str1,str2,str3,str4,str5,str6,str7,str8,str9,str10,str11,str12,str13,str14;
    public void init()
    {
    Color bg=new Color(242,189,125);
    Color fg=new Color(162,65,44);
    Color tt=new Color(255,82,0);
    setBackground(bg);
    setForeground(fg);
    Font f1=new Font("Courier",Font.BOLD,30);
    p1=new Panel(new GridLayout(14,2,15,15));
    p2=new Panel(new FlowLayout(FlowLayout.CENTER));
    setLayout(new BorderLayout());
    l1=new Label("Resume Builder",Label.CENTER);
    l1.setFont(f1);
    l1.setForeground(tt);
    l2=new Label("Name:");
    l3=new Label("Address:");
    l4=new Label("Telephone No.");
    l5=new Label("E-mail:");
    l6=new Label("Date of Birth:");
    l7=new Label("HSC passing year:");
    l8=new Label("HSC Board:");
    l9=new Label("HSC result:");
    l10=new Label("College passing year:");
    l11=new Label("University name:");
    l12=new Label("CGPA:");
    l13=new Label("Achievements:");
    l14=new Label("Area of Interest:");
    l15=new Label("Skill & Hobby:");
    b1=new Button("Create");
    b2=new Button("View");
    tf1=new TextField(20);
    tf2=new TextField(20);
    tf3=new TextField(20);
    tf4=new TextField(20);
    tf5=new TextField(20);
    tf6=new TextField(20);
    tf7=new TextField(20);
    tf8=new TextField(20);
    tf9=new TextField(20);
    tf10=new TextField(20);
    ta1=new TextArea(1,20);
    ta2=new TextArea(1,20);
    ta3=new TextArea(1,20);
    ta4=new TextArea(1,20);
    add("North",l1);
    add("Center",p1);
    add("South",p2);
    p1.add(l2);
    p1.add(tf1);
    p1.add(l3);
    p1.add(ta1);
    p1.add(l4);
    p1.add(tf2);
    p1.add(l5);
    p1.add(tf3);
    p1.add(l6);
    p1.add(tf4);
    p1.add(l7);
    p1.add(tf5);
    p1.add(l8);
    p1.add(tf6);
    p1.add(l9);
    p1.add(tf7);
    p1.add(l10);
    p1.add(tf8);
    p1.add(l11);
    p1.add(tf9);
    p1.add(l12);
    p1.add(tf10);
    p1.add(l13);
    p1.add(ta2);
    p1.add(l14);
    p1.add(ta3);
    p1.add(l15);
    p1.add(ta4);
    p2.add(b1);
    p2.add(b2);
    b1.addActionListener(this);
    b2.addActionListener(this);
    }
   
    public void transfer()
    {
    str1=tf1.getText();
    str2=ta1.getText();
    str3=tf2.getText();
    str4=tf3.getText();
    str5=tf4.getText();
    str6=tf5.getText();
    str7=tf6.getText();
    str8=tf7.getText();
    str9=tf8.getText();
    str10=tf9.getText();
    str11=tf10.getText();
    str12=ta2.getText();
    str13=ta3.getText();
    str14=ta4.getText();
    }
   
    public void actionPerformed(ActionEvent ae)
    {
        if(ae.getSource()==b1)
        {
        this.transfer();
            try
            {
            File file=new File("Resume.doc");
                if(file.exists()==true)
                {
                file.delete();
                }
            file.createNewFile();   
            FileWriter fw1=new FileWriter("Resume.doc",true);
            fw1.write("Name:"+str1+"\n\n");
            fw1.write("Address:"+str2+"\n\n");
            fw1.write("Telephone No.:"+str3+"\n\n");
            fw1.write("E-mail:"+str4+"\n\n");
            fw1.write("Date of Birth:"+str5+"\n\n");
            fw1.write("HSC passing year:"+str6+"\n\n");
            fw1.write("HSC Board:"+str7+"\n\n");
            fw1.write("HSC result:"+str8+"\n\n");
            fw1.write("College passing year:"+str9+"\n\n");
            fw1.write("University name:"+str10+"\n\n");
            fw1.write("CGPA:"+str11+"\n\n");
            fw1.write("Achievements:"+str12+"\n\n");
            fw1.write("Area of Interest:"+str13+"\n\n");
            fw1.write("Skill & Hobby:"+str14);
            fw1.close();
            }
            catch(Exception e)
            {
            }
        }
       
        else if(ae.getSource()==b2)
        {
            try
            {
            Process p=Runtime.getRuntime().exec("cmd /c start Resume.doc");
            }
            catch(Exception e)
            {
            }
        }
    }
}

Snapshots: