Пример #1
0
  private void LoginButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_LoginButtonActionPerformed
    // TODO add your handling code here:
    String sql = "select * from bruker where brukerNavn=? and brukerPassord=?";

    try {
      int userType = accountType.getSelectedIndex();

      pst = conn.prepareStatement(sql);
      pst.setString(1, UsrInput.getText());
      pst.setString(2, PswdInput.getText());
      rs = pst.executeQuery();

      if (rs.next()) {
        // JOptionPane.showMessageDialog(null,"Username and password is correct");
        close();
        if (userType == 0) {
          MainPage m = new MainPage();
          m.setVisible(true);
        } else {
          fMainPage fm = new fMainPage();
          fm.setVisible(true);
        }

      } else {
        JOptionPane.showMessageDialog(null, "Username or password is incorrect");
      }
    } catch (Exception e) {
      JOptionPane.showMessageDialog(null, e);
    }
  } // GEN-LAST:event_LoginButtonActionPerformed
Пример #2
0
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    PswdInput = new javax.swing.JPasswordField();
    RememberCheckBox = new javax.swing.JCheckBox();
    LoginButton = new javax.swing.JButton();
    UsrInput = new javax.swing.JTextField();
    UsernameText = new javax.swing.JLabel();
    PasswordText = new javax.swing.JLabel();
    accountType = new javax.swing.JComboBox();
    heading = new javax.swing.JLabel();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    addWindowListener(
        new java.awt.event.WindowAdapter() {
          public void windowOpened(java.awt.event.WindowEvent evt) {
            formWindowOpened(evt);
          }
        });

    RememberCheckBox.setText("Remember me");
    RememberCheckBox.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            RememberCheckBoxActionPerformed(evt);
          }
        });

    LoginButton.setText("Login");
    LoginButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            LoginButtonActionPerformed(evt);
          }
        });

    UsrInput.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            UsrInputActionPerformed(evt);
          }
        });

    UsernameText.setText("Username:"******"Password:"******"Student", "Foreleser", "Hjelpelærer"}));
    accountType.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            accountTypeActionPerformed(evt);
          }
        });

    heading.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
    heading.setText("IT og Informasjonssytem - IS-109 & IS-110");

    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(34, 34, 34)
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(heading, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(
                                layout
                                    .createSequentialGroup()
                                    .addGap(130, 130, 130)
                                    .addGroup(
                                        layout
                                            .createParallelGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(
                                                PswdInput,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                134,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(
                                                accountType,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                134,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGroup(
                                                layout
                                                    .createSequentialGroup()
                                                    .addGap(6, 6, 6)
                                                    .addComponent(
                                                        RememberCheckBox,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        128,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addComponent(
                                                LoginButton,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                128,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(
                                                UsrInput,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                134,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGroup(
                                                layout
                                                    .createSequentialGroup()
                                                    .addGap(36, 36, 36)
                                                    .addComponent(PasswordText))
                                            .addGroup(
                                                layout
                                                    .createSequentialGroup()
                                                    .addGap(32, 32, 32)
                                                    .addComponent(UsernameText)))
                                    .addPreferredGap(
                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                        114,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(40, Short.MAX_VALUE)));
    layout.setVerticalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addGap(54, 54, 54)
                    .addComponent(heading)
                    .addGap(43, 43, 43)
                    .addComponent(UsernameText)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(
                        UsrInput,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(PasswordText)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(
                        PswdInput,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(
                        accountType,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(RememberCheckBox)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(
                        LoginButton,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        49,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(69, Short.MAX_VALUE)));

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