Saturday, April 29, 2017

Registration Form Java

Code:

import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
public class Formm extends Frame
{   Label [] l=new Label[8];
    TextField[] t=new TextField[6];
    TextArea a=new TextArea();
    CheckboxGroup p=new CheckboxGroup();
    Checkbox c1=new Checkbox("Male",p,true);
    Checkbox c2=new Checkbox("Female",p,false);
    Button s=new Button("Submit");
    Button r=new Button("Reset");
    int y=30;
    Connection cp;
    Statement st;
    Formm()
    {
        setLayout(null);
        setVisible(true);
        for(int i=0;i<8;i++)
        {
            l[i]=new Label();
            l[i].setBounds(30,y,100,30);
            add(l[i]);
            y+=40;
        }
        y=30;
        for(int i=0;i<6;i++)
        {
            t[i]=new TextField();
            t[i].setBounds(130,y,100,30);
            add(t[i]);
            y+=40;
        }
        a.setBounds(130,310,150,80);
        add(a);
        s.setBounds(50,400,50,30);
        add(s);
        r.setBounds(120,400,50,30);
        add(r);
        c1.setBounds(130,270,50,30);
        add(c1);
        c2.setBounds(180,270,60,30);
        add(c2);
        l[0].setText("Name");
        l[1].setText("Email");
        l[2].setText("Password");
        l[3].setText("Pincode");
        l[4].setText("DOB");
        l[5].setText("Mobile Number");
        l[6].setText("Gender");
        l[7].setText("Address");
        Label h=new Label("City:");
        h.setBounds(300,310,50,20);
        add(h);
        Choice c=new Choice();
        c.setBounds(350,310,100,30);
        c.add("Ludhiana");
        c.add("Jalandhar");
        c.add("Bhatinda");
        c.add("Amritsar");
        c.add("Hoshiarpur");
        add(c);
        this.addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent e)
            {
                System.exit(0);
            }
        });
        try
        {
         
            Class.forName("com.mysql.jdbc.Driver");
            cp=DriverManager.getConnection("jdbc:mysql://localhost/college","root","password");
            st=cp.createStatement();
        }
        catch(Exception e)
        {
            System.out.println("Error"+e);
        }
        r.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                for(int i=0;i<6;i++)
                {
                    t[i].setText(" ");
                }
                a.setText(" ");
            }
        });
        s.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e)
            {
           
             try
        {
            st.executeUpdate("Insert into form values('"+t[0].getText()+"','"+t[1].getText()+"','"+t[2].getText()+"','"+t[3].getText()+"','"+t[4].getText()+"','"+a.getText()+"','"+t[5].getText()+"','"+p.getSelectedCheckbox().getLabel()+"','"+c.getSelectedItem()+",) ");
        }
        catch(Exception ex)
        {
            System.out.println("Error Occured"+ex);
        }
             JOptionPane.showMessageDialog(null,"Record Entered");
             for(int i=0;i<6;i++)
             {
                 t[i].setText("");
             }
             a.setText("");
            }
        });
        setSize(500,500);  
    }
    public static void main(String[] nt)
    {
        new Formm();
    }
}

Output::





Friday, April 21, 2017

Anagram Python

Code::

def isanagram(s1,s2):
    s1="".join(sorted(s1))
    s2="".join(sorted(s2))
    if s1==s2:
        print("Anagram")
    else:
        print("Not Anagram")
     
     
w1=input("Enter First Word: ")
w2=input("Enter Second Word: ")
isanagram(w1.lower(),w2.lower())


Output:

Tuesday, April 18, 2017

TCP /IP,Ping/Ipconfig,File Sharing

Screenshots:








Ubuntu Installation and Virtual Box

Steps:

1.



























Tuesday, April 11, 2017

Currency Converter Java

Code::

import javax.swing.*;
import java.awt.event.*;
public class CurrencyConverter extends JFrame
{    JTextField t1=new JTextField();
     JTextField t2=new JTextField();
     JTextField t3=new JTextField();
     JLabel l1=new JLabel("Rupees:");
     JLabel l2=new JLabel("US Dollars:");
     JLabel l3=new JLabel("Euros:");
     CurrencyConverter()
     {
        setLayout(null);
        setTitle("Converter");
        setVisible(true);
        setSize(400,200);
        l1.setBounds(20,30,70,30);
        l2.setBounds(20,70,70,30);
        l3.setBounds(20,110,70,30);
        t1.setBounds(120,30,70,30);
        t2.setBounds(120,70,70,30);
        t3.setBounds(120,110,70,30);
        add(t1);
        add(l1);
        add(l2);
        add(t2);
        add(t3);
        add(l3);
        t1.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e)
            {
                double a=Double.parseDouble(t1.getText());
                t2.setText(String.format("%.2f",a*0.015));
                t3.setText(String.format("%.2f",a*0.015));
                
            }
        });
        t2.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e)
            {
                double a=Double.parseDouble(t2.getText());
                t1.setText(String.format("%.2f",a*64.68));
                t3.setText(String.format("%.2f",a*0.94));
                
            }
        });
        t3.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e)
            {
                double a=Double.parseDouble(t3.getText());
                t2.setText(String.format("%.2f",a*1.06));
                t1.setText(String.format("%.2f",a*68.71));
                
            }
        });
     }
      public static void main(String[] nt) 
    {
        new CurrencyConverter();
    }
    
}

Output::


Temperature Converter Java

Code::

import javax.swing.*;
import java.awt.event.*;
public class Converter extends JFrame 
{
    
    JTextField t1 =new JTextField();
    JTextField t2 =new JTextField();
    JLabel l1=new JLabel("Celsius:");
    JLabel l2=new JLabel("Fahrenheit:");
    Converter()
    {
        setLayout(null);
        setTitle("Converter");
        setVisible(true);
        setSize(400,200);
        l1.setBounds(20,30,70,30);
        l2.setBounds(20,70,70,30);
        t1.setBounds(120,30,70,30);
        t2.setBounds(120,70,70,30);
        add(t1);
        add(l1);
        add(l2);
        add(t2);
        t1.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e)
            {  double a=(Double.parseDouble(t1.getText()))*1.8+32;
                t2.setText(String.format("%.1f",a));
            }
        });
        t2.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e)
            {  double a=(((Double.parseDouble(t2.getText()))-32)/1.8);
                t1.setText(String.format("%.1f",a));
            }
        });
    }
   
    public static void main(String[] nt) {
      new Converter();
    }
    
}

Output::

Monday, April 10, 2017

Puzzle Game Java

Code::

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Puzzle extends Applet implements ActionListener
{   Button b[]=new Button[9];
    Button r=new Button("Reset");

    public void init()
    {  setLayout(null);
       setSize(400,400);
       JOptionPane.showMessageDialog(this,"Make sequence 1,2,3... by Clicking on buttons...");
        int x=50;
        int y=50;
       
        for (int i=0;i<9;i++)
        {  b[i]=new Button(String.valueOf(i+1));
           b[i].setBounds(x+50,y+50,30,30);
           x+=50;
           if((i+1)%3==0)
           {
               y+=50;
               x=50;
           }
           add(b[i]);
           b[i].addActionListener(this);
        }
        b[8].setLabel("2");
        b[1].setLabel("");
       r.setBounds(140,250,50,50);
       r.addActionListener(this);
       add(r);
    }

   public void actionPerformed(ActionEvent e)
   {
         if(e.getSource()==b[0])
         {
             if(b[1].getLabel()=="")
             {
                 b[1].setLabel(b[0].getLabel());
                 b[0].setLabel("");
             }
             if(b[3].getLabel()=="")
             {
                 b[3].setLabel(b[0].getLabel());
                 b[0].setLabel("");
             }
         }
         if(e.getSource()==b[8])
         {
           
             if(b[5].getLabel()=="")
             {
                 b[5].setLabel(b[8].getLabel());
                 b[8].setLabel("");
             }
             if(b[7].getLabel()=="")
             {
                 b[7].setLabel(b[8].getLabel());
                 b[8].setLabel("");
             }
         }
         if(e.getSource()==b[1])
         {
             if(b[0].getLabel()=="")
             {
                 b[0].setLabel(b[1].getLabel());
                 b[1].setLabel("");
             }
             if(b[2].getLabel()=="")
             {
                 b[2].setLabel(b[1].getLabel());
                 b[1].setLabel("");
             }
             if(b[4].getLabel()=="")
             {
                 b[4].setLabel(b[1].getLabel());
                 b[1].setLabel("");
             }
         }
         if(e.getSource()==b[2])
         {
             if(b[1].getLabel()=="")
             {
                 b[1].setLabel(b[2].getLabel());
                 b[2].setLabel("");
             }
             if(b[5].getLabel()=="")
             {
                 b[5].setLabel(b[2].getLabel());
                 b[2].setLabel("");
             }
         }
         if(e.getSource()==b[3])
         {
             if(b[0].getLabel()=="")
             {
                 b[0].setLabel(b[3].getLabel());
                 b[3].setLabel("");
             }
             if(b[4].getLabel()=="")
             {
                 b[4].setLabel(b[3].getLabel());
                 b[3].setLabel("");
             }
             if(b[6].getLabel()=="")
             {
                 b[6].setLabel(b[3].getLabel());
                 b[3].setLabel("");
             }
         }
         if(e.getSource()==b[4])
         {
             if(b[1].getLabel()=="")
             {
                 b[1].setLabel(b[4].getLabel());
                 b[4].setLabel("");
             }
             if(b[3].getLabel()=="")
             {
                 b[3].setLabel(b[4].getLabel());
                 b[4].setLabel("");
             }
             if(b[5].getLabel()=="")
             {
                 b[5].setLabel(b[4].getLabel());
                 b[4].setLabel("");
             }
             if(b[7].getLabel()=="")
             {
                 b[7].setLabel(b[4].getLabel());
                 b[4].setLabel("");
             }
         }
         if(e.getSource()==b[5])
         {
             if(b[2].getLabel()=="")
             {
                 b[2].setLabel(b[5].getLabel());
                 b[5].setLabel("");
             }
             if(b[4].getLabel()=="")
             {
                 b[4].setLabel(b[5].getLabel());
                 b[5].setLabel("");
             }
             if(b[8].getLabel()=="")
             {
                 b[8].setLabel(b[5].getLabel());
                 b[5].setLabel("");
             }
         }
         if(e.getSource()==b[7])
         {
             if(b[4].getLabel()=="")
             {
                 b[4].setLabel(b[7].getLabel());
                 b[7].setLabel("");
             }
             if(b[6].getLabel()=="")
             {
                 b[6].setLabel(b[7].getLabel());
                 b[7].setLabel("");
             }
             if(b[8].getLabel()=="")
             {
                 b[8].setLabel(b[7].getLabel());
                 b[7].setLabel("");
             }
         }
         if(e.getSource()==b[6])
         {
             if(b[3].getLabel()=="")
             {
                 b[3].setLabel(b[6].getLabel());
                 b[6].setLabel("");
             }
             if(b[7].getLabel()=="")
             {
                 b[7].setLabel(b[6].getLabel());
                 b[6].setLabel("");
             }
         }
     if(b[0].getLabel().equals("1")&&b[1].getLabel().equals("2")&&b[2].getLabel()  
            .equals("3")&&b[3].getLabel().equals("4")&&b[4].getLabel().equals("5")  
            &&b[5].getLabel().equals("6")&&b[6].getLabel().equals("7")&&b[7].getLabel()  
            .equals("8")&&b[8].getLabel().equals(""))
     {    
            JOptionPane.showMessageDialog(this,"Congratulations! You won.");  
     }
     if(e.getSource()==r)
     { for(int i=0;i<9;i++)
     {
         b[i].setLabel(String.valueOf(i+1));
     }
    int  j=(int)(7*Math.random());
    if(j==5)
    {
        j=(int)(7*Math.random());
    }
     b[8].setLabel(b[j].getLabel());
     b[j].setLabel("");
     }
   }
   public void paint(Graphics g)
   {
       g.drawImage(getImage(getDocumentBase(),"23.jpg"),0,0,this);
       g.setFont(new Font("Arial",Font.BOLD|Font.ITALIC,25));
       g.drawString("Puzzle Game",105,40);
       g.drawString("By Dishant",125,350);
   }

}

Output::