30 Nov 2013

java swing buttons example

/* java swing buttons example, jbutton in java swing example, jbutton in java swing actionlistener, jbutton actionperformed java example */

import java.util.Map;
import java.util.TreeMap;
import javax.swing.JOptionPane;

public class ClientLogin extends javax.swing.JFrame {

   

    public ClientLogin() {
        initComponents();
    }

  

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPasswordField1 = new javax.swing.JPasswordField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        setMinimumSize(new java.awt.Dimension(510, 400));
        getContentPane().setLayout(null);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Client Login", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 14), new java.awt.Color(0, 0, 0))); // NOI18N

        jPanel1.setLayout(null);

        jLabel1.setFont(new java.awt.Font("Times New Roman", 3, 24));

        jLabel1.setText("Client Login");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(180, 20, 130, 30);

        jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 14));

        jLabel2.setText("User Id");
        jPanel1.add(jLabel2);
        jLabel2.setBounds(50, 100, 100, 30);

        jLabel3.setFont(new java.awt.Font("Times New Roman", 1, 14));

        jLabel3.setText("Password");
        jPanel1.add(jLabel3);
        jLabel3.setBounds(50, 170, 110, 30);
        jPanel1.add(jTextField1);
        jTextField1.setBounds(180, 100, 140, 30);

        jButton1.setFont(new java.awt.Font("Times New Roman", 1, 14));

        jButton1.setText("Login");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1);
        jButton1.setBounds(270, 233, 100, 30);

        jButton2.setFont(new java.awt.Font("Times New Roman", 1, 14));

        jButton2.setText("Reset");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton2);
        jButton2.setBounds(390, 233, 90, 30);
        jPanel1.add(jPasswordField1);
        jPasswordField1.setBounds(180, 170, 140, 30);

        getContentPane().add(jPanel1);

        jPanel1.setBounds(10, 10, 490, 310);

        pack();

    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        DBPack.DBConnection db=new DBPack.DBConnection();
        Map map=db.loginVal();
        String s=jTextField1.getText();
        String ss=jPasswordField1.getText();
        System.out.println("uname"+s);
        System.out.println("upass"+ss);
        boolean uname1=map.containsKey(s);
        boolean upass1=map.containsValue(ss);
        System.out.println("uname"+map);
        System.out.println(uname1+""+upass1);

        if(uname1 && upass1)

        {
           
            db.insertclient(s);
            System.out.println(uname1+""+upass1);
            JOptionPane.showMessageDialog(rootPane, "Login successfully");
            this.dispose();
            ClientHomeSW ch=new ClientHomeSW();
            ch.clientName(s);
            ch.setVisible(true);
           
        }
 else
        {
            JOptionPane.showMessageDialog(rootPane, "In-Valid Login");
 }

    }//GEN-LAST:event_jButton1ActionPerformed


    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    public static void main(String args[]) {

        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ClientLogin().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables

    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables

}

0 comments:

Post a Comment