Powered by Blogger.

Contact

Popular Posts

Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

Monday, 29 July 2013

/*
 * login_form.java
 *
 * Created on July 16, 2013, 10:57 AM
 */

package loginform;

/**
 *
 * @author  LTIET_CSE_DEPT
 */
public class login_form extends javax.swing.JFrame {
   
    /** Creates new form login_form */
    public login_form() {
        initComponents();
        jOptionPane1.setVisible(false);
    }
   
    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        uname = new javax.swing.JTextField();
        ok = new javax.swing.JButton();
        cancel_btn = new javax.swing.JButton();
        upass = new javax.swing.JPasswordField();
        jOptionPane1 = new javax.swing.JOptionPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Name:");

        jLabel2.setText("Password:");

        ok.setText("OK");
        ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okActionPerformed(evt);
            }
        });

        cancel_btn.setText("Cancel");
        cancel_btn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancel_btnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(51, 51, 51)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(upass)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(ok)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(cancel_btn))
                            .addComponent(uname, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(84, 84, 84)
                        .addComponent(jOptionPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(242, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(uname, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(upass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ok)
                    .addComponent(cancel_btn))
                .addGap(28, 28, 28)
                .addComponent(jOptionPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(151, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed
        if(uname.getText().equals("Sagar"))
        {
            if(upass.getText().equals("123"))
            {
                jOptionPane1.showMessageDialog(this,"Welcome");
            }
            else{jOptionPane1.showMessageDialog(this,"Enter Correct Password");}
        }
        else{jOptionPane1.showMessageDialog(this,"Enter Correct UserName");}
    }//GEN-LAST:event_okActionPerformed

    private void cancel_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancel_btnActionPerformed
        System.exit(0);
    }//GEN-LAST:event_cancel_btnActionPerformed
   
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new login_form().setVisible(true);
            }
        });
    }
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancel_btn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JOptionPane jOptionPane1;
    private javax.swing.JButton ok;
    private javax.swing.JTextField uname;
    private javax.swing.JPasswordField upass;
    // End of variables declaration//GEN-END:variables
   
}

Saturday, 27 July 2013

  
package ajt;

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

class StudentReg extends JPanel implements ActionListener {
   
    JButton b1;
    JTextField t1,t2,t3;
    JLabel l1,l2,l3,l4;
    JCheckBox c1,c2,c3;
    JRadioButton r1,r2;
    ButtonGroup bg1;
    JComboBox cb;
    String str="Game : ";
    JCheckBox c[] = new JCheckBox[3];
    public StudentReg()
    {
        b1 = new JButton("Submit");
        t1 = new JTextField("Sagar",10);
        t2 = new JTextField("CE",10);
        t3 = new JTextField("Botad",10);
        l1 = new JLabel("Name");
        l2 = new JLabel("Branch");
        l3 = new JLabel("Address");
        l4 = new JLabel("Car");
        r1 = new JRadioButton("Male");
        r1.setActionCommand("male");
        r2 = new JRadioButton("Female");
        r2.setActionCommand("female");
        c1 = new JCheckBox("Cricket");
        c2 = new JCheckBox("FootBall");
        c3 = new JCheckBox("VollyBall");
        cb = new JComboBox();
        bg1 = new ButtonGroup();
       
        cb.addItem("BMW");
        cb.addItem("AUDI");
        cb.addItem("AMW");
       
        b1.addActionListener(this);
        bg1.add(r1);
        bg1.add(r2);
       
        add(l1);
        add(t1);
        add(l2);
        add(t2);
        add(l3);
        add(t3);   
        add(l4);
        add(cb);
        add(r1);add(r2);
        add(c1);add(c2);add(c3);
        add(b1);
   
    }
   public void actionPerformed(ActionEvent e)
   {
       String name = t1.getText();
       System.out.println("Name : "+name);
       String branch = t2.getText();
       System.out.println("Branch : "+branch);
       String add = t3.getText();
       System.out.println("Address : "+add);
      
       String car = cb.getSelectedItem().toString();
       System.out.println("Car : "+car);
       if(bg1.getSelection().getActionCommand().equals("male"))
       {
            System.out.println("Gender : Male");
       }
       else
       {
            System.out.println("Gender : Female");
       }
      
        if(c1.isSelected())
        { 
           str = str +"Cricket ";
          
        }
        if(c2.isSelected())
        {
           str = str+"+ FootBall";   
          
        }
        if(c3.isSelected())
        {
            str = str+ "+ VollyBall ";         
        }
        System.out.println(" "+str);
   }
   public static void main(String args[])
   {
        JFrame frame = new JFrame("JButtonDemo");
   
        frame.addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent e)
            {
                System.exit(0);
            }
        });
        frame.getContentPane().add(new StudentReg());
        frame.pack();
        frame.setVisible(true);
   }
}

package ajt;

/**
 *
 * @author  SAGAR
 */
public class StudentRegForm extends javax.swing.JFrame {

