Пример #1
0
  public void actionPerformed(ActionEvent e) {
    p2.str1 = fn1.getText();
    p2.str2 = ln1.getText();
    p2.str3 = un1.getText();
    p2.str4 = ps11.getText();
    p2.str5 = eid1.getText();
    p2.str6 = ps21.getText();
    p2.str7 = mb1.getText();
    p2.str8 = cct1.getText();
    p2.str9 = hquali1.getText();
    p2.str10 = dober1.getText();
    p2.str11 = dober2.getText();
    p2.str12 = dober3.getText();
    p2.str13 = p2.str10 + "/" + p2.str11 + "/" + p2.str12;

    boolean bl1, bl2, bl3, bl4, bl5, bl6, bl7, bl8, bl9;
    bl1 = false;
    bl2 = false;
    bl3 = false;
    bl4 = false;
    bl5 = false;
    bl6 = false;
    bl7 = false;
    bl8 = false;

    if (str1.length() > 0) {
      // er1.setForeground(null);
      er1.setText("");
      fn1.setBorder(BorderFactory.createLineBorder(Color.GRAY));
      bl1 = true;
      repaint();
    } else {
      er1.setForeground(Color.red);
      er1.setText("(First name can't be null)");
      fn1.setBorder(BorderFactory.createLineBorder(Color.red));
      repaint();
    }

    if (str3.length() > 0) {
      er3.setText("");
      un1.setBorder(BorderFactory.createLineBorder(Color.GRAY));
      bl2 = true;
      repaint();

    } else {
      er3.setForeground(Color.red);
      er3.setText("(Username can't be null)");
      un1.setBorder(BorderFactory.createLineBorder(Color.red));
      repaint();
    }

    if (str5.length() > 0) {
      er6.setText("");
      eid1.setBorder(BorderFactory.createLineBorder(Color.GRAY));
      bl3 = true;
      repaint();

    } else {
      er6.setForeground(Color.red);
      er6.setText("(email id can't be null)");
      eid1.setBorder(BorderFactory.createLineBorder(Color.red));
      repaint();
    }

    if (str4.length() > 0) {
      er4.setText("");
      ps11.setBorder(BorderFactory.createLineBorder(Color.GRAY));
      bl4 = true;
      repaint();

    } else {
      er4.setForeground(Color.red);
      er4.setText("(Password can't be null)");
      ps11.setBorder(BorderFactory.createLineBorder(Color.red));
      repaint();
    }

    if ((str4.equals(str6))) {
      str6 = str4;
      er5.setForeground(null);
      er5.setText("");
      ps21.setBorder(BorderFactory.createLineBorder(Color.GRAY));
      bl5 = true;
      repaint();

    } else {
      er5.setForeground(Color.red);
      er5.setText("(both pwd should be same)");
      ps21.setBorder(BorderFactory.createLineBorder(Color.red));
      repaint();
    }
    if (str7.length() == 10) {
      er7.setText("");
      mb1.setBorder(BorderFactory.createLineBorder(Color.GRAY));
      bl6 = true;
      repaint();

    } else {
      er7.setForeground(Color.red);
      er7.setText("(number should be of 10 digit)");
      mb1.setBorder(BorderFactory.createLineBorder(Color.red));
      repaint();
    }
    if (str8.length() > 0) {
      er8.setText("");
      cct1.setBorder(BorderFactory.createLineBorder(Color.GRAY));
      bl7 = true;
      repaint();

    } else {
      er8.setForeground(Color.red);
      er8.setText("(Current City can't be null)");
      cct1.setBorder(BorderFactory.createLineBorder(Color.red));
      repaint();
    }
    if (str9.length() > 0) {
      er9.setText("");
      hquali1.setBorder(BorderFactory.createLineBorder(Color.GRAY));
      bl8 = true;
      repaint();

    } else {
      er9.setForeground(Color.red);
      er9.setText("(Highest Qualif. can't be null)");
      hquali1.setBorder(BorderFactory.createLineBorder(Color.red));
      repaint();
    }

    try {
      if ((bl1 && bl2 && bl3 && bl4 && bl5 && bl6 && bl7 && bl8) == true) {
        JOptionPane.showMessageDialog(null, "Data submitting ");
        p2.goer();
      }
    } catch (Exception e3) {
    }
  }
  public Design() throws Exception {
    super.setBackground(Color.BLACK);
    this.setTitle("");
    con = getContentPane();
    con.setLayout(null);
    dim = tk.getDefaultToolkit().getScreenSize();
    this.setTitle("Customer Peer Login");

    l1 = new JLabel(new ImageIcon("plain.jpg"));
    l1.setBounds(0, 0, 400, 400);
    con.add(l1);
    l1.setBorder(BorderFactory.createEtchedBorder(5, Color.black, Color.black));

    title = new JLabel("CUSTOMER PEER LOGIN ");
    title.setFont(new Font("Bookman Old Style", Font.ROMAN_BASELINE, 20));
    title.setForeground(Color.red);
    title.setBounds(80, 30, 300, 30);
    l1.add(title);

    l4 = new JLabel("CMACHINE NAME");
    l4.setFont(new Font("Bookman Old Style", Font.BOLD, 16));
    l4.setForeground(Color.BLUE);
    l4.setBounds(70, 100, 160, 20);
    //	l4.setBorder(BorderFactory.createEtchedBorder(5,Color.green,Color.green));

    l1.add(l4);
    jtf2 = new JTextField();
    jtf2.setBounds(250, 100, 100, 20);
    jtf2.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green));

    l1.add(jtf2);

    l2 = new JLabel("CUSER LOGIN");
    l2.setFont(new Font("Bookman Old Style", Font.BOLD, 16));
    l2.setForeground(Color.blue);
    l2.setBounds(70, 150, 120, 20);
    l1.add(l2);

    jtf1 = new JTextField();
    jtf1.setBounds(250, 150, 100, 20);
    jtf1.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green));

    l1.add(jtf1);

    l3 = new JLabel("CPASSWORD");
    l3.setFont(new Font("Bookman Old Style", Font.BOLD, 16));
    l3.setForeground(Color.blue);
    l3.setBounds(70, 200, 120, 20);
    l1.add(l3);

    jptf1 = new JPasswordField();
    jptf1.setBounds(250, 200, 100, 20);
    jptf1.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green));

    l1.add(jptf1);

    JLabel l4 = new JLabel("DAgent");
    l4.setFont(new Font("Bookman Old Style", Font.BOLD, 16));
    l4.setForeground(Color.blue);
    l4.setBounds(70, 250, 120, 20);
    l1.add(l4);

    box = new JComboBox();
    box.setBounds(250, 250, 100, 20);
    box.setBorder(BorderFactory.createEtchedBorder(5, Color.green, Color.green));
    l1.add(box);

    b2 = new JButton("Register");
    b2.setBounds(50, 300, 100, 20);
    l1.add(b2);
    b2.setBorder(BorderFactory.createEtchedBorder(10, Color.BLUE, Color.BLUE));

    b3 = new JButton("Login");
    b3.setBounds(150, 300, 100, 20);
    b3.setBorder(BorderFactory.createEtchedBorder(10, Color.BLUE, Color.BLUE));
    l1.add(b3);

    b1 = new JButton("Cancel");
    b1.setBounds(250, 300, 100, 20);
    b1.setBorder(BorderFactory.createEtchedBorder(10, Color.BLUE, Color.BLUE));

    l1.add(b1);

    b1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent we) {

            dispose();
          }
        });

    try {

      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      conn = DriverManager.getConnection("jdbc:odbc:agent");

    } catch (Exception exp) {

    }

    try {
      Statement satem = conn.createStatement();
      ResultSet rsatem = satem.executeQuery("select * from Dagent");
      while (rsatem.next()) {
        String namem = rsatem.getString("uname");
        box.addItem(namem);
      }

    } catch (Exception expo1) {

    }

    b2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent we) {

            String username = jtf1.getText().trim();
            String password = jptf1.getText().trim();
            String mechine = jtf2.getText().trim();
            String dname = box.getSelectedItem().toString();
            int porte = 0;

            try {
              Statement sate = conn.createStatement();
              ResultSet rsate =
                  sate.executeQuery("select * from Dagent where uname='" + dname + "'");
              if (rsate.next()) {
                servermachine = rsate.getString("umechine");
                porte = rsate.getInt("ulistport");
                System.out.println(servermachine);
              }
              System.out.println(servermachine);

            } catch (Exception exp) {
              exp.printStackTrace();
            }

            try {
              packet p = new packet();
              p.setaction("Creg");
              p.setCuser(username);
              p.setCpass(password);
              p.setCmname(mechine);
              p.setCDpeer(dname);
              Socket soc = new Socket(servermachine, porte);
              ObjectOutputStream out = new ObjectOutputStream(soc.getOutputStream());
              out.writeObject(p);
              ObjectInputStream in = new ObjectInputStream(soc.getInputStream());
              packet rpac = (packet) in.readObject();
              if (rpac.getaction().equals("ok")) {

                JOptionPane.showMessageDialog(null, "Sucessfully Registered");

                jtf2.setText("");
                jtf1.setText("");
                jptf1.setText("");

              } else {

                JOptionPane.showMessageDialog(null, "Already Registered");
                jtf2.setText("");
                jtf1.setText("");
                jptf1.setText("");
              }

            } catch (Exception exp) {
            }
          }
        });

    b3.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent we) {

            String username = jtf1.getText().trim();
            String password = jptf1.getText().trim();
            String mechine = jtf2.getText().trim();
            String Dname = box.getSelectedItem().toString();

            int porte = 0;

            try {
              Statement sate = conn.createStatement();
              ResultSet rsate =
                  sate.executeQuery("select * from Dagent where uname='" + Dname + "'");
              if (rsate.next()) {
                servermachine = rsate.getString("umechine");
                porte = rsate.getInt("ulistport");
                System.out.println(servermachine);
              }
              System.out.println(servermachine);

            } catch (Exception exp) {

            }

            try {

              packet p1 = new packet();
              p1.setaction("clogin");
              p1.setCuser(username);
              p1.setCpass(password);
              p1.setCmname(mechine);
              p1.setCDpeer(Dname);
              Socket soc1 = new Socket(servermachine, porte);
              ObjectOutputStream out1 = new ObjectOutputStream(soc1.getOutputStream());
              out1.writeObject(p1);
              ObjectInputStream in1 = new ObjectInputStream(soc1.getInputStream());
              packet rpac1 = (packet) in1.readObject();
              if (rpac1.getaction().equals("ok")) {
                int port1 = 0;
                try {

                  int portm = rpac1.getCport();
                  System.out.println("XXXXXXX" + portm);
                  //	JOptionPane.showMessageDialog(null,"Sucessfully Started");

                  new Listen(portm);
                  new process(username, portm);
                  dispose();
                } catch (Exception exp) {
                }
              } else {
                JOptionPane.showMessageDialog(
                    null, "Enter valid username and password", "Server reply", 2);
                jtf1.setText("");
                jtf2.setText("");
                jptf1.setText("");
              }

            } catch (Exception exp) {
            }
          }
        });

    setSize(400, 400);
    show();
    setLocation(150, 100);
    setResizable(false);
  }