Advertisement
Guest User

LOGIN

a guest
Apr 7th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.25 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.  
  7. package rental;
  8.  
  9. import com.mysql.jdbc.Connection;
  10. import com.mysql.jdbc.Statement;
  11. import java.sql.ResultSet;
  12. import javax.swing.JOptionPane;
  13.  
  14. /**
  15. *
  16. * @author ECS
  17. */
  18. public class login extends javax.swing.JFrame {
  19. koneksi kn = new koneksi();
  20. Connection conn;
  21. Statement stt;
  22. ResultSet rs;
  23. String sql;
  24. /**
  25. * Creates new form login
  26. */
  27. public login() {
  28. initComponents();
  29. }
  30.  
  31.  
  32. /**
  33. * This method is called from within the constructor to initialize the form.
  34. * WARNING: Do NOT modify this code. The content of this method is always
  35. * regenerated by the Form Editor.
  36. */
  37. @SuppressWarnings("unchecked")
  38. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  39. private void initComponents() {
  40.  
  41. jComboBox1 = new javax.swing.JComboBox();
  42. panel2 = new java.awt.Panel();
  43. tpas = new javax.swing.JPasswordField();
  44. tnama = new javax.swing.JTextField();
  45. jLabel2 = new javax.swing.JLabel();
  46. jLabel3 = new javax.swing.JLabel();
  47. jButton1 = new javax.swing.JButton();
  48. jButton2 = new javax.swing.JButton();
  49. jLabel1 = new javax.swing.JLabel();
  50.  
  51. jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
  52.  
  53. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  54.  
  55. panel2.setBackground(new java.awt.Color(102, 204, 0));
  56.  
  57. tpas.addActionListener(new java.awt.event.ActionListener() {
  58. public void actionPerformed(java.awt.event.ActionEvent evt) {
  59. tpasActionPerformed(evt);
  60. }
  61. });
  62.  
  63. tnama.addActionListener(new java.awt.event.ActionListener() {
  64. public void actionPerformed(java.awt.event.ActionEvent evt) {
  65. tnamaActionPerformed(evt);
  66. }
  67. });
  68.  
  69. jLabel2.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
  70. jLabel2.setForeground(new java.awt.Color(255, 255, 255));
  71. jLabel2.setText("USERNAME");
  72.  
  73. jLabel3.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
  74. jLabel3.setForeground(new java.awt.Color(255, 255, 255));
  75. jLabel3.setText("PASSWORD");
  76.  
  77. jButton1.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
  78. jButton1.setText("LOGIN");
  79. jButton1.addActionListener(new java.awt.event.ActionListener() {
  80. public void actionPerformed(java.awt.event.ActionEvent evt) {
  81. jButton1ActionPerformed(evt);
  82. }
  83. });
  84.  
  85. jButton2.setFont(new java.awt.Font("Tempus Sans ITC", 1, 14)); // NOI18N
  86. jButton2.setText("EXIT");
  87. jButton2.addActionListener(new java.awt.event.ActionListener() {
  88. public void actionPerformed(java.awt.event.ActionEvent evt) {
  89. jButton2ActionPerformed(evt);
  90. }
  91. });
  92.  
  93. jLabel1.setBackground(new java.awt.Color(255, 51, 255));
  94. jLabel1.setFont(new java.awt.Font("Tempus Sans ITC", 1, 24)); // NOI18N
  95. jLabel1.setForeground(new java.awt.Color(255, 0, 204));
  96. jLabel1.setText("SILAHKAN LOGIN");
  97.  
  98. javax.swing.GroupLayout panel2Layout = new javax.swing.GroupLayout(panel2);
  99. panel2.setLayout(panel2Layout);
  100. panel2Layout.setHorizontalGroup(
  101. panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  102. .addGroup(panel2Layout.createSequentialGroup()
  103. .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  104. .addGroup(panel2Layout.createSequentialGroup()
  105. .addGap(141, 141, 141)
  106. .addComponent(jLabel1))
  107. .addGroup(panel2Layout.createSequentialGroup()
  108. .addGap(74, 74, 74)
  109. .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  110. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel2Layout.createSequentialGroup()
  111. .addComponent(jLabel2)
  112. .addGap(38, 38, 38)
  113. .addComponent(tnama, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE))
  114. .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel2Layout.createSequentialGroup()
  115. .addComponent(jLabel3)
  116. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  117. .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  118. .addGroup(panel2Layout.createSequentialGroup()
  119. .addComponent(jButton1)
  120. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  121. .addComponent(jButton2))
  122. .addComponent(tpas, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE))))))
  123. .addContainerGap(79, Short.MAX_VALUE))
  124. );
  125. panel2Layout.setVerticalGroup(
  126. panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  127. .addGroup(panel2Layout.createSequentialGroup()
  128. .addComponent(jLabel1)
  129. .addGap(13, 13, 13)
  130. .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  131. .addComponent(jLabel2)
  132. .addComponent(tnama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  133. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  134. .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  135. .addComponent(jLabel3)
  136. .addComponent(tpas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  137. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  138. .addGroup(panel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  139. .addComponent(jButton1)
  140. .addComponent(jButton2))
  141. .addContainerGap(50, Short.MAX_VALUE))
  142. );
  143.  
  144. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  145. getContentPane().setLayout(layout);
  146. layout.setHorizontalGroup(
  147. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  148. .addComponent(panel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  149. );
  150. layout.setVerticalGroup(
  151. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  152. .addComponent(panel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  153. );
  154.  
  155. pack();
  156. }// </editor-fold>
  157.  
  158. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  159. // TODO add your handling code here:
  160.  
  161. }
  162.  
  163. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  164. // TODO add your handling code here:
  165. try {
  166. sql = "SELECT * FROM user WHERE username='"+tnama.getText()+"' AND password='"+tpas.getText()+"'";
  167. stt = (Statement) kn.logon().createStatement();
  168. rs = stt.executeQuery(sql);
  169. if (rs.next()) {
  170. if (tnama.getText().equals(rs.getString("username"))&& tpas.getText().equals("password"));{
  171. JOptionPane.showMessageDialog(null, "Berhasil Login");
  172. new hlmnawal().setVisible(true);
  173. this.dispose();
  174.  
  175. }
  176. }else{
  177.  
  178. }
  179. } catch (Exception e) {
  180. }
  181. }
  182.  
  183. private void tpasActionPerformed(java.awt.event.ActionEvent evt) {
  184. // TODO add your handling code here:
  185. }
  186.  
  187. private void tnamaActionPerformed(java.awt.event.ActionEvent evt) {
  188. // TODO add your handling code here:
  189. }
  190.  
  191. /**
  192. * @param args the command line arguments
  193. */
  194. public static void main(String args[]) {
  195. /* Set the Nimbus look and feel */
  196. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  197. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  198. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  199. */
  200. try {
  201. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  202. if ("Nimbus".equals(info.getName())) {
  203. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  204. break;
  205. }
  206. }
  207. } catch (ClassNotFoundException ex) {
  208. java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  209. } catch (InstantiationException ex) {
  210. java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  211. } catch (IllegalAccessException ex) {
  212. java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  213. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  214. java.util.logging.Logger.getLogger(login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  215. }
  216. //</editor-fold>
  217.  
  218. /* Create and display the form */
  219. java.awt.EventQueue.invokeLater(new Runnable() {
  220. public void run() {
  221. new login().setVisible(true);
  222. }
  223. });
  224. }
  225.  
  226. // Variables declaration - do not modify
  227. private javax.swing.JButton jButton1;
  228. private javax.swing.JButton jButton2;
  229. private javax.swing.JComboBox jComboBox1;
  230. private javax.swing.JLabel jLabel1;
  231. private javax.swing.JLabel jLabel2;
  232. private javax.swing.JLabel jLabel3;
  233. private java.awt.Panel panel2;
  234. private javax.swing.JTextField tnama;
  235. private javax.swing.JPasswordField tpas;
  236. // End of variables declaration
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement