Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.00 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package spp;
  7. import java.sql.Connection;
  8. import java.sql.ResultSet;
  9. import java.sql.Statement;
  10. import javax.swing.JOptionPane;
  11. /**
  12. *
  13. * @author tokek
  14. */
  15. public class login extends javax.swing.JFrame {
  16. //deklarasi
  17. Connection con;
  18. Statement stat;
  19. ResultSet rs;
  20. String sql;
  21.  
  22. /**
  23. * Creates new form login
  24. */
  25. public login() {
  26. initComponents();
  27. //pemanggilan fungsi koneksi yg sudah dibuat
  28. koneksi DB = new koneksi();
  29. DB.config();
  30. con = DB.con;
  31. stat = DB.stm;
  32. }
  33.  
  34. /**
  35. * This method is called from within the constructor to initialize the form.
  36. * WARNING: Do NOT modify this code. The content of this method is always
  37. * regenerated by the Form Editor.
  38. */
  39. @SuppressWarnings("unchecked")
  40. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  41. private void initComponents() {
  42.  
  43. jMenuItem1 = new javax.swing.JMenuItem();
  44. jLabel3 = new javax.swing.JLabel();
  45. jPanel1 = new javax.swing.JPanel();
  46. txtusername = new javax.swing.JTextField();
  47. txtpassword = new javax.swing.JPasswordField();
  48. jLabel1 = new javax.swing.JLabel();
  49. jLabel2 = new javax.swing.JLabel();
  50. login = new javax.swing.JButton();
  51.  
  52. jMenuItem1.setText("jMenuItem1");
  53.  
  54. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  55.  
  56. jLabel3.setBackground(new java.awt.Color(204, 204, 0));
  57. jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
  58. jLabel3.setText("SILAHKAN LOGIN APLIKASI PEMBAYARAN SPP ");
  59.  
  60. jPanel1.setBackground(new java.awt.Color(0, 255, 255));
  61. jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Masukan Disini"));
  62.  
  63. txtusername.addActionListener(new java.awt.event.ActionListener() {
  64. public void actionPerformed(java.awt.event.ActionEvent evt) {
  65. txtusernameActionPerformed(evt);
  66. }
  67. });
  68.  
  69. jLabel1.setText("Username");
  70.  
  71. jLabel2.setText("Password");
  72.  
  73. login.setText("Login");
  74. login.addActionListener(new java.awt.event.ActionListener() {
  75. public void actionPerformed(java.awt.event.ActionEvent evt) {
  76. loginActionPerformed(evt);
  77. }
  78. });
  79.  
  80. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  81. jPanel1.setLayout(jPanel1Layout);
  82. jPanel1Layout.setHorizontalGroup(
  83. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  84. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
  85. .addContainerGap()
  86. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  87. .addGroup(jPanel1Layout.createSequentialGroup()
  88. .addGap(0, 0, Short.MAX_VALUE)
  89. .addComponent(login))
  90. .addGroup(jPanel1Layout.createSequentialGroup()
  91. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  92. .addComponent(jLabel1)
  93. .addComponent(jLabel2))
  94. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
  95. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  96. .addComponent(txtpassword, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
  97. .addComponent(txtusername))))
  98. .addContainerGap())
  99. );
  100. jPanel1Layout.setVerticalGroup(
  101. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  102. .addGroup(jPanel1Layout.createSequentialGroup()
  103. .addContainerGap()
  104. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  105. .addComponent(txtusername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  106. .addComponent(jLabel1))
  107. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  108. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  109. .addComponent(txtpassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  110. .addComponent(jLabel2))
  111. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
  112. .addComponent(login))
  113. );
  114.  
  115. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  116. getContentPane().setLayout(layout);
  117. layout.setHorizontalGroup(
  118. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  119. .addGroup(layout.createSequentialGroup()
  120. .addGap(44, 44, 44)
  121. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  122. .addGroup(layout.createSequentialGroup()
  123. .addGap(17, 17, 17)
  124. .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  125. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
  126. .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING))
  127. .addContainerGap(47, Short.MAX_VALUE))
  128. );
  129. layout.setVerticalGroup(
  130. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  131. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  132. .addContainerGap(18, Short.MAX_VALUE)
  133. .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
  134. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  135. .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  136. .addContainerGap())
  137. );
  138.  
  139. pack();
  140. }// </editor-fold>
  141.  
  142. private void txtusernameActionPerformed(java.awt.event.ActionEvent evt) {
  143. // TODO add your handling code here:
  144. }
  145.  
  146. private void loginActionPerformed(java.awt.event.ActionEvent evt) {
  147. // TODO add your handling code here:
  148. try{
  149. sql = "SELECT * FROM admin WHERE username='"+txtusername.getText()+"' AND password='"+txtpassword.getText()+"'";
  150. rs = stat.executeQuery(sql);
  151. if (rs.next()){
  152. if(txtusername.getText().equals(rs.getString("username")) && txtpassword.getText().equals(rs.getString("password"))){
  153. JOptionPane.showMessageDialog(null, "berhasil Login");}
  154. new menuawal().setVisible(true);
  155. }else {
  156. JOptionPane.showMessageDialog(null, "username atau password salah");
  157. }
  158. }catch (Exception e){
  159. JOptionPane.showMessageDialog(this, e.getMessage());
  160. }
  161. }
  162.  
  163. /**
  164. * @param args the command line arguments
  165. */
  166. public static void main(String args[]) {
  167. /* Set the Nimbus look and feel */
  168. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  169. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  170. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  171. */
  172. try {
  173. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  174. if ("Nimbus".equals(info.getName())) {
  175. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  176. break;
  177. }
  178. }
  179. } catch (ClassNotFoundException ex) {
  180. java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  181. } catch (InstantiationException ex) {
  182. java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  183. } catch (IllegalAccessException ex) {
  184. java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  185. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  186. java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  187. }
  188. //</editor-fold>
  189.  
  190. /* Create and display the form */
  191. java.awt.EventQueue.invokeLater(new Runnable() {
  192. public void run() {
  193. new login().setVisible(true);
  194. }
  195. });
  196. }
  197.  
  198. // Variables declaration - do not modify
  199. private javax.swing.JLabel jLabel1;
  200. private javax.swing.JLabel jLabel2;
  201. private javax.swing.JLabel jLabel3;
  202. private javax.swing.JMenuItem jMenuItem1;
  203. private javax.swing.JPanel jPanel1;
  204. private javax.swing.JButton login;
  205. private javax.swing.JPasswordField txtpassword;
  206. private javax.swing.JTextField txtusername;
  207. // End of variables declaration
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement