Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package spp;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import javax.swing.JOptionPane;
- /**
- *
- * @author tokek
- */
- public class login extends javax.swing.JFrame {
- //deklarasi
- Connection con;
- Statement stat;
- ResultSet rs;
- String sql;
- /**
- * Creates new form login
- */
- public login() {
- initComponents();
- //pemanggilan fungsi koneksi yg sudah dibuat
- koneksi DB = new koneksi();
- DB.config();
- con = DB.con;
- stat = DB.stm;
- }
- /**
- * 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.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jMenuItem1 = new javax.swing.JMenuItem();
- jLabel3 = new javax.swing.JLabel();
- jPanel1 = new javax.swing.JPanel();
- txtusername = new javax.swing.JTextField();
- txtpassword = new javax.swing.JPasswordField();
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- login = new javax.swing.JButton();
- jMenuItem1.setText("jMenuItem1");
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jLabel3.setBackground(new java.awt.Color(204, 204, 0));
- jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
- jLabel3.setText("SILAHKAN LOGIN APLIKASI PEMBAYARAN SPP ");
- jPanel1.setBackground(new java.awt.Color(0, 255, 255));
- jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Masukan Disini"));
- txtusername.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txtusernameActionPerformed(evt);
- }
- });
- jLabel1.setText("Username");
- jLabel2.setText("Password");
- login.setText("Login");
- login.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- loginActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(0, 0, Short.MAX_VALUE)
- .addComponent(login))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel1)
- .addComponent(jLabel2))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(txtpassword, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
- .addComponent(txtusername))))
- .addContainerGap())
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(txtusername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel1))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(txtpassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel2))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
- .addComponent(login))
- );
- 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(44, 44, 44)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(17, 17, 17)
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING))
- .addContainerGap(47, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addContainerGap(18, Short.MAX_VALUE)
- .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap())
- );
- pack();
- }// </editor-fold>
- private void txtusernameActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void loginActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- try{
- sql = "SELECT * FROM admin WHERE username='"+txtusername.getText()+"' AND password='"+txtpassword.getText()+"'";
- rs = stat.executeQuery(sql);
- if (rs.next()){
- if(txtusername.getText().equals(rs.getString("username")) && txtpassword.getText().equals(rs.getString("password"))){
- JOptionPane.showMessageDialog(null, "berhasil Login");}
- new menuawal().setVisible(true);
- }else {
- JOptionPane.showMessageDialog(null, "username atau password salah");
- }
- }catch (Exception e){
- JOptionPane.showMessageDialog(this, e.getMessage());
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new login().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JMenuItem jMenuItem1;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JButton login;
- private javax.swing.JPasswordField txtpassword;
- private javax.swing.JTextField txtusername;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement