Advertisement
Guest User

Untitled

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