Sunday, 15 May 2016

Java code to check whether a number is power of two


import java.util.Scanner;

public class CheckPowerTwo {
   
     
    public static void main(String args[])
    {
    Scanner ob= new Scanner(System.in);
    int a,i;
    System.out.println("Enter an integer");
    a=ob.nextInt();
   
    for( i=0;i<a;i++)
    {
    if(a==Math.pow(2,i))
    { System.out.println("The number is power of two");break;
    }
   
    }
    if(i==a)
        System.out.println("The number is not power of two");
   
   
    }
   
}

Reading a file using FileInputStream in java

import java.io.FileInputStream;

public class ReadFile {
   
   
   
    public static void main(String args[])
        
           
    {  FileInputStream fin ;
    try{
  
    fin= new FileInputStream("C:\\Users\\user\\Desktop\\ash.txt");
    int c;
    while((c=fin.read())!=-1)
    {
       
       
        System.out.print((char)c);
    }
   
    }
    catch(Exception e){}
   
    } 
   
}

Student database GUI using java which adds the records to a text file


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.io.FileOutputStream;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public class StudentDatabase extends JFrame{
   static FileOutputStream fou;

  
   
    class Handler   implements ActionListener{

        @Override
        public void actionPerformed(ActionEvent e) {
           String s0 = "\r\n";
             byte h0[]=s0.getBytes();
           String s="    ";
           byte h[]=s.getBytes();
            String s1= t1.getText();
            byte h1[]=s1.getBytes();
            String s2= t2.getText();
            byte h2[]=s2.getBytes();
            String s3= t3.getText();
            byte h3[]=s3.getBytes();
            String s4= t4.getText();
            byte h4[]=s4.getBytes();
            String s5= t5.getText();
            byte h5[]=s5.getBytes();

   try{
fou.write(h1);
fou.write(h);
fou.write(h2);
fou.write(h);
fou.write(h3);
fou.write(h);
fou.write(h4);
fou.write(h);
fou.write(h5);
fou.write(h0);
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
JOptionPane j= new JOptionPane();
     j.showMessageDialog(rootPane, "RECORD ADDED");

   }
   catch(Exception ee)
   {}
         
        }
       }
     JTextField t1;
   JTextField t2;
    JTextField t3;
     JTextField t4;
      JTextField t5;
      JButton b;
    StudentDatabase()
    {b= new JButton("ADD");
    Handler k = new Handler();
    b.setBounds(50, 250, 70, 30);
    b.addActionListener(k);
          JLabel j1= new JLabel("STUDENT DATABASE");
    j1.setBounds(90, 30,140, 20);
    t1= new JTextField();
    t1.setBounds(200,50,150,20);
    JLabel j2= new JLabel("STUDENT NAME");
    j2.setBounds(50, 50,150, 20);
    t2= new JTextField();
    t2.setBounds(200,80,150,20);
       JLabel j3= new JLabel("STUDENT ROLL. NO.");
    j3.setBounds(50, 80,150, 20);
     JLabel j4= new JLabel("STUDENT BRANCH");
    j4.setBounds(50, 110,150, 20);
    t3= new JTextField();
    t3.setBounds(200,110,150,20);
     JLabel j5= new JLabel("DOB");
    j5.setBounds(50, 140,150, 20);
    t4= new JTextField();
    t4.setBounds(200,140,150,20);
        JLabel j6= new JLabel("STUDENT SECTION");
    j6.setBounds(50, 170,150, 20);
    t5= new JTextField();
    t5.setBounds(200,170,150,20);
    add(j1);
    add(t1);
    add(j2);
    add(t2);
    add (b);
add(t3);
add(t4);
add(t5);
    add(j3);
       add(j4);
          add(j5);
             add(j6);
            
        setSize(400, 400);
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(null);
    setVisible(true);
   
    }
      public static void main(String args[])
         {  new   StudentDatabase();
 
    try{ fou= new FileOutputStream("C:\\Users\\user\\Desktop\\aa.txt");}
    catch(Exception ee)
    {}
   
}
}

-------------------------------------------------------------

import java.io.FileInputStream;

public class ReadFile {
   
   
   
    public static void main(String args[])
        
           
    {  FileInputStream fin ;
    try{
  
    fin= new FileInputStream("C:\\Users\\user\\Desktop\\ash.txt");
    int c;
    while((c=fin.read())!=-1)
    {
       
       
        System.out.print((char)c);
    }
   
    }
    catch(Exception e){}
   
    } 
   
}

Saturday, 14 May 2016

GUI for weight conversion in java


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class WeightConv extends JFrame {
   
    class Handler implements ActionListener{

     
        public void actionPerformed(ActionEvent e) {
           
          String s= a1.getText();
          double d= Integer.parseInt(s);
              if(kg1.isSelected()&&kg2.isSelected())
              { a2.setText(s);
              }
       if(kg1.isSelected()&&pound2.isSelected())
       {   double pou= d*2.205;
         a2.setText( Double.toString(pou));
      
      
      
       }
            if(kg1.isSelected()&&ounce2.isSelected())
            { double ounce=d*35.274;
             a2.setText( Double.toString(ounce));}
           
            if(pound1.isSelected()&&kg2.isSelected())
            {  double kgs= d/2.205;
             a2.setText( Double.toString(kgs));}
              if(pound1.isSelected()&&pound2.isSelected())  
            a2.setText(s);
             
               if(pound1.isSelected()&&ounce2.isSelected())
               {double ounces=d/.0625;
                a2.setText( Double.toString(ounces));
               }
              if(ounce1.isSelected()&&kg2.isSelected())
              { double kgs2=d/35.274;
               a2.setText( Double.toString(kgs2));}
               if(ounce1.isSelected()&&pound2.isSelected())
             
               {double pounds2= d*.0625;
                a2.setText( Double.toString(pounds2));}
                if(ounce1.isSelected()&&ounce2.isSelected())
                 a2.setText(s);
           
        }
   
   
   
    }
   
   
   
JButton b;
JTextArea a2;
JTextField a1;
JCheckBox kg1;
  JCheckBox kg2;
    JCheckBox pound1;
     JCheckBox pound2;
     JCheckBox ounce1;
      JCheckBox ounce2;
    WeightConv()
    {Handler h= new Handler();
       
        JLabel l= new JLabel( "WEIGHT CONVERTER");
       l.setBounds(120, 0, 180, 20);
       add(l);
        JLabel l2= new JLabel( "INPUT UNIT");
       l2.setBounds(56, 65, 100, 10);
       add(l2);
       JLabel l3= new JLabel( "OUTPUT UNIT");
       l3.setBounds(230, 65, 100, 10);
       add(l3);
        b= new JButton("Convert");
      b.setBounds(120, 260, 100, 50);
      a1= new JTextField();
      a1.setBounds(120, 20, 100, 30);
      a2=new JTextArea();
      a2.setBounds(120, 310, 100, 40);
    kg1= new JCheckBox("KG");
    kg1.setBounds(50,110, 140, 20);
      kg2= new JCheckBox("KG");
       kg2.setBounds(230, 110, 140, 20);
        pound1= new JCheckBox("Pounds");
         pound1.setBounds(50, 160, 100,20);
          pound2= new JCheckBox("Pounds");
           pound2.setBounds(230, 160, 100,20);
            ounce1= new JCheckBox("Ounce");
            ounce1.setBounds(50, 210, 100,20);
              ounce2= new JCheckBox("Ounce");
                ounce2.setBounds(230, 210, 100,20);
              add(b);
              add(kg1);
              add(kg2);
              add(a1);
              add(a2);
              add(pound1);
              add(pound2);
              add(ounce1);
              add(ounce2);
              b.addActionListener(h);
             
             setSize(400, 400);
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(null);
    setVisible(true);
   
    }
   
   
   
   
    public static void main(String args[])
    { WeightConv obj= new WeightConv();}
   
}

Java code to check given number is even or odd


import java.util.Scanner;

public class CheckEven {
   
   
    public static void main(String args[])
    {
    Scanner ob= new Scanner(System.in);
    int a;
    System.out.println("Enter an integer");
    a=ob.nextInt();
    if(a%2==0)
        System.out.println("The Entered number is even");
    else
     System.out.println("The Entered number is odd");  
    }
   
   
}

Java code to check number is palindrome or not.

import java.util.Scanner;

public class CheckPalindrome {
   
      public static void main(String args[])
    {
    Scanner ob= new Scanner(System.in);
   double k;int a,count=0;
   double r=0;
    System.out.println("Enter an integer");
    a=ob.nextInt();
    int b=a;
    while(b!=0)  //loop to count number of digits in a
    {b=b/10;
    count++;
    }
   b=a;
  for(int i=count;i>0;i--)
  {k=b%10;
  k*= Math.pow(10,i-1);
  r+=k;
  b=b/10;
  }
    
    if(a==r)
         System.out.println("The number is a palindrome");
    else
         System.out.println("The number is not a palindrome");
    }
   
   
}

Java code to check whether number is prime or composite

import java.util.Scanner;
public class CheckPrime {
   
 
    public static void main(String args[])
    {
    Scanner ob= new Scanner(System.in);
    int a,i;
    System.out.println("Enter an integer");
    a=ob.nextInt();
    if(a==1)
        System.out.println("Number is prime");
    for(i=2;i<a;i++)
    {
     if(a%i==0) 
     {System.out.println("Number is composite");
     break;}
   
    }
    if(i==a)
        System.out.println("Number is prime");
   

}}

Sunday, 17 April 2016

Memory blocks game code in java