    /** Creates new form StudentRegForm */
    public StudentRegForm() {
        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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jCheckBox3 = new javax.swing.JCheckBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Name");

        jLabel2.setText("Branch");

        jLabel3.setText("Address");

        jRadioButton1.setText("Male");

        jRadioButton2.setText("Female");

        jTextField1.setToolTipText("");

        jLabel4.setText("State");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Cars", "Bike", "Bicycle" }));
        jComboBox1.setToolTipText("");

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jCheckBox1.setText("Cricket");

        jCheckBox2.setText("FootBall");

        jCheckBox3.setText("VollyBall");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 345, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 52, Short.MAX_VALUE))
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jTextField2)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE)
                                    .addComponent(jTextField3, javax.swing.GroupLayout.Alignment.TRAILING))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jCheckBox3)
                                    .addComponent(jCheckBox2)
                                    .addComponent(jCheckBox1)))
                            .addComponent(jButton1)))
                    .addComponent(jRadioButton2)
                    .addComponent(jRadioButton1))
                .addContainerGap(344, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(24, 24, 24)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jRadioButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRadioButton2))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addComponent(jCheckBox1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCheckBox2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCheckBox3)))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(79, 79, 79))
        );

        pack();
    }// </editor-fold>
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        String name = jTextField1.getText();
        System.out.println("Name : " + name);
        String branch = jTextField2.getText();
        System.out.println("Branch : " + branch);
        String address = jTextField3.getText();
        System.out.println("Address : " + address);

        String s = jComboBox1.getSelectedItem().toString();
        System.out.println("State : "+ s);
      
       jCheckBox1.getSelectedObjects().toString();
      
      
    }                                       

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new StudentRegForm().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    // End of variables declaration
}
  1. import javax.swing.JFrame;  
  2. import javax.swing.JCheckBox;  
  3. import javax.swing.JButton;  
  4. import javax.swing.JOptionPane;  
  5.   
  6. import java.awt.GridLayout;  
  7.   
  8. import java.awt.event.ActionEvent;  
  9. import java.awt.event.ActionListener;  
  10.   
  11. public class GetSelectedJCheckBox implements ActionListener  
  12. {  
  13. //Create String that will be use to hold selected JCheckBox text  
  14. String selectedCheckBox="";  
  15.   
  16. //Create check box using JCheckBox  
  17. JCheckBox checkBox1=new JCheckBox("Duck");  
  18. JCheckBox checkBox2=new JCheckBox("Chicken");  
  19. JCheckBox checkBox3=new JCheckBox("Cow");  
  20. JCheckBox checkBox4=new JCheckBox("Sheep");  
  21.   
  22. //Create button using JButton with text ( Get selected JCheckBox )  
  23. JButton button=new JButton("Get selected JCheckBox");  
  24.   
  25. //method actionPerformed that we override because we implement ActionListener  
  26. public void actionPerformed(ActionEvent event)  
  27. {  
  28.  //Action for button  
  29.  if(event.getSource()==button)  
  30.  {  
  31.   //Check first JCheckBox is selected or not  
  32.   if(checkBox1.isSelected())  
  33.   {  
  34.    selectedCheckBox=selectedCheckBox+checkBox1.getText()+"\n";  
  35.   }  
  36.    
  37.   //Check second JCheckBox is selected or not  
  38.   if(checkBox2.isSelected())  
  39.   {  
  40.    selectedCheckBox=selectedCheckBox+checkBox2.getText()+"\n";  
  41.   }  
  42.    
  43.   //Check third JCheckBox is selected or not  
  44.   if(checkBox3.isSelected())  
  45.   {  
  46.    selectedCheckBox=selectedCheckBox+checkBox3.getText()+"\n";  
  47.   }  
  48.    
  49.   //Check fourth JCheckBox is selected or not  
  50.   if(checkBox4.isSelected())  
  51.   {  
  52.    selectedCheckBox=selectedCheckBox+checkBox4.getText()+"\n";  
  53.   }  
  54.    
  55.   //Show message that tell you, what check box that you selected  
  56.   JOptionPane.showMessageDialog(null,"Selected check box is : \n"+selectedCheckBox);  
  57.    
  58.   //Make selectedCheckBox string like initial with empty string  
  59.   selectedCheckBox=new String("");  
  60.  }  
  61. }  
  62.   
  63. //Constructor  
  64. public GetSelectedJCheckBox()  
  65. {  
  66.  //Create a window using JFrame with title ( Get selected JCheckBox )  
  67.  JFrame frame=new JFrame("Get selected JCheckBox");  
  68.   
  69.  //Create layout that will be use by JFrame  
  70.  GridLayout gl=new GridLayout(5,1);  
  71.   
  72.  //Add ActionListener to button  
  73.  button.addActionListener(this);  
  74.   
  75.  //Set JFrame layout  
  76.  frame.setLayout(gl);  
  77.   
  78.  //Add all created check box into JFrame  
  79.  frame.add(checkBox1);  
  80.  frame.add(checkBox2);  
  81.  frame.add(checkBox3);  
  82.  frame.add(checkBox4);  
  83.   
  84.  //Add created button into JFrame  
  85.  frame.add(button);  
  86.   
  87.  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
  88.  frame.setSize(350,200);  
  89.  frame.setVisible(true);  
  90. }  
  91.   
  92. //Main method  
  93. public static void main(String[]args)  
  94. {  
  95.  GetSelectedJCheckBox gsjcb=new GetSelectedJCheckBox();  
  96. }