Monday, 12 February 2018

how to connect java with sqlite database

who to///////////////////******************* Java Connector ***************////////////////////////

           

import java.sql.*;

import javax.swing.*;

public class connector {

    

    Connection cn=null;

    public static Connection connectorBD()

    { 

        try 

        {

            Class.forName("org.sqlite.JDBC");

            Connection cn = DriverManager.getConnection("jdbc:sqlite:C:\\Users\\bilal\\Documents\\NetBeansProjects\\HospitalManagementSystem\\HospitalManament.sqlite");//Here you past your address

         

            return cn;

        }

        catch(Exception e)

        { 

            JOptionPane.showMessageDialog(null, e);

            return null;

        }

    }

} 

Tuesday, 9 January 2018

recursion in data stucture factorial of a number

#include<iostream>
using namespace std;
int fact(int num)
{
         if(num==0)
         return 1;
         else return num*fact(num-1);
}
int main()
{
int n;
cout<<"Enter any number please"<<endl;
cin>>n;
cout<<"factorial is "<<fact(n)<<endl;
}

data structure

A program that add new node if the all node in the 





#include <iostream>
#include<queue>
using namespace std;
struct BTNode{
int data;
BTNode *left;
BTNode *right;
};BTNode *root;

BTNode* getnewNode(int a){

BTNode *n=new BTNode;

if(a % 2==0)
{
cout<<"num is even: not added"<<endl;
}else
{

n->data=a;
}
n->right=NULL;
n->left=NULL;
return n;


}
BTNode* insertNode (BTNode* r,int d){
if(r==NULL)
{
r=getnewNode(d);


}else
{
if( d<=r->data)
{
r->left=insertNode(r->left,d);
}else
{
r->right=insertNode(r->right,d);
}
return r;

}

}
void in_orderdisplay( BTNode* r)
{
if(r==NULL)
{
return;

}
in_orderdisplay(r->left);
cout<<r->data;
in_orderdisplay(r->right);
}
void pre_orderdisplay(BTNode* r)
{
if(r==NULL)
{
return ;

}
cout<<r->data<<endl;
pre_orderdisplay(r->left);
pre_orderdisplay(r->right);
}
 void post_orderdisplay(BTNode* r)
{
if(r==NULL)
{
return;
}
post_orderdisplay(r->left);
post_orderdisplay(r->right);
cout<<r->data;

}
void level_orderdisplay(BTNode* r){
if(r==NULL)
{

return;

}
queue<BTNode*> Q;
Q.push(r);
while(!Q.empty())
{
BTNode* temp=Q.front();
cout<<temp->data;
if(temp->left!=NULL)
{
Q.push(temp->left);
}
if( temp->right!=NULL)
{
Q.push(temp->right);

}
Q.pop();
}


}

int main()
{
int choice,a ;
root=NULL;

char ch='y';
while(ch='y')
{

cout<<"enter 1 to add node "<<endl;
cout<<"enter 2 to display"<<endl;
cout<<"enter 3 to inorder dispaly"<<endl;
cout<<"enter 4 to postorder dispaly"<<endl;
cout<<"enter 5 to level wise display"<<endl;
cin>>choice;
switch(choice)
{
case 1:
cout<<"enter value"<<endl;
cin>>a;
root=insertNode(root,a);
break;
case 2:
pre_orderdisplay(root);
break;
case 3:
in_orderdisplay(root);
break;
case 4:
post_orderdisplay(root);
break;
case 5:
level_orderdisplay(root);
break;
default:
break;

}
cout<<"prees y to continue"<<endl;
cout<<"press n to exist"<<endl;
cin>>ch;
}
}



c++ how to make function that sum the number

#include<iostream>
using namespace std;
void sum (int&, int&);
main()
{
int a,b;
cin>>a>>b;
sum(a,b);
}
void sum(int &c, int &d)
{
int sum;
sum=c+d;
cout<<"sum is: "<<sum;

}

c++ program that find isosceles triangle equilateral triangle right angle triangle and scalene triangle

#include <iostream>

using namespace std;
main(){
int side1,side2,side3,a,b,c;
cout<<"Enter first side =";
cin>>side1;
cout<<"Enter second side=";
cin>>side2;
cout<<"Enter third side=";
cin>>side3;
if(side1==side2 && side2==side3 && side1==side3)
{

cout<<"isosceles triangle";
}

else if (side1==side2==side3)
{

cout<<"equilateral triangle";
}
else if(c*c==a*a+b*b || b*b==a*a+c*c || a*a==b*b+c*c )
{

cout<<"right angle triangle";
}
else
{

cout<<"scalene triangle";
}


}

c++ first program

#include<iostream>
using namespace std;
int main()
{
  cout<<"Welcome"<<endl;
}

Sunday, 17 December 2017

how to insert value in table using sql server

how to insert value in table using sql server

insert into students(id,name,course) values (9,'bilal','BSE')

How to create a table in sql server

How to create a table in sql server

 create table students
(
      stdID int primary key,
    Name nvarchar(30),
    Course nvarchar(30)
)

how to create a database in sql server

How to create a database in sql server

create database college

after this you write

use college


      
 

A program find the table of number

import java.awt.Toolkit;

import java.util.Calendar;

import java.util.GregorianCalendar;

import java.util.logging.Level;

import java.util.logging.Logger;

import javax.swing.JOptionPane;

import java.io.*;

import com.sun.speech.freetts.*;


public class tabels extends javax.swing.JFrame {


    /**

     * Creates new form tabels

     */

    public tabels() {

        initComponents();

     }


     

    /**

     * This method is called from within the constructor to initialize the form.

     * WARNING: Do NOT modify this code. The content of this method is always

     * regenerated by the Form Editor.

     */

    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          

    private void initComponents() {


        jPanel1 = new javax.swing.JPanel();

        tf1 = new javax.swing.JTextField();

        jLabel2 = new javax.swing.JLabel();

        tf = new javax.swing.JTextField();

        jLabel3 = new javax.swing.JLabel();

        jButton1 = new javax.swing.JButton();

        jButton2 = new javax.swing.JButton();

        jScrollPane1 = new javax.swing.JScrollPane();

        ta = new javax.swing.JTextArea();

        l = new javax.swing.JLabel();


        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);


        tf1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N

        tf1.addKeyListener(new java.awt.event.KeyAdapter() {

            public void keyTyped(java.awt.event.KeyEvent evt) {

                tf1KeyTyped(evt);

            }

        });


        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N

        jLabel2.setForeground(new java.awt.Color(102, 102, 0));

        jLabel2.setText("Enter table number");

        jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent evt) {

                jLabel2MouseClicked(evt);

            }

        });


        tf.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N

        tf.addKeyListener(new java.awt.event.KeyAdapter() {

            public void keyTyped(java.awt.event.KeyEvent evt) {

                tfKeyTyped(evt);

            }

        });


        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N

        jLabel3.setForeground(new java.awt.Color(102, 102, 0));

        jLabel3.setText("Enter table Limit");

        jLabel3.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent evt) {

                jLabel3MouseClicked(evt);

            }

        });


        jButton1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N

        jButton1.setForeground(new java.awt.Color(102, 102, 0));

        jButton1.setText("Display Table");

        jButton1.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                jButton1ActionPerformed(evt);

            }

        });


        jButton2.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N

        jButton2.setForeground(new java.awt.Color(102, 102, 0));

        jButton2.setText("Refresh");

        jButton2.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {

                jButton2ActionPerformed(evt);

            }

        });


        ta.setColumns(20);

        ta.setFont(new java.awt.Font("Monospaced", 1, 24)); // NOI18N

        ta.setForeground(new java.awt.Color(102, 102, 0));

        ta.setRows(5);

        jScrollPane1.setViewportView(ta);


        l.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N

        l.setText("Table of Number");


        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);

        jPanel1.setLayout(jPanel1Layout);

        jPanel1Layout.setHorizontalGroup(

            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()

                .addGap(0, 0, Short.MAX_VALUE)

                .addComponent(l, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addGap(144, 144, 144))

            .addGroup(jPanel1Layout.createSequentialGroup()

                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                    .addGroup(jPanel1Layout.createSequentialGroup()

                        .addGap(30, 30, 30)

                        .addComponent(jButton2)

                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                        .addComponent(jButton1))

                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 411, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addGroup(jPanel1Layout.createSequentialGroup()

                        .addContainerGap()

                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)

                            .addGroup(jPanel1Layout.createSequentialGroup()

                                .addComponent(jLabel2)

                                .addGap(18, 18, 18)

                                .addComponent(tf1, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))

                            .addGroup(jPanel1Layout.createSequentialGroup()

                                .addComponent(jLabel3)

                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

                                .addComponent(tf, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)))))

                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

        );

        jPanel1Layout.setVerticalGroup(

            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(jPanel1Layout.createSequentialGroup()

                .addGap(40, 40, 40)

                .addComponent(l)

                .addGap(18, 18, 18)

                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(tf1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(jLabel2))

                .addGap(28, 28, 28)

                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

                    .addComponent(tf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(jLabel3))

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

                    .addComponent(jButton1)

                    .addComponent(jButton2))

                .addGap(18, 18, 18)

                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 425, Short.MAX_VALUE))

        );


        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

        getContentPane().setLayout(layout);

        layout.setHorizontalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

        );

        layout.setVerticalGroup(

            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

                .addContainerGap())

        );


        pack();

    }// </editor-fold>                        


    private void tfKeyTyped(java.awt.event.KeyEvent evt) {                            

 char ch = evt.getKeyChar();

     if(Character.isAlphabetic(ch))

     { 

         evt.consume();

     } // TODO add your handling code here:

    }                           


    private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {                                     

// TODO add your handling code here:

    }                                    


    private void tf1KeyTyped(java.awt.event.KeyEvent evt) {                             

        // TODO add your handling code here:

    }                            


    private void jLabel3MouseClicked(java.awt.event.MouseEvent evt) {                                     

        // TODO add your handling code here:

    }                                    


    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

                  try {

         

            int n1=Integer.parseInt(tf.getText());

            int n=Integer.parseInt(tf1.getText());

         for(int i=1;i<=n1;i++){

       ta.append(n+"   x    "+i+"  =  "+n*i+"\n");

 

      

     

     }  }

catch(Exception e)

{

    JOptionPane.showMessageDialog(null, e);

}        // TODO add your handling code here:

    }                                        


    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         

     ta.setText("");

     tf1.setText("");

        tf.setText("");// TODO add your handling code here:

    }                                        


    /**

     * @param args the command line arguments

     */

    public static void main(String args[]) {

        /* Set the Nimbus look and feel */

        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">

        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 

         */

        try {

            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {

                if ("Nimbus".equals(info.getName())) {

                    javax.swing.UIManager.setLookAndFeel(info.getClassName());

                    break;

                }

            }

        } catch (ClassNotFoundException ex) {

            java.util.logging.Logger.getLogger(tabels.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (InstantiationException ex) {

            java.util.logging.Logger.getLogger(tabels.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (IllegalAccessException ex) {

            java.util.logging.Logger.getLogger(tabels.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (javax.swing.UnsupportedLookAndFeelException ex) {

            java.util.logging.Logger.getLogger(tabels.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        }

        //</editor-fold>


        /* Create and display the form */

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {

                new tabels().setVisible(true);

            }

        });

    }


    // Variables declaration - do not modify                     

    private javax.swing.JButton jButton1;

    private javax.swing.JButton jButton2;

    private javax.swing.JLabel jLabel2;

    private javax.swing.JLabel jLabel3;

    private javax.swing.JPanel jPanel1;

    private javax.swing.JScrollPane jScrollPane1;

    private javax.swing.JLabel l;

    private javax.swing.JTextArea ta;

    private javax.swing.JTextField tf;

    private javax.swing.JTextField tf1;

    // End of variables declaration                   

}

java program print the number of table

import java.awt.Toolkit;import java.util.Calendar;import java.util.GregorianCalendar;import java.util.logging.Level;import java.util.logging.Logger;import javax.swing.JOptionPane;import java.io.*;import com.sun.speech.freetts.*;
public class tabels extends javax.swing.JFrame {
    /**     * Creates new form tabels     */    public tabels() {        initComponents();     }
         /**     * This method is called from within the constructor to initialize the form.     * WARNING: Do NOT modify this code. The content of this method is always     * regenerated by the Form Editor.     */    @SuppressWarnings("unchecked")    // <editor-fold defaultstate="collapsed" desc="Generated Code">                              private void initComponents() {
        jPanel1 = new javax.swing.JPanel();        tf1 = new javax.swing.JTextField();        jLabel2 = new javax.swing.JLabel();        tf = new javax.swing.JTextField();        jLabel3 = new javax.swing.JLabel();        jButton1 = new javax.swing.JButton();        jButton2 = new javax.swing.JButton();        jScrollPane1 = new javax.swing.JScrollPane();        ta = new javax.swing.JTextArea();        l = new javax.swing.JLabel();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        tf1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N        tf1.addKeyListener(new java.awt.event.KeyAdapter() {            public void keyTyped(java.awt.event.KeyEvent evt) {                tf1KeyTyped(evt);            }        });
        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N        jLabel2.setForeground(new java.awt.Color(102, 102, 0));        jLabel2.setText("Enter table number");        jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {            public void mouseClicked(java.awt.event.MouseEvent evt) {                jLabel2MouseClicked(evt);            }        });
        tf.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N        tf.addKeyListener(new java.awt.event.KeyAdapter() {            public void keyTyped(java.awt.event.KeyEvent evt) {                tfKeyTyped(evt);            }        });
        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N        jLabel3.setForeground(new java.awt.Color(102, 102, 0));        jLabel3.setText("Enter table Limit");        jLabel3.addMouseListener(new java.awt.event.MouseAdapter() {            public void mouseClicked(java.awt.event.MouseEvent evt) {                jLabel3MouseClicked(evt);            }        });
        jButton1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N        jButton1.setForeground(new java.awt.Color(102, 102, 0));        jButton1.setText("Display Table");        jButton1.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton1ActionPerformed(evt);            }        });
        jButton2.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N        jButton2.setForeground(new java.awt.Color(102, 102, 0));        jButton2.setText("Refresh");        jButton2.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton2ActionPerformed(evt);            }        });
        ta.setColumns(20);        ta.setFont(new java.awt.Font("Monospaced", 1, 24)); // NOI18N        ta.setForeground(new java.awt.Color(102, 102, 0));        ta.setRows(5);        jScrollPane1.setViewportView(ta);
        l.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N        l.setText("Table of Number");
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);        jPanel1.setLayout(jPanel1Layout);        jPanel1Layout.setHorizontalGroup(            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()                .addGap(0, 0, Short.MAX_VALUE)                .addComponent(l, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)                .addGap(144, 144, 144))            .addGroup(jPanel1Layout.createSequentialGroup()                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)                    .addGroup(jPanel1Layout.createSequentialGroup()                        .addGap(30, 30, 30)                        .addComponent(jButton2)                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                        .addComponent(jButton1))                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 411, javax.swing.GroupLayout.PREFERRED_SIZE)                    .addGroup(jPanel1Layout.createSequentialGroup()                        .addContainerGap()                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)                            .addGroup(jPanel1Layout.createSequentialGroup()                                .addComponent(jLabel2)                                .addGap(18, 18, 18)                                .addComponent(tf1, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))                            .addGroup(jPanel1Layout.createSequentialGroup()                                .addComponent(jLabel3)                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                                .addComponent(tf, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)))))                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))        );        jPanel1Layout.setVerticalGroup(            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(jPanel1Layout.createSequentialGroup()                .addGap(40, 40, 40)                .addComponent(l)                .addGap(18, 18, 18)                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(tf1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                    .addComponent(jLabel2))                .addGap(28, 28, 28)                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)                    .addComponent(tf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)                    .addComponent(jLabel3))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(jButton1)                    .addComponent(jButton2))                .addGap(18, 18, 18)                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 425, Short.MAX_VALUE))        );
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());        getContentPane().setLayout(layout);        layout.setHorizontalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)        );        layout.setVerticalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                .addContainerGap())        );
        pack();    }// </editor-fold>                        
    private void tfKeyTyped(java.awt.event.KeyEvent evt) {                             char ch = evt.getKeyChar();     if(Character.isAlphabetic(ch))     {          evt.consume();     } // TODO add your handling code here:    }                           
    private void jLabel2MouseClicked(java.awt.event.MouseEvent evt) {                                     // TODO add your handling code here:    }                                    
    private void tf1KeyTyped(java.awt.event.KeyEvent evt) {                                     // TODO add your handling code here:    }                            
    private void jLabel3MouseClicked(java.awt.event.MouseEvent evt) {                                             // TODO add your handling code here:    }                                    
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                                           try {                     int n1=Integer.parseInt(tf.getText());            int n=Integer.parseInt(tf1.getText());         for(int i=1;i<=n1;i++){       ta.append(n+"   x    "+i+"  =  "+n*i+"\n");                 }  }catch(Exception e){    JOptionPane.showMessageDialog(null, e);}        // TODO add your handling code here:    }                                        
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                              ta.setText("");     tf1.setText("");        tf.setText("");// TODO add your handling code here:    }                                        
    /**     * @param args the command line arguments     */    public static void main(String args[]) {        /* Set the Nimbus look and feel */        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html          */        try {            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {                if ("Nimbus".equals(info.getName())) {                    javax.swing.UIManager.setLookAndFeel(info.getClassName());                    break;                }            }        } catch (ClassNotFoundException ex) {            java.util.logging.Logger.getLogger(tabels.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);        } catch (InstantiationException ex) {            java.util.logging.Logger.getLogger(tabels.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);        } catch (IllegalAccessException ex) {            java.util.logging.Logger.getLogger(tabels.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);        } catch (javax.swing.UnsupportedLookAndFeelException ex) {            java.util.logging.Logger.getLogger(tabels.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);        }        //</editor-fold>
        /* Create and display the form */        java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {                new tabels().setVisible(true);            }        });    }
    // Variables declaration - do not modify                         private javax.swing.JButton jButton1;    private javax.swing.JButton jButton2;    private javax.swing.JLabel jLabel2;    private javax.swing.JLabel jLabel3;    private javax.swing.JPanel jPanel1;    private javax.swing.JScrollPane jScrollPane1;    private javax.swing.JLabel l;    private javax.swing.JTextArea ta;    private javax.swing.JTextField tf;    private javax.swing.JTextField tf1;    // End of variables declaration                   }

                 

Thursday, 7 December 2017

java calculatore


package bilaly;
import javax.swing.*; 
import java.awt.event.*; 
public class Main implements ActionListener{ 
    JTextField tf1,tf2,tf3; 
    JButton b1,b2,b3,b4; 
    Main(){ 
        JFrame f= new JFrame(); 
        tf1=new JTextField(); 
        tf1.setBounds(50,50,150,20); 
        tf2=new JTextField(); 
        tf2.setBounds(50,100,150,20); 
        tf3=new JTextField(); 
        tf3.setBounds(50,150,150,20); 
        tf3.setEditable(false); 
        b1=new JButton("+"); 
        b1.setBounds(20,200,50,50); 
        b2=new JButton("-"); 
        b2.setBounds(80,200,50,50);
        b3=new JButton("x"); 
        b3.setBounds(200,200,50,50);
        b4=new JButton("/"); 
        b4.setBounds(140,200,50,50);
        b1.addActionListener(this); 
        b2.addActionListener(this);
         b3.addActionListener(this); 
        b4.addActionListener(this);
        f.add(tf1);f.add(tf2);f.add(tf3);f.add(b1);f.add(b2); f.add(b3);f.add(b4);
        f.setSize(300,300); 
        f.setLayout(null); 
        f.setVisible(true); 
    }       
    public void actionPerformed(ActionEvent e) { 
        String s1=tf1.getText(); 
        String s2=tf2.getText(); 
       Double a = new Double(s1);
       Double b= new Double(s2);

        double c=0; 
        if(e.getSource()==b1){ 
            c=a+b; 
        }else if(e.getSource()==b2){ 
            c=a-b; 
        }  else if(e.getSource()==b3){ 
            c=a*b; 
        }  else if(e.getSource()==b4){ 
            c=a/b; 
        } 
        String result=String.valueOf(c); 
        tf3.setText(result); 
    } 
public static void main(String[] args) { 
    new Main(); 
} }

Monday, 20 November 2017

Using java build a beautiful clock display current time

THIS IS THE CODE TO DISPLAY A BEAUTIFUL CLOCK

 package javaaa;

import java.awt.*;
import java.awt.geom.*;
 import java.awt.event.*;
 import java.util.Calendar;
 import javax.swing.*;

public class Javaaa extends JApplet {
 public static void main(String s[]) {
 JFrame frame = new JFrame();
 frame.setTitle("Clock");

 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 JApplet applet = new Javaaa();
 applet.init();
 frame.getContentPane().add(applet);
 frame.pack();
 frame.setVisible(true);
 }

 public void init() {
 JPanel panel = new ClockPanel();
 getContentPane().add(panel);
 }
 }
 class ClockPanel extends JPanel implements ActionListener{
 AffineTransform rotH = new AffineTransform();
 AffineTransform rotM = new AffineTransform();
 AffineTransform rotS = new AffineTransform();

 public ClockPanel() {
 setPreferredSize(new Dimension(640, 480));
 setBackground(Color.white);
 Timer timer = new Timer(500, this);
 timer.start();
 }

 public void paintComponent(Graphics g) {
 super.paintComponent(g);
 Graphics2D g2 = (Graphics2D)g;
 Font currentFont = g2.getFont();
 g2.translate(320,240);
 // clock face
 Paint paint = new GradientPaint
 (-140,-140,Color.GREEN,-10,-10,Color.ORANGE);
 g2.setPaint(paint);
 g2.fillOval(-210, -210, 420, 420);
 g2.setColor(Color.red);
  Font newFont = currentFont.deriveFont(currentFont.getSize() * 3.4F);
            g2.setFont(newFont);
 g2.drawString("CLOCK", -70, 80);
 g2.setColor(Color.black);
  Font newFont1 = currentFont.deriveFont(currentFont.getSize() * 2.4F);
            g2.setFont(newFont1);
 g2.drawString("12", -18, -140);
 g2.drawString("3", 134, 19);
 g2.drawString("6", -8, 159);
 g2.drawString("9", -149, 20);
 Stroke stroke = new BasicStroke(3);
 g2.setStroke(stroke);
 g2.drawOval(-210, -210, 420, 420);
 for (int i = 0; i < 24; i++) {
 g2.rotate(2*Math.PI/12);
 if(i%2==0)
     g2.setColor(Color.BLUE);
 else
     g2.setColor(Color.red);
            
 g2.fill3DRect(-30, -200, 60, 30, true);
 }
 // clock hands
 Shape hour = new Line2D.Double(0, 0, 0, -100);
 hour = rotH.createTransformedShape(hour);
 Shape minute = new Line2D.Double(0, 0, 0, -140);
 minute = rotM.createTransformedShape(minute);
 Shape second = new Line2D.Double(0, 0, 0, -170);
 second = rotS.createTransformedShape(second);
 g2.setColor(Color.MAGENTA);
 g2.setStroke(new BasicStroke(10,
 BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
 g2.draw(hour);
 g2.draw(minute);
 g2.setStroke(new BasicStroke(4));
 g2.draw(second);
 }
 public void actionPerformed(ActionEvent e) {
 int hour = Calendar.getInstance().get(Calendar.HOUR);
 int min = Calendar.getInstance().get(Calendar.MINUTE);
 int sec = Calendar.getInstance().get(Calendar.SECOND);
 rotH.setToRotation(Math.PI * (hour+min/60.0)/6.0);
 rotM.setToRotation(Math.PI * min /30.0);
 rotS.setToRotation(Math.PI * sec /30.0);
 repaint();
}}

OUTPUT