import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class Megame extends JFrame  {
   
   
    class Outr implements ActionListener,Runnable{
   
   
    public void actionPerformed(ActionEvent e) {
            if(e.getSource()==b1)
            {
                Thread t1= new Thread(new Outr(),"t1");
              
            b1.setBackground(Color.red);
             t1.start();
            }
                  if(e.getSource()==b2)
            {
                Thread t2= new Thread(new Outr(),"t2");
              
            b2.setBackground(Color.green);
             t2.start();
            }
                        if(e.getSource()==b3)
            {
                Thread t3= new Thread(new Outr(),"t3");
              
            b3.setBackground(Color.blue);
             t3.start();
            }
                              if(e.getSource()==b4)
            {
                Thread t4= new Thread(new Outr(),"t4");
              
            b4.setBackground(Color.PINK);
             t4.start();
            }
                                    if(e.getSource()==b5)
            {
                Thread t5= new Thread(new Outr(),"t5");
              
            b5.setBackground(Color.PINK);
             t5.start();
            }
                                          if(e.getSource()==b6)
            {
                Thread t6= new Thread(new Outr(),"t6");
              
            b6.setBackground(Color.blue);
             t6.start();
            }
                                                if(e.getSource()==b7)
            {
                Thread t7= new Thread(new Outr(),"t7");
              
            b7.setBackground(Color.green);
             t7.start();
            }
                                                    
          if(e.getSource()==b8)
                                                   
            {
                Thread t8= new Thread(new Outr(),"t8");
              
            b8.setBackground(Color.red);
             t8.start();
            }
                                                     
          if(e.getSource()==b9)
                                                   
            {
                Thread t9= new Thread(new Outr(),"t9");
              
            b9.setBackground(Color.cyan);
             t9.start();
            }
                 
                                                      
          if(e.getSource()==b10)
                                                   
            {
                Thread t10= new Thread(new Outr(),"t10");
              
            b10.setBackground(Color.MAGENTA);
             t10.start();
            }
         
                                                     
          if(e.getSource()==b11)
                                                   
            {
                Thread t11= new Thread(new Outr(),"t11");
              
            b11.setBackground(Color.cyan);
             t11.start();
            }
                                                     
          if(e.getSource()==b12)
                                                   
            {
                Thread t12= new Thread(new Outr(),"t12");
              
            b12.setBackground(Color.MAGENTA);
             t12.start();
            }
                                                     
          if(e.getSource()==b13)
                                                   
            {
                Thread t13= new Thread(new Outr(),"t13");
              
            b13.setBackground(Color.YELLOW);
             t13.start();
            }
                                                     
          if(e.getSource()==b14)
                                                   
            {
                Thread t14= new Thread(new Outr(),"t14");
              
            b14.setBackground(Color.BLACK);
             t14.start();
            }
                                                     
          if(e.getSource()==b15)
                                                   
            {
                Thread t15= new Thread(new Outr(),"t15");
              
            b15.setBackground(Color.YELLOW);
             t15.start();
            }
                                                     
          if(e.getSource()==b16)
                                                   
            {
                Thread t16= new Thread(new Outr(),"t16");
              
            b16.setBackground(Color.BLACK);
             t16.start();
            }
         

   
        }
   
   
    
         public void run() {
             count++;
          try{
          
             if((Thread.currentThread().getName()).equals("t1"))
                
             {
                
                 if(count%2==0) 
                 { Thread.sleep(200);
                     if(A2==1)
                            {
                            b1.setBackground(Color.red);
                          
                            b8.setBackground(Color.red);
                            }
             
                     else
                            {b1.setBackground(Color.white);
  A1=0;A2=0;C1=0;C2=0;D1=0;D2=0;E1=0;E2=0;F1=0;F2=0;G1=0;G2=0;H1=0;H2=0;I1=0;
    I2=0;
                            b8.setBackground(Color.white);
              }
             
              }
              else{
                     Thread.sleep(200);
                     b1.setBackground(Color.white);
            
              A1=1;
              }
             
             
                
               
       }
            
            if((Thread.currentThread().getName()).equals("t2"))
             {if(count%2==0) 
              {Thread.sleep(200);
              if(C2==1)
              {b2.setBackground(Color.green);
                   b7.setBackground(Color.green);
              }
             
              else{b2.setBackground(Color.white);
              A1=0;A2=0;C1=0;C2=0;D1=0;D2=0;E1=0;E2=0;F1=0;F2=0;G1=0;G2=0;H1=0;H2=0;I1=0;
    I2=0;
                   b7.setBackground(Color.white);
              }
             
              }
              else{
                 Thread.sleep(200);
              b2.setBackground(Color.white);
              C1=1;
              }
          
       } 
               if((Thread.currentThread().getName()).equals("t3"))
             {if(count%2==0) 
              { Thread.sleep(200);
              if(D2==1)
              {
                
                  b3.setBackground(Color.BLUE);
                   b6.setBackground(Color.BLUE);
              }
             
              else{b3.setBackground(Color.white);
              A1=0;A2=0;C1=0;C2=0;D1=0;D2=0;E1=0;E2=0;F1=0;F2=0;G1=0;G2=0;H1=0;H2=0;I1=0;
    I2=0;
                   b6.setBackground(Color.white);
              }
             
              }
              else{
                     Thread.sleep(200);
                     b3.setBackground(Color.white);
             
              D1=1;
              }
              }
            
            if((Thread.currentThread().getName()).equals("t4"))
             { if(count%2==0) 
                 { Thread.sleep(200);
                     if(E2==1)
                            {
                            b4.setBackground(Color.pink);
                            b5.setBackground(Color.pink);
                            }
             
                     else
                            {b4.setBackground(Color.white);
                            A1=0;A2=0;C1=0;C2=0;D1=0;D2=0;E1=0;E2=0;F1=0;F2=0;G1=0;G2=0;H1=0;H2=0;I1=0;
    I2=0;
                            b5.setBackground(Color.white);
              }
             
              }
              else{
                     Thread.sleep(200);
                     b4.setBackground(Color.white);
            
              E1=1;
              }
              }
           
              if((Thread.currentThread().getName()).equals("t5"))
             {if(count%2==0) 
              {Thread.sleep(200);
              if(E1==1)
              {b4.setBackground(Color.pink);
                   b5.setBackground(Color.pink);
              }
             
              else{b4.setBackground(Color.white);
              A1=0;A2=0;C1=0;C2=0;D1=0;D2=0;E1=0;E2=0;F1=0;F2=0;G1=0;G2=0;H1=0;H2=0;I1=0;
    I2=0;
                   b5.setBackground(Color.white);
              }
             
              }
              else{
                 Thread.sleep(200);
              b5.setBackground(Color.white);
              E2=1;
              }}
                if((Thread.currentThread().getName()).equals("t6"))
             {if(count%2==0) 
              {Thread.sleep(200);
              if(D1==1)
              {b3.setBackground(Color.BLUE);
                   b6.setBackground(Color.BLUE);
              }
             
              else{b3.setBackground(Color.white);
              A1=0;A2=0;C1=0;C2=0;D1=0;D2=0;E1=0;E2=0;F1=0;F2=0;G1=0;G2=0;H1=0;H2=0;I1=0;
    I2=0;
                   b6.setBackground(Color.white);
              }
             
              }
              else{
                 Thread.sleep(200);
              b6.setBackground(Color.white);
              D2=1;}
             }
               if((Thread.currentThread().getName()).equals("t7"))
             {if(count%2==0) 
              {Thread.sleep(200);
              if(C1==1)
              {b2.setBackground(Color.green);
                   b7.setBackground(Color.green);
              }
             
              else{b2.setBackground(Color.white);
              A1=0;A2=0;C1=0;C2=0;D1=0;D2=0;E1=0;E2=0;F1=0;F2=0;G1=0;G2=0;H1=0;H2=0;I1=0;
    I2=0;
             
                   b7.setBackground(Color.white);
              }
             
              }
              else{
                 Thread.sleep(200);
              b7.setBackground(Color.white);
              C2=1;
              }
          
       }
             if((Thread.currentThread().getName()).equals("t8"))
             { if(count%2==0) 
              {Thread.sleep(200);
              if(A1==1)
              {b1.setBackground(Color.red);
                   b8.setBackground(Color.red);
              }
             
              else{b1.setBackground(Color.white);
             A1=0;A2=0;C1=0;C2=0;D1=0;D2=0;E1=0;E2=0;F1=0;F2=0;G1=0;G2=0;H1=0;H2=0;I1=0;
    I2=0;
                   b8.setBackground(Color.white);
              }
             
              }
              else{
                 Thread.sleep(200);
              b8.setBackground(Color.white);
              A2=1;
              }
          
       }
            
               if((Thread.currentThread().getName()).equals("t10"))
                
             {
                
                 if(count%2==0) 
                 { Thread.sleep(200);
                     if(F2==1)
                            {
                            b10.setBackground(Color.MAGENTA);
                            b12.setBackground(Color.MAGENTA);
                            }
             
                     else
                            {b10.setBackground(Color.white);
                            A1=0;A2=0;C1=0;C2=0;D1=0;D2=0;E1=0;E2=0;F1=0;F2=0;G1=0;G2=0;H1=0;H2=0;I1=0;
    I2=0;
                            b12.setBackground(Color.white);
              }
             
              }
              else{
                     Thread.sleep(200);
                     b10.setBackground(Color.white);
            
              F1=1;
              }
                            
       }
          if((Thread.currentThread().getName()).equals("t12"))
             { if(count%2==0) 
              {Thread.sleep(200);
              if(F1==1)
              {b10.setBackground(Color.MAGENTA);
                   b12.setBackground(Color.MAGENTA);
              }
             
              else{b10.setBackground(Color.white);
              A1=0;A2=0;C1=0;C2=0;D1=0;D2=0;E1=0;E2=0;F1=0;F2=0;G1=0;G2=0;H1=0;H2=0;I1=0;
    I2=0;
                   b12.setBackground(Color.white);
              }
             
              }
              else{
                 Thread.sleep(200);
              b12.setBackground(Color.white);
              F2=1;
              }
          
       }
           if((Thread.currentThread().getName()).equals("t9"))
                
             {
                
                 if(count%2==0) 
                 { Thread.sleep(200);
                     if(G2==1)
                            {
                            b9.setBackground(Color.CYAN);
                            b11.setBackground(Color.CYAN);
                            }
             
                     else
                            {b9.setBackground(Color.white);
                            A1=0;A2=0;C1=0;C2=0;D1=0;D2=0;E1=0;E2=0;F1=0;F2=0;G1=0;G2=0;H1=0;H2=0;I1=0;
    I2=0;
                            b11.setBackground(Color.white);
              }
             
              }
              else{
                     Thread.sleep(200);
                     b9.setBackground(Color.white);
            
              G1=1;
              }
                            
       }
       
        if((Thread.currentThread().getName()).equals("t11"))
             { if(count%2==0) 
              {Thread.sleep(200);
              if(G1==1)
              {b9.setBackground(Color.CYAN);
                   b11.setBackground(Color.CYAN);
              }
             
              else{b9.setBackground(Color.white);
              A1=0;A2=0;C1=0;C2=0;D1=0;D2=0;E1=0;E2=0;F1=0;F2=0;G1=0;G2=0;H1=0;H2=0;I1=0;
    I2=0;
                   b11.setBackground(Color.white);
              }
             
              }
              else{
                 Thread.sleep(200);
              b11.setBackground(Color.white);
              G2=1;
              }
          
       }
        if((Thread.currentThread().getName()).equals("t13"))
                
             {Thread.sleep(200);
                
                 if(count%2==0) 
                 {
                     if(H2==1)
                            {
                            b13.setBackground(Color.YELLOW);
                            b15.setBackground(Color.YELLOW);
                            }
             
                     else
                            {b13.setBackground(Color.white);
                            A1=0;A2=0;C1=0;C2=0;D1=0;D2=0;E1=0;E2=0;F1=0;F2=0;G1=0;G2=0;H1=0;H2=0;I1=0;
    I2=0;
                            b15.setBackground(Color.white);
              }
             
              }
              else{
                     Thread.sleep(200);
                     b13.setBackground(Color.white);
            
              H1=1;
              }
                            
       }
        if((Thread.currentThread().getName()).equals("t15"))
             { if(count%2==0) 
              {Thread.sleep(200);
              if(H1==1)
              {b13.setBackground(Color.YELLOW);
                   b15.setBackground(Color.YELLOW);
              }
             
              else{b13.setBackground(Color.white);
              A1=0;A2=0;C1=0;C2=0;D1=0;D2=0;E1=0;E2=0;F1=0;F2=0;G1=0;G2=0;H1=0;H2=0;I1=0;
    I2=0;
                   b15.setBackground(Color.white);
              }
             
              }
              else{
                 Thread.sleep(200);
              b15.setBackground(Color.white);
              H2=1;
              }
          
       }
       
       
        if((Thread.currentThread().getName()).equals("t14"))
                
             {
                
                 if(count%2==0) 
                 { Thread.sleep(200);
                     if(I2==1)
                            {
                            b14.setBackground(Color.BLACK);
                            b16.setBackground(Color.BLACK);
                            }
             
                     else
                            {b14.setBackground(Color.white);
                            A1=0;A2=0;C1=0;C2=0;D1=0;D2=0;E1=0;E2=0;F1=0;F2=0;G1=0;G2=0;H1=0;H2=0;I1=0;
    I2=0;
                            b16.setBackground(Color.white);
              }
             
              }
              else{
                     Thread.sleep(200);
                     b14.setBackground(Color.white);
            
              I1=1;
              }
                            
       }
       
       
        if((Thread.currentThread().getName()).equals("t16"))
             { if(count%2==0) 
              {Thread.sleep(200);
              if(I1==1)
              {b14.setBackground(Color.BLACK);
                   b16.setBackground(Color.BLACK);
              }
             
              else{b14.setBackground(Color.white);
              A1=0;A2=0;C1=0;C2=0;D1=0;D2=0;E1=0;E2=0;F1=0;F2=0;G1=0;G2=0;H1=0;H2=0;I1=0;
    I2=0;
                   b16.setBackground(Color.white);
              }
             
              }
              else{
                 Thread.sleep(200);
              b16.setBackground(Color.white);
              I2=1;
              }
          
       }
       
          }   
        catch(Exception e)
        {}
   

if( (b1.getBackground()==Color.red)&&(b8.getBackground()==Color.red)&&(b2.getBackground()==Color.green)
        &&(b7.getBackground()==Color.green)&&(b3.getBackground()==Color.blue)&&(b6.getBackground()==Color.blue  )
        &&(b4.getBackground()==Color.pink)&&(b5.getBackground()==Color.pink)&&(b9.getBackground()==Color.cyan)&&(b11.getBackground()==Color.cyan)
        &&(b10.getBackground()==Color.MAGENTA)&&(b12.getBackground()==Color.MAGENTA)&&(b13.getBackground()==Color.yellow)&&(b15.getBackground()==Color.yellow)
        &&(b14.getBackground()==Color.black)&&(b16.getBackground()==Color.black))
  {
     JOptionPane j= new JOptionPane();
     j.showMessageDialog(rootPane, "YOU WON");
 
  }  
       
   
}
   
   
}
    Megame()
    { b1= new JButton();
    b1.setBackground(Color.white);
       b1.setBounds(50, 50, 50, 50);
    add(b1);
    Outr tim = new Outr();
    b1.addActionListener(tim);
    b2= new JButton();
    b2.setBackground(Color.white);
       b2.setBounds(100, 50, 50, 50);
    add(b2);
      b2.addActionListener(tim);
    b3= new JButton();
    b3.setBackground(Color.white);
       b3.setBounds(150, 50, 50, 50);
    add(b3);
      b3.addActionListener(tim);
     b4= new JButton();
b4.setBackground(Color.white);
    
     b4.setBounds(50, 100, 50, 50);
    add(b4);
      b4.addActionListener(tim);
     b5= new JButton();
     b5.setBackground(Color.white);
       b5.setBounds(100, 100, 50, 50);
    add(b5);
     b5.addActionListener(tim);
    b6= new JButton();
    b6.setBackground(Color.white);
       b6.setBounds(150, 100, 50, 50);
    add(b6);
      b6.addActionListener(tim);
    b7= new JButton();
    b7.setBackground(Color.white);
       b7.setBounds(50, 150, 50, 50);
    add(b7);
      b7.addActionListener(tim);
     b8= new JButton();
     b8.setBackground(Color.white);
       b8.setBounds(100, 150, 50, 50);
    add(b8);
      b8.addActionListener(tim);
     b9= new JButton();
       b9.setBounds(150, 150, 50, 50);
    add(b9);
     b9.setBackground(Color.white);
     b9.addActionListener(tim);
      b10= new JButton();
       b10.setBounds(200, 50, 50, 50);
    add(b10);
     b10.setBackground(Color.white);
     b10.addActionListener(tim);
      b11= new JButton();
       b11.setBounds(200, 100, 50, 50);
    add(b11);
     b11.setBackground(Color.white);
     b11.addActionListener(tim);
      b12= new JButton();
       b12.setBounds(200, 150, 50, 50);
    add(b12);
     b12.setBackground(Color.white);
     b12.addActionListener(tim);
      b13= new JButton();
       b13.setBounds(50, 200, 50, 50);
    add(b13);
     b13.setBackground(Color.white);
     b13.addActionListener(tim);
      b14= new JButton();
       b14.setBounds(100, 200, 50, 50);
    add(b14);
     b14.setBackground(Color.white);
     b14.addActionListener(tim);
      b15= new JButton();
       b15.setBounds(150, 200, 50, 50);
    add(b15);
     b15.setBackground(Color.white);
     b15.addActionListener(tim);
     b16= new JButton();
       b16.setBounds(200, 200, 50, 50);
    add(b16);
     b16.setBackground(Color.white);
     b16.addActionListener(tim);
      setSize(400, 400);
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(null);
    setVisible(true);
   }
   
   JButton b1;
   JButton b2;
   JButton b3;
   JButton b4;
   JButton b5;
   JButton b6;
   JButton b7;
   JButton b8;
   JButton b9;
   JButton b10;
   JButton b11;
   JButton b12;
   JButton b13;
   JButton b14;
   JButton b15;
   JButton b16;
   int A1=0,A2=0,C1=0,C2=0,D1=0,D2=0,E1=0,E2=0,F1=0,F2=0,G1=0,G2=0,H1=0,H2=0;
   int I1=0,I2=0;

  int count=0;
   

   
    public static void main(String args[])
           
    {
    Megame m1=new Megame();

   
   
    }
   
}