コード例 #1
0
  Usermaster() {
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    x = dim.width;
    y = dim.height;
    setSize(x, y);
    setUndecorated(true);

    Container c = getContentPane();

    center =
        new JPanel() {
          public void paintComponent(Graphics g) {
            Toolkit kit = Toolkit.getDefaultToolkit();
            Image img = kit.getImage("Image/user.jpg");
            MediaTracker t = new MediaTracker(this);
            t.addImage(img, 0);
            while (true) {
              try {
                t.waitForAll();
                break;
              } catch (Exception ee) {
              }
            }
            g.drawImage(img, 0, 0, x, y, null);
          }
        };

    c.add(center);
    center.setLayout(null);

    titleLb =
        new JLabel(
            "<html><body ><font size='5'><b><i>&nbsp;&nbsp; User Name &nbsp;&nbsp;</b></i></font></body></html>");
    titleLb.setForeground(new Color(10, 110, 255));
    titleLb.setBounds(x / 2 + 50, x / 4, 150, 50);
    center.add(titleLb);

    output =
        new JLabel(
            "<html><body ><font size='5'><b><i>&nbsp;&nbsp; OUTPUT &nbsp;&nbsp;</b></i></font></body></html>");
    output.setForeground(Color.white);
    output.setBounds(x / 2 - 250, x / 6, 150, 50);
    center.add(output);

    login = new JButton(new ImageIcon("Image/logBut.gif"));
    login.setBorder(BorderFactory.createRaisedBevelBorder());
    login.setBounds(x / 2 + 100, x / 2 - 70, 100, 100);
    login.setBackground(Color.white);

    pass = new JPasswordField();
    pass.setToolTipText("Enter The Password To Payroll System");
    login.requestFocus();
    pass.setBorder(BorderFactory.createRaisedBevelBorder());
    pass.setForeground(new Color(10, 110, 255));
    pass.setFont(new Font("Arial", Font.BOLD, 22));
    pass.setCaretColor(Color.red);
    pass.setBounds(x / 2 + 50, x / 3, 200, 35);
    center.add(pass);
    center.add(login);

    pass.addKeyListener(
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            output.setText(
                "<html><body ><font size='5'><b><i>&nbsp;&nbsp; OUTPUT &nbsp;&nbsp;</b></i></font></body></html>");
            output.setForeground(Color.white);
          }
        });

    try {
      clsConnection connect = new clsConnection();
      conn = connect.setConnection(conn, "", "");
    } catch (Exception e) {
    }

    login.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              st = conn.createStatement();
              rs = st.executeQuery("select * from img");
              while (rs.next()) {
                if (pass.getText().equals(rs.getString(3))) {
                  setVisible(false);
                  URL url = closeSystem.class.getResource("spacemusic.au");
                  click = Applet.newAudioClip(url);
                  click.play();
                  paro.setVisible(true);
                } else {
                  pass.setText("");
                  pass.requestFocus();
                  output.setText("Fell");
                  output.setFont(new Font("Arial", Font.BOLD, 36));
                  output.setForeground(Color.red);
                }
              }
            } catch (Exception er) {
              System.out.println("Sorry\n" + er);
            }
          }
        });
  }
コード例 #2
0
  /** Initialize the contents of the frame. */
  private void initialize() {
    frame = new JFrame();
    frame.getContentPane().setBackground(new Color(153, 50, 204));
    frame.setBounds(100, 100, 725, 547);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(null);

    JLabel lblNewLabel = new JLabel("Username");
    lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 18));
    lblNewLabel.setBounds(119, 113, 146, 36);
    frame.getContentPane().add(lblNewLabel);

    textField = new JTextField();
    textField.setBounds(355, 122, 153, 22);
    frame.getContentPane().add(textField);
    textField.setColumns(10);

    JLabel lblNewLabel_1 = new JLabel("Password");
    lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 18));
    lblNewLabel_1.setBounds(119, 213, 87, 22);
    frame.getContentPane().add(lblNewLabel_1);

    JButton btnNewButton = new JButton("Back");
    btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 22));
    btnNewButton.setBounds(124, 313, 121, 36);
    frame.getContentPane().add(btnNewButton);

    JButton btnNewButton_1 = new JButton("Login");
    btnNewButton_1.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            try {
              String query = "select * from logindetails where UserName=? and Password=?";
              PreparedStatement pst = connect.prepareStatement(query);
              pst.setString(1, textField.getText());
              pst.setString(2, passwordField.getText());
              ResultSet rs = pst.executeQuery();
              if (rs.next()) {
                // JOptionPane.showMessageDialog(null, "connection successfull");
                ah.setVisible(true);
                frame.dispose();
              } else {
                JOptionPane.showMessageDialog(
                    null, "user credentials are wrong.Try again with correct credentials");
              }
            } catch (Exception e) {
              JOptionPane.showMessageDialog(null, e);
            }
          }
        });
    btnNewButton_1.setFont(new Font("Tahoma", Font.PLAIN, 22));
    btnNewButton_1.setBounds(424, 314, 97, 35);
    frame.getContentPane().add(btnNewButton_1);

    passwordField = new JPasswordField();
    passwordField.setBounds(355, 215, 166, 22);
    frame.getContentPane().add(passwordField);

    JLabel lblNewLabel_2 = new JLabel("Administrator Login");
    lblNewLabel_2.setForeground(new Color(128, 128, 128));
    lblNewLabel_2.setFont(new Font("Tahoma", Font.BOLD, 28));
    lblNewLabel_2.setBounds(199, 48, 309, 34);
    frame.getContentPane().add(lblNewLabel_2);
  }
  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);
  }