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

class NewUser //extends Variable implements ActionListener
{
 JInternalFrame ifrm;
 JLabel lbleid,lblena,lbleadd,lbletp,lbleage,lbluse,lblpas,lblcat;
 JTextField txteid,txtuse,txtena,txteadd,txtetp,txteage,txtpas;
 JButton btnadd,btndelete,btnclear,btnsearch,btnupdate;
 JComboBox cmbcat ; 

 public JInternalFrame display()

{

        JInternalFrame ifrm=new JInternalFrame("User Process",true,true,false,false);

    //  ifrm.getContentPane().setLayout(null);

        ifrm.setSize(600,600);
        ifrm.setLocation(0,0);
        ifrm.setResizable(false);
        ifrm.setDefaultCloseOperation(ifrm.DISPOSE_ON_CLOSE);
        ifrm.setVisible(true);

        JPanel p;
        p=new JPanel();
        p.setLayout(null);  

        //pic =new JLabel(new ImageIcon("Employee.jpg"));
        //pic.setBounds(0,0,800,600);

        lbleid=new JLabel("Employee ID");
        lblena=new JLabel("Name");
        lbleadd=new JLabel("Address");
        lbletp=new JLabel("TPNo");
        lbleage=new JLabel("Age");
        lbluse=new JLabel("User ID");
        lblpas=new JLabel("Password");
        //lblcat=new JLabel("Category");

        txteid=new JTextField(20);
        txtuse=new JTextField(20);
        txtena=new JTextField(15);
        txteadd=new JTextField(25);
        txtetp=new JTextField(14);
        txteage=new JTextField(3);
        txtpas=new JTextField(15);

        //cmbcat=new JComboBox(cat);

        btnadd=new JButton("Add");
        btndelete=new JButton("Delete");
        btnclear=new JButton("Clear");
        btnsearch=new JButton("Search");
        btnupdate=new JButton("Update");

        lbleid.setBounds(100,110,100,25);
        lblena.setBounds(100,140,100,25);   
        lbleadd.setBounds(100,170,120,25);
        lbletp.setBounds(100,200,120,25);
        lbleage.setBounds(100,230,160,25);
        lbluse.setBounds(100,260,120,25);
        lblpas.setBounds(100,290,100,25);
        lblcat.setBounds(100,320,100,25);

        txteid.setBounds(180,110,125,25);
        txtuse.setBounds(180,140,125,25);
        txtena.setBounds(180,170,125,25);
        txteadd.setBounds(180,200,125,25);
        txtetp.setBounds(180,230,125,25);
        txteage.setBounds(180,260,125,25);
        txtpas.setBounds(180,290,125,25);   

        //cmbcat.setBounds(180,320,125,25);

        btnadd.setBounds(350,120,75,25);
        btndelete.setBounds(350,160,75,25);
        btnclear.setBounds(350,200,75,25);
        btnsearch.setBounds(350,240,75,25);
        btnupdate.setBounds(350,280,75,25);

        //btnadd.addActionListener(this);
        //btndelete.addActionListener(this);
        //btnclear.addActionListener(this);
        //btnsearch.addActionListener(this);
        //btnupdate.addActionListener(this);

        p.add(lbleid);
        p.add(txteid);
        p.add(lblpas);
        p.add(lblena);
        p.add(lbleadd);
        p.add(lbletp);
        p.add(lbleage);
        p.add(lbluse);
        p.add(lblcat);
        p.add(txtpas);
        p.add(txtena);
        p.add(txteadd);
        p.add(txtetp);
        p.add(txteage);
        p.add(txtuse);
        p.add(btnadd);
        p.add(btndelete);
        p.add(btnclear);
        p.add(btnsearch);
        p.add(btnupdate);
//      p.add(cmbcat);
        //p.add(pic);

    ifrm.getContentPane().add(p);
            return(ifrm);
    }

        // public void actionPerformed(ActionEvent e) 
         // {

       //   try
         //  {
         //  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

           //Establish connection 

         //  Connection con=DriverManager.getConnection("jdbc:odbc:PC","","");


        // if(e.getSource()==btnadd){

        //  if((txteid.getText()).equals("")){  
        //      JOptionPane.showMessageDialog(null, "Enter User ID ");
        //  }
        //  else if((txtena.getText()).equals("")){
        //      JOptionPane.showMessageDialog(null, "Enter Employee Name");
        //      }
        //  else if((txteadd.getText()).equals("")){
        //      JOptionPane.showMessageDialog(null, "Enter Employee Address");

        //      }
        //  else if((txtetp.getText()).equals("")){
        //      JOptionPane.showMessageDialog(null, "Enter Employee TPNo");
        //      }
        //  else if((txteage.getText()).equals("")){
        //      JOptionPane.showMessageDialog(null, "Enter Employee Age");
        //      }
        //  else if((txtpas.getText()).equals("")){
        //      JOptionPane.showMessageDialog(null, "Enter Login Password");    
        //      }
        //  else{

        //   PreparedStatement smt1=con.prepareStatement("insert into Employee values (?,?,?,?,?,?,?)");
           //Fill up the parameter values from
        //   smt1.setString(1,txteid.getText());
        //   smt1.setString(2,txtena.getText());
       //    smt1.setString(3,txteadd.getText());
       //    smt1.setString(4,txtetp.getText());
       //    smt1.setString(5,txteage.getText());
       //    smt1.setString(6,txtpas.getText());
      //     smt1.setString(7,(String)cmbcat.getSelectedItem());
       //    smt1.executeUpdate();

       //    con.close();
       //    JOptionPane.showMessageDialog(null,"Insertion Successfully completed");
      //     txteid.setText("");
      //     txtpas.setText("");
       //    txtena.setText("");
       //      txteadd.setText("");
      //       txtetp.setText("");
      //       txteage.setText("");
       //      cmbcat.setSelectedIndex(-1);   
       //       }
     //      }
       //       if(e.getSource()==btndelete){

      //       PreparedStatement smt2=con.prepareStatement("delete from Employee where Emp_ID=?");
      //    smt2.setString(1,txteid.getText());
       //    smt2.executeUpdate();

       //    con.close();
      //     JOptionPane.showMessageDialog(null,"Users details have been deleted");
       //    txteid.setText("");
       //      txtena.setText("");
      //       txteadd.setText("");             
       //      txtetp.setText("");
       //      txteage.setText("");
       //      txtpas.setText("");
       //      cmbcat.setSelectedIndex(-1);         
       //     }

 //   if(e.getSource()==btnclear){

   //       txteid.setText("");
  //        txtena.setText("");
  //        txteadd.setText("");
   //       txtetp.setText("");
   //       txteage.setText("");
  //        txtpas.setText("");
   //       cmbcat.setSelectedIndex(-1);   
    //      }

   //   if(e.getSource()==btnsearch){

     //      PreparedStatement smt6=con.prepareStatement("select * from Employee where Emp_ID=? ");
    //       smt6.setString(1,txteid.getText());

      //    ResultSet rs=smt6.executeQuery();

    //   while (rs.next())
    //   {
    //   txtena.setText(rs.getString("Emp_Name"));
    //   txteadd.setText(rs.getString("Emp_Address"));
   //    txtetp.setText(rs.getString("Emp_TPNo"));
   //    txteage.setText(rs.getString("Emp_Age"));
   //    txtpas.setText(rs.getString("Password"));
   //    cmbcat.setSelectedItem(rs.getString("Category")); 
    //   JOptionPane.showMessageDialog(null,"User Records are Founded");
    //   }
   //    con.close();       
   //    }

  //   if (e.getSource()==btnupdate){

     //       PreparedStatement smt7=con.prepareStatement("update Employee set Emp_Name=?,Emp_Address=?,Emp_TPNo=?,Emp_Age=?,Password=?,Category=?  where Emp_ID=?");
           //Fill up the parameter values from
   //        smt7.setString(1,txtena.getText());
     //      smt7.setString(2,txteadd.getText());
    //       smt7.setString(3,txtetp.getText());
     //      smt7.setString(4,txteage.getText());
     //      smt7.setString(5,txtpas.getText());
    //       smt7.setString(6,(String)cmbcat.getSelectedItem());
    //       smt7.setString(7,txteid.getText());

   //        smt7.executeUpdate();

     //      con.close();
     //      JOptionPane.showMessageDialog(null,"Updation Successfully completed");
     //      txteid.setText("");
     //      txtena.setText("");
      //       txteadd.setText("");
     //        txtetp.setText("");
     //        txteage.setText("");     
      //       txtpas.setText("");
     //        cmbcat.setSelectedIndex(-1);     
    //      } 
    //   }
   //  catch (Exception exception)
   //    {
   //       JOptionPane.showMessageDialog(null,exception);
    //   }
//}

//public static void main(String[]arg)
    //  {
    //  NewUser ob=new NewUser();
    //  }
//}

Edited by Dani: Formatting fixed

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by adams161
0
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

class NewUser //extends Variable implements ActionListener
{
 JInternalFrame ifrm;
 JLabel lbleid,lblena,lbleadd,lbletp,lbleage,lbluse,lblpas,lblcat;
 JTextField txteid,txtuse,txtena,txteadd,txtetp,txteage,txtpas;
 JButton btnadd,btndelete,btnclear,btnsearch,btnupdate;
 JComboBox cmbcat ; 

 public JInternalFrame display()

{

        JInternalFrame ifrm=new JInternalFrame("User Process",true,true,false,false);

    //  ifrm.getContentPane().setLayout(null);

        ifrm.setSize(600,600);
        ifrm.setLocation(0,0);
        ifrm.setResizable(false);
        ifrm.setDefaultCloseOperation(ifrm.DISPOSE_ON_CLOSE);
        ifrm.setVisible(true);

        JPanel p;
        p=new JPanel();
        p.setLayout(null);  

        //pic =new JLabel(new ImageIcon("Employee.jpg"));
        //pic.setBounds(0,0,800,600);

        lbleid=new JLabel("Employee ID");
        lblena=new JLabel("Name");
        lbleadd=new JLabel("Address");
        lbletp=new JLabel("TPNo");
        lbleage=new JLabel("Age");
        lbluse=new JLabel("User ID");
        lblpas=new JLabel("Password");
        //lblcat=new JLabel("Category");

        txteid=new JTextField(20);
        txtuse=new JTextField(20);
        txtena=new JTextField(15);
        txteadd=new JTextField(25);
        txtetp=new JTextField(14);
        txteage=new JTextField(3);
        txtpas=new JTextField(15);

        //cmbcat=new JComboBox(cat);

        btnadd=new JButton("Add");
        btndelete=new JButton("Delete");
        btnclear=new JButton("Clear");
        btnsearch=new JButton("Search");
        btnupdate=new JButton("Update");

        lbleid.setBounds(100,110,100,25);
        lblena.setBounds(100,140,100,25);   
        lbleadd.setBounds(100,170,120,25);
        lbletp.setBounds(100,200,120,25);
        lbleage.setBounds(100,230,160,25);
        lbluse.setBounds(100,260,120,25);
        lblpas.setBounds(100,290,100,25);
        lblcat.setBounds(100,320,100,25);

        txteid.setBounds(180,110,125,25);
        txtuse.setBounds(180,140,125,25);
        txtena.setBounds(180,170,125,25);
        txteadd.setBounds(180,200,125,25);
        txtetp.setBounds(180,230,125,25);
        txteage.setBounds(180,260,125,25);
        txtpas.setBounds(180,290,125,25);   

        //cmbcat.setBounds(180,320,125,25);

        btnadd.setBounds(350,120,75,25);
        btndelete.setBounds(350,160,75,25);
        btnclear.setBounds(350,200,75,25);
        btnsearch.setBounds(350,240,75,25);
        btnupdate.setBounds(350,280,75,25);

        //btnadd.addActionListener(this);
        //btndelete.addActionListener(this);
        //btnclear.addActionListener(this);
        //btnsearch.addActionListener(this);
        //btnupdate.addActionListener(this);

        p.add(lbleid);
        p.add(txteid);
        p.add(lblpas);
        p.add(lblena);
        p.add(lbleadd);
        p.add(lbletp);
        p.add(lbleage);
        p.add(lbluse);
        p.add(lblcat);
        p.add(txtpas);
        p.add(txtena);
        p.add(txteadd);
        p.add(txtetp);
        p.add(txteage);
        p.add(txtuse);
        p.add(btnadd);
        p.add(btndelete);
        p.add(btnclear);
        p.add(btnsearch);
        p.add(btnupdate);
//      p.add(cmbcat);
        //p.add(pic);

    ifrm.getContentPane().add(p);
            return(ifrm);
    }

        // public void actionPerformed(ActionEvent e) 
         // {

       //   try
         //  {
         //  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

           //Establish connection 

         //  Connection con=DriverManager.getConnection("jdbc:odbc:PC","","");


        // if(e.getSource()==btnadd){

        //  if((txteid.getText()).equals("")){  
        //      JOptionPane.showMessageDialog(null, "Enter User ID ");
        //  }
        //  else if((txtena.getText()).equals("")){
        //      JOptionPane.showMessageDialog(null, "Enter Employee Name");
        //      }
        //  else if((txteadd.getText()).equals("")){
        //      JOptionPane.showMessageDialog(null, "Enter Employee Address");

        //      }
        //  else if((txtetp.getText()).equals("")){
        //      JOptionPane.showMessageDialog(null, "Enter Employee TPNo");
        //      }
        //  else if((txteage.getText()).equals("")){
        //      JOptionPane.showMessageDialog(null, "Enter Employee Age");
        //      }
        //  else if((txtpas.getText()).equals("")){
        //      JOptionPane.showMessageDialog(null, "Enter Login Password");    
        //      }
        //  else{

        //   PreparedStatement smt1=con.prepareStatement("insert into Employee values (?,?,?,?,?,?,?)");
           //Fill up the parameter values from
        //   smt1.setString(1,txteid.getText());
        //   smt1.setString(2,txtena.getText());
       //    smt1.setString(3,txteadd.getText());
       //    smt1.setString(4,txtetp.getText());
       //    smt1.setString(5,txteage.getText());
       //    smt1.setString(6,txtpas.getText());
      //     smt1.setString(7,(String)cmbcat.getSelectedItem());
       //    smt1.executeUpdate();

       //    con.close();
       //    JOptionPane.showMessageDialog(null,"Insertion Successfully completed");
      //     txteid.setText("");
      //     txtpas.setText("");
       //    txtena.setText("");
       //      txteadd.setText("");
      //       txtetp.setText("");
      //       txteage.setText("");
       //      cmbcat.setSelectedIndex(-1);   
       //       }
     //      }
       //       if(e.getSource()==btndelete){

      //       PreparedStatement smt2=con.prepareStatement("delete from Employee where Emp_ID=?");
      //    smt2.setString(1,txteid.getText());
       //    smt2.executeUpdate();

       //    con.close();
      //     JOptionPane.showMessageDialog(null,"Users details have been deleted");
       //    txteid.setText("");
       //      txtena.setText("");
      //       txteadd.setText("");             
       //      txtetp.setText("");
       //      txteage.setText("");
       //      txtpas.setText("");
       //      cmbcat.setSelectedIndex(-1);         
       //     }

 //   if(e.getSource()==btnclear){

   //       txteid.setText("");
  //        txtena.setText("");
  //        txteadd.setText("");
   //       txtetp.setText("");
   //       txteage.setText("");
  //        txtpas.setText("");
   //       cmbcat.setSelectedIndex(-1);   
    //      }

   //   if(e.getSource()==btnsearch){

     //      PreparedStatement smt6=con.prepareStatement("select * from Employee where Emp_ID=? ");
    //       smt6.setString(1,txteid.getText());

      //    ResultSet rs=smt6.executeQuery();

    //   while (rs.next())
    //   {
    //   txtena.setText(rs.getString("Emp_Name"));
    //   txteadd.setText(rs.getString("Emp_Address"));
   //    txtetp.setText(rs.getString("Emp_TPNo"));
   //    txteage.setText(rs.getString("Emp_Age"));
   //    txtpas.setText(rs.getString("Password"));
   //    cmbcat.setSelectedItem(rs.getString("Category")); 
    //   JOptionPane.showMessageDialog(null,"User Records are Founded");
    //   }
   //    con.close();       
   //    }

  //   if (e.getSource()==btnupdate){

     //       PreparedStatement smt7=con.prepareStatement("update Employee set Emp_Name=?,Emp_Address=?,Emp_TPNo=?,Emp_Age=?,Password=?,Category=?  where Emp_ID=?");
           //Fill up the parameter values from
   //        smt7.setString(1,txtena.getText());
     //      smt7.setString(2,txteadd.getText());
    //       smt7.setString(3,txtetp.getText());
     //      smt7.setString(4,txteage.getText());
     //      smt7.setString(5,txtpas.getText());
    //       smt7.setString(6,(String)cmbcat.getSelectedItem());
    //       smt7.setString(7,txteid.getText());

   //        smt7.executeUpdate();

     //      con.close();
     //      JOptionPane.showMessageDialog(null,"Updation Successfully completed");
     //      txteid.setText("");
     //      txtena.setText("");
      //       txteadd.setText("");
     //        txtetp.setText("");
     //        txteage.setText("");     
      //       txtpas.setText("");
     //        cmbcat.setSelectedIndex(-1);     
    //      } 
    //   }
   //  catch (Exception exception)
   //    {
   //       JOptionPane.showMessageDialog(null,exception);
    //   }
//}

//public static void main(String[]arg)
    //  {
    //  NewUser ob=new NewUser();
    //  }
//}

please correct the error and help me i can not understand please help me

Edited by mike_2000_17: Fixed formatting

0

Please explain about the error. Where is it? When does it happen? Is it compile time or execution time or logic.
What is the program supposed to do?

One BIG problem I see is that you don't use a layout manager.

Also please use code tags when posting code. See icon above, to right.

Edited by NormR1: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.