Thursday, 29 October 2015

simple pic puzzle game with java



images are  available in the following folder:
https://drive.google.com/folderview?id=0B-lUMire6Uw_RUVOd0dsaU1BZVk&usp=sharing


 import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class picpuz2 extends JFrame implements ActionListener

{
   JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,sample;
   Icon star;
   public picpuz2()
   {

   super("picture puzzel");

   JFrame f=new JFrame();


   b1 = new JButton( new ImageIcon("minions-character-21.jpg") );

   b3 = new JButton(new ImageIcon("minions-character-21_2.jpg"));
   b6 = new JButton(new ImageIcon("minions-character-21_3.jpg"));
   b5 = new JButton(new ImageIcon("minions-character-21_4.jpg"));
   b2 = new JButton(new ImageIcon("minions-character-21_5.jpg"));
   b9 = new JButton(new ImageIcon("minions-character-21_10.jpg"));
   b4 = new JButton(new ImageIcon("minions-character-21_7.jpg"));
   b7 = new JButton(new ImageIcon("minions-character-21_8.jpg"));
   b8 = new JButton(new ImageIcon("minions-character-21_9.jpg"));
   b10 = new JButton(new ImageIcon("change.jpg"));
   sample=new JButton(new ImageIcon("1.jpg"));
   star =b9.getIcon();

    b1.setBounds(10,80,332,247);
    b2.setBounds(342,80,332,247);
    b3.setBounds(674,80,332,247);
    b4.setBounds(10,327,332,247);
    b5.setBounds(342,327,332,247);
    b6.setBounds(674,327,332,247);
    b7.setBounds(10,574,332,247);
    b8.setBounds(342,574,332,247);
    b9.setBounds(674,574,332,247);
    sample.setBounds(1130,330,100,80);
    b10.setBounds(445,22,70,50);

    f.add(b1);

    f.add(b2);
    f.add(b3);
    f.add(b4);
    f.add(b5);
    f.add(b6);
    f.add(b7);
    f.add(b8);
    f.add(b9);
    f.add(b10);
    f.add(sample);

     JLabel l1=new JLabel("Sample:");

     l1.setBounds(1018,350,120,50);
     l1.setFont(new Font("TIMES NEW ROMAN",Font.BOLD,30));
     JLabel l2=new JLabel("NOTE: icon has power to swap with neighbor icon=>");
     l2.setBounds(0,0,900,100);
     l2.setFont(new Font("TIMES NEW ROMAN",Font.BOLD,20));
     JLabel l3=new JLabel("click on sample picture to next");
     l3.setBounds(1020,410,900,50);
     l3.setForeground(Color.red);
     l3.setFont(new Font("TIMES NEW ROMAN",Font.BOLD,20));

     f.add(l1);

     f.add(l2);
     f.add(l3);

         b1.addActionListener(this);

          b2.addActionListener(this);
          b3.addActionListener(this);
          b4.addActionListener(this);
          b5.addActionListener(this);
          b6.addActionListener(this);
          b7.addActionListener(this);
          b8.addActionListener(this);
          b9.addActionListener(this);



    f.setLayout(null);

    f.setSize(600,500);
    f.setVisible(true);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}


public void actionPerformed(ActionEvent e)
{

if(e.getSource()==b1)

    {
    Icon s1=b1.getIcon();
      if(b2.getIcon()==star){
        b2.setIcon(s1);
        b1.setIcon(star);
      }
      else if(b4.getIcon()==star)
      {
                    b4.setIcon(s1);
                    b1.setIcon(star);
                   }
  }//end of if

if(e.getSource()==b2){

    Icon s1=b2.getIcon();
      if(b1.getIcon()==star){
        b1.setIcon(s1);
        b2.setIcon(star);
      } else if(b5.getIcon()==star){
                    b5.setIcon(s1);
                    b2.setIcon(star);
                   }
         else if(b3.getIcon()==star){
                    b3.setIcon(s1);
                    b2.setIcon(star);
                   }
  }//end of if

if(e.getSource()==b3){

    Icon s1=b3.getIcon();
      if(b2.getIcon()==star){
        b2.setIcon(s1);
        b3.setIcon(star);
      } else if(b6.getIcon()==star){
                    b6.setIcon(s1);
                    b3.setIcon(star);
                   }
  }//end of if

if(e.getSource()==b4){

    Icon s1=b4.getIcon();
      if(b1.getIcon()==star){
        b1.setIcon(s1);
        b4.setIcon(star);
      } else if(b5.getIcon()==star){
                    b5.setIcon(s1);
                    b4.setIcon(star);
                   }
         else if(b7.getIcon()==star){
                    b7.setIcon(s1);
                    b4.setIcon(star);
                   }
  }//end of if

if(e.getSource()==b5){

    Icon s1=b5.getIcon();
      if(b2.getIcon()==star){
        b2.setIcon(s1);
        b5.setIcon(star);
      } else if(b4.getIcon()==star){
                    b4.setIcon(s1);
                    b5.setIcon(star);
                   }
         else if(b6.getIcon()==star){
                    b6.setIcon(s1);
                    b5.setIcon(star);
                   }
          else if(b8.getIcon()==star){
                    b8.setIcon(s1);
                    b5.setIcon(star);
                   }
  }//end of if

if(e.getSource()==b6){

    Icon s1=b6.getIcon();
      if(b3.getIcon()==star){
        b3.setIcon(s1);
        b6.setIcon(star);
      } else if(b5.getIcon()==star){
                    b5.setIcon(s1);
                    b6.setIcon(star);
                   }
         else if(b9.getIcon()==star){
                    b9.setIcon(s1);
                    b6.setIcon(star);
                   }
}//end of if

if(e.getSource()==b7){

    Icon s1=b7.getIcon();
      if(b4.getIcon()==star){
        b4.setIcon(s1);
        b7.setIcon(star);
      } else if(b8.getIcon()==star){
                    b8.setIcon(s1);
                    b7.setIcon(star);
                   }
 }//end of if

   if(e.getSource()==b8){

    Icon s1=b8.getIcon();
      if(b7.getIcon()==star){
        b7.setIcon(s1);
        b8.setIcon(star);
      } else if(b5.getIcon()==star){
                    b5.setIcon(s1);
                    b8.setIcon(star);
                   }
         else if(b9.getIcon()==star){
                    b9.setIcon(s1);
                    b8.setIcon(star);
                   }

  }//end of if


 if(e.getSource()==b9){

    Icon s1=b9.getIcon();
      if(b8.getIcon()==star){
        b8.setIcon(s1);
        b9.setIcon(star);
      } else if(b6.getIcon()==star){
                    b6.setIcon(s1);
                    b9.setIcon(star);
                   }
  }//end of if

}



    public static void main(String args[])

     {
      new picpuz2();
     }//end of main
}
//end of class


Friday, 27 March 2015

constructor in inheritance


constructor call in derived class:

#include<iostream>
#include<conio.h>
using namespace std;
class base
{
    public:

    base()   //1st cal  instructor
    {
        cout<<"   base constructor calling"<<endl;

    }


};

class derive:public base
{
    public:
    derive() :base() //2nd call
    {
        cout<<"   derive constructor calling"<<endl;
    }

};

int main()
{

     derive obj;

     getch();
     return(0);

}


parametrized constructor call in inheritance:


#include<iostream>
#include<conio.h>
using namespace std;
class alpha
{

    int x;
public:
    alpha(int i)
    {

        x=i;
        cout<<"alpha intialized"<<endl;
        cout<<"x:  "<<x<<'\n';

    }
};

class beta
{
    int y;
public:

    beta(int j)
    {

         y=j;
        cout<<"beta is  intialized"<<endl;
        cout<<"y:  "<<y<<'\n';

    }
};

class gamma:public beta,public alpha
{

    int m,n;
public:
    gamma(int a,int b) : alpha(a),beta(b)
    {
        m=a;
        n=b;
        cout<<"m:  "<<m<<endl;
        cout<<"n:  "<<n<<endl;

    }


};
int main()
{
    gamma obj(5,10);
    cout<<"  "<<endl;
    getch();

    return(0);



}

Tuesday, 24 March 2015

Types of inheritance practical

practical 5:Inheritance

MULTILEVEL INHERITANCE:
 
#include<iostream>
#include<conio.h>
using namespace std;
class rectangle
{
protected:
    float length;
    float width;
public:
    void setlength()
    {
        cout<<"your length:  "<<endl;
        cin>>length;
        cout<<"your width:   "<<endl;
        cin>> width;
    }
};
class area : public rectangle
{
 public:
    float calc()
    {
        return(length*width);
    }
};
class peri: public area
{
    public:
    float calc1()
    {
        return (2*(length*width));
    }
};
int main()
{
    peri a;
    cout<<"enter the data for first rectangle to find the area:  "<<endl;
    a.setlength();
    cout<<"area is :   "<< a.calc() <<"sq/m"<<endl;
    cout<<"enter the data for  rectangle to find the perimeter:  "<<endl;
    a.setlength();
    cout<<"perimeter is:   "<< a.calc1() << "m" <<endl;
    getch();
    return(0);
}



MULTIPLE INHERITANCE :


#include<iostream>
#include<conio.h>
using namespace std;
class student
{

    protected:
    int no,m1,m2;
    public:
        student()
        {
            cout<<"enter the roll no. "<<endl;
            cin>>no;
            cout<<"enter the marks of two subject  "<<endl;
            cin>>m1>>m2;
        }

};


class sports
{
    protected:
    int spo;
    public:
        sports()
        {


           cout<<"enter the sports marks:  "<<endl;
           cin>>spo;
        }

};


class statement : public student ,public sports
{
    float total,avg;


    public:
    void display()
    {
        total=(m1+m2+spo);
        avg=total/3;
        cout<<"total marks is :  "<<total<<endl;
        cout<<"average is :       "<<avg<<endl;

    }



};


int main()
{
    statement obj;
    obj.display();

    getch();
    return(0);


}


Hierarchical inheritance:


#include<iostream>
#include<conio.h>
using namespace std;
class A          //base class
{
protected:
    int a;
public:
    void getnumber()
    {
        cout<<"enter the number  :...."<<endl;
        cin>>a;

    }
};

class B:public A
{
   public:
        int squr()
       {
           cout<<"square is  :  "<<(a*a)<<endl;
       }


};

class C :public A
{

    public:



        void qube()

    {



        cout<<"qube  is :  "<<(a*a*a)<<endl;;


    }

};


int main()
{
    B b1;
    b1.getnumber();
    b1.squr();
    C  c1 ;
    c1.getnumber();
    c1.qube();

    getch();
    return(0);

}



Hybrid inheritance:



#include<iostream>
#include<conio.h>
using namespace std;


class arithmetic
{
protected:
int num1, num2;
public:
void getdata()
{
cout<<"For Addition:";
cout<<"\nEnter the first number: ";
cin>>num1;
cout<<"\nEnter the second number: ";
cin>>num2;
}
};


class plusl:public arithmetic
{
protected:
int sum;
public:
void add()
{
sum=num1+num2;
}
};


class minusl
{
protected:
int n1,n2,diff;
public:
void sub()
{
cout<<"\nFor Subtraction:";
cout<<"\nEnter the first number: ";
cin>>n1;
cout<<"\nEnter the second number: ";
cin>>n2;
diff=n1-n2;
}
};


class result:public plusl, public minusl
{
public:
void display()
{
cout<<"\nSum of "<<num1<<" and "<<num2<<"= "<<sum;
cout<<"\nDifference of "<<n1<<" and "<<n2<<"= "<<diff;
}
};


int  main()
{
result z;
z.getdata();
z.add();
z.sub();
z.display();
getch();
return(0);
}






 

Saturday, 7 March 2015

basic program on constructor and destructor

Example on constructor and destructor :


#include<iostream>
#include<conio.h>
using namespace std;
  static int countl;
 class test
 {

 public:
    test()
    {
        countl++;
         cout<<"\t\t  constructor msg:object"                <<countl<<"created....."<<endl;
    }


    ~test()
    {

        cout<<"\t\t  destructor msg:object  "   <<countl<<"destroy....."<<endl;
          countl--;
    }
 };


 int main()
 {

     cout<<"inside block...."<<endl<<endl;
     cout<<"creat object....."<<endl;

    {


         test t1;


      {
         cout<<"inside main block.."<<endl;
          cout<<"creat another two  object....."<<endl;
          test t2,t3;
          cout<<"leave the block....."<<endl;

        }

}

        cout<<"back to main block....."<<endl;
     getch();
     return(0);



 }

Monday, 16 February 2015

Function In c++(practicla 2)

Practical -2

  •  Wite a program to demonstrate inline function.
#include<iostream>
using namespace std;

inline float max1(float a,float b);
int main()
{
    float a,b;
    float result;
    cout<<"write the value of a";
    cin>>a;
    cout<<"write the value of b";
    cin>>b;
     result=max1(a,b);
    cout<<"max("<<a<<","<<b<<"):  "<<endl;
    cout<<result<<endl;

    return(0);

}
inline float max1(float a,float b)
{
    return(  (a>b)? a:b );
}

  • Wite a program to demonstrate overloading of function. 

#include<iostream>
using namespace std;
void test(int);           //function 1
void test(int ,float);   //function 2
void test(float);        //function 3
int main()
{

    int a=50;
    float b=23.26;
    test(a);   //call fun1
    test(b);    //call fun3
    test(a,b);  //call fun2

    return(0);


}

void test(int a )
{
    cout<<"Integer number: "<<a<<endl;
}

void test(float var)
{
    cout<<"Float number: "<<var<<endl;
}

void test(int var1, float var2)
{
    cout<<"Integer number: "<<var1<<endl;
    cout<<" And float number:"<<var2<<endl;
}
 

Tuesday, 10 February 2015

C++ code for 1st practical (intoduction to c++)

         SEMESTER 4: Object oriented programming with C++.



.check that given number is palindron or not :c++ code
 #include<iostream>
using namespace std;
int main()
{
  int number,temp;
  int sum=0,reminder;
  cout<<"give the number what you want"<<endl;
  cin>>number;
  temp=number;
  while(number !=0)
  {
      reminder=number%10;
      sum=sum+reminder*reminder*reminder;
      number=number/10;

  }
    if(sum == temp)
        cout<<"armstrong number"<<endl;
    else
         cout<<"not armstrong number"<<endl;


   return(0);

}

  • find the maximum among the three number
#include<iostream>
using namespace std;
int main()
{
     int a,b,c;
     cout<<"give your three numbers"<<endl;
     cout<<"value of a"<<endl;
     cin>>a;
     cout<<"value of b"<<endl;
     cin>>b;
     cout<<"value of c"<<endl;
     cin>>c;

     if(a>b)
     {
         if(a>c)
            cout<<a <<'\t'<<" is maximum among all three"<<endl;
         else
            cout<<c <<'\t'<<" is maximum among all three"<<endl;
     }

     if (b>a)
     {
         if(b>c)
            cout<<b <<'\t'<<"  is maximum among all three"<<endl;
         else
            cout<<c <<'\t'<<"  is maximum among all three"<<endl;
     }

         cout<<"*******"<<endl;
  
  return(0);

}

  • write a code for Fibonacci series up to 100.
#include<iostream>
using namespace std;
int main()
{
    int a=0,b=1,c=0;
    int i;
    cout<<"fibbo series of 1 to 100"<<endl;
    for(i=0;i<30;i++)
        {

             if(i<=1)
              c=i;
              else
               {
                   c=a+b;
                    a=b;
                    b=c;
                }

            if(c<=100)
            {
                cout<<c<<endl;
            }

         }
    return(0);
}
  • write a program to exchange the information of two variable using pass by reference.

    #include<iostream>
    using namespace std;
    int  swap(float &a,float &b);
    int main()
    {
        float a,b;
        cout<<"give the value of two variable"<<endl;
        cout<<"value of a is "<<endl;
        cin>>a;
        cout<<"value of b is "<<endl;
        cin>>b;
        swap(a,b);
         cout<<" 1.value of a is"<<a<<endl;
          cout<<" 1.value of b is"<<b<<endl;
    }
    int swap(float &a,float &b)
    {
        float t;
          t=a;
          a=b;
          b=t;
         return(0);

    }

Monday, 19 January 2015

strucrure and keywords of c language.


This blog inform you about the general structure and keywords of C language.

   C program basically has the following form:
  • Preprocessor Commands
  • Functions
  • Variables
  • Statements & Expressions
  • Comments

The following program is written in the C programming language:
#include <stdio.h> 
 int main()
 { /* My first program */ 
 printf("Hello, World! \n"); 
 return 0; 
Preprocessor Commands: These commands tells the compiler to do preprocessing before doing actual compilation. Like #include <stdio.h> is a preprocessor command which tells a C compiler to include stdio.h file before going to actual compilation. You will learn more about C Preprocessors in C Preprocessors session.

Functions: are main building blocks of any C Program. Every C Program will have one or more functions and there is one mandatory function which is called main() function. This function is prefixed with keyword int which means this function returns an integer value when it exits. This integer value is returned using return statement.
The C Programming language provides a set of built-in functions. In the above example printf() is a C built-in function which is used to print anything on the screen. Check Builtin function section for more detail.
 You will learn how to write your own functions and use them in Using Function session.

Variables: are used to hold numbers, strings and complex data for manipulation. You will learn in detail about variables in C Variable Types.
 
Statements & Expressions : Expressions combine variables and constants to create new values. Statements are expressions, assignments, function calls, or control flow statements which make up C programs.
Comments: are used to give additional useful information inside a C Program. All the comments will be put inside /*...*/ as given in the example above. A comment can span through multiple lines.

      Note the followings
  • C is a case sensitive programming language.
  •  It means in C printf and Printf will have different meanings. 
  • End of each C statement must be marked with a semicolon.
  •   Multiple statements can be one the same line.  
  • White Spaces (ie tab space and space bar ) are ignored. Statements can continue over multiple lines.