Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.74 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 student.registry;
  7.  
  8. import java.awt.Image;
  9. import java.awt.Toolkit;
  10. import java.sql.*;
  11. import java.util.logging.Level;
  12. import java.util.logging.Logger;
  13. import javax.swing.*;
  14. import net.proteanit.sql.DbUtils;
  15.  
  16. public class StudentRegistry extends javax.swing.JFrame {
  17.  
  18. Connection con;
  19. PreparedStatement pst;
  20. ResultSet rs;
  21.  
  22.  
  23. public StudentRegistry() {
  24. initComponents();
  25. this.setResizable(false);
  26. this.setSize(931, 569);
  27. this.setLocation(400, 100);
  28.  
  29.  
  30.  
  31. try {
  32. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sample","root","");
  33. String sql = "SELECT * FROM studentinfo";
  34. pst = con.prepareStatement(sql);
  35. rs = pst.executeQuery();
  36. tableData.setModel(DbUtils.resultSetToTableModel(rs));
  37. } catch (SQLException ex) {
  38. Logger.getLogger(StudentRegistry.class.getName()).log(Level.SEVERE, null, ex);
  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. jLabel1 = new javax.swing.JLabel();
  52. jLabel2 = new javax.swing.JLabel();
  53. jLabel3 = new javax.swing.JLabel();
  54. jLabel4 = new javax.swing.JLabel();
  55. jLabel5 = new javax.swing.JLabel();
  56. jLabel6 = new javax.swing.JLabel();
  57. jTextField1 = new javax.swing.JTextField();
  58. txtFName = new javax.swing.JTextField();
  59. txtLName = new javax.swing.JTextField();
  60. txtGLevel = new javax.swing.JTextField();
  61. txtSection = new javax.swing.JTextField();
  62. txtCNumber = new javax.swing.JTextField();
  63. btnCreate = new javax.swing.JButton();
  64. btnUpdate = new javax.swing.JButton();
  65. btnDelete = new javax.swing.JButton();
  66. jScrollPane1 = new javax.swing.JScrollPane();
  67. tableData = new javax.swing.JTable();
  68. jLabel7 = new javax.swing.JLabel();
  69. jLabel8 = new javax.swing.JLabel();
  70.  
  71. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  72. setMaximumSize(new java.awt.Dimension(931, 569));
  73. setMinimumSize(new java.awt.Dimension(931, 569));
  74. getContentPane().setLayout(null);
  75.  
  76. jLabel1.setBackground(new java.awt.Color(255, 0, 102));
  77. jLabel1.setFont(new java.awt.Font("Lucida Sans Typewriter", 3, 18)); // NOI18N
  78. jLabel1.setForeground(new java.awt.Color(255, 255, 255));
  79. jLabel1.setText("ID");
  80. getContentPane().add(jLabel1);
  81. jLabel1.setBounds(39, 59, 150, 50);
  82.  
  83. jLabel2.setBackground(new java.awt.Color(255, 0, 102));
  84. jLabel2.setFont(new java.awt.Font("Lucida Sans Typewriter", 3, 18)); // NOI18N
  85. jLabel2.setForeground(new java.awt.Color(255, 255, 255));
  86. jLabel2.setText("FIRST NAME");
  87. getContentPane().add(jLabel2);
  88. jLabel2.setBounds(39, 88, 150, 50);
  89.  
  90. jLabel3.setBackground(new java.awt.Color(255, 0, 102));
  91. jLabel3.setFont(new java.awt.Font("Lucida Sans Typewriter", 3, 18)); // NOI18N
  92. jLabel3.setForeground(new java.awt.Color(255, 255, 255));
  93. jLabel3.setText("LAST NAME");
  94. getContentPane().add(jLabel3);
  95. jLabel3.setBounds(39, 117, 150, 50);
  96.  
  97. jLabel4.setBackground(new java.awt.Color(255, 0, 102));
  98. jLabel4.setFont(new java.awt.Font("Lucida Sans Typewriter", 3, 18)); // NOI18N
  99. jLabel4.setForeground(new java.awt.Color(255, 255, 255));
  100. jLabel4.setText("GRADE LEVEL");
  101. getContentPane().add(jLabel4);
  102. jLabel4.setBounds(39, 146, 150, 50);
  103.  
  104. jLabel5.setBackground(new java.awt.Color(255, 0, 102));
  105. jLabel5.setFont(new java.awt.Font("Lucida Sans Typewriter", 3, 18)); // NOI18N
  106. jLabel5.setForeground(new java.awt.Color(255, 255, 255));
  107. jLabel5.setText("SECTION");
  108. getContentPane().add(jLabel5);
  109. jLabel5.setBounds(39, 175, 150, 50);
  110.  
  111. jLabel6.setBackground(new java.awt.Color(255, 0, 102));
  112. jLabel6.setFont(new java.awt.Font("Lucida Sans Typewriter", 3, 18)); // NOI18N
  113. jLabel6.setForeground(new java.awt.Color(255, 255, 255));
  114. jLabel6.setText("CLASS NUMBER");
  115. getContentPane().add(jLabel6);
  116. jLabel6.setBounds(39, 204, 150, 50);
  117.  
  118. jTextField1.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 18)); // NOI18N
  119. jTextField1.addActionListener(new java.awt.event.ActionListener() {
  120. public void actionPerformed(java.awt.event.ActionEvent evt) {
  121. jTextField1ActionPerformed(evt);
  122. }
  123. });
  124. getContentPane().add(jTextField1);
  125. jTextField1.setBounds(180, 70, 180, 30);
  126.  
  127. txtFName.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 18)); // NOI18N
  128. txtFName.addActionListener(new java.awt.event.ActionListener() {
  129. public void actionPerformed(java.awt.event.ActionEvent evt) {
  130. txtFNameActionPerformed(evt);
  131. }
  132. });
  133. getContentPane().add(txtFName);
  134. txtFName.setBounds(180, 90, 180, 30);
  135.  
  136. txtLName.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 18)); // NOI18N
  137. txtLName.addActionListener(new java.awt.event.ActionListener() {
  138. public void actionPerformed(java.awt.event.ActionEvent evt) {
  139. txtLNameActionPerformed(evt);
  140. }
  141. });
  142. getContentPane().add(txtLName);
  143. txtLName.setBounds(180, 120, 180, 30);
  144.  
  145. txtGLevel.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 18)); // NOI18N
  146. txtGLevel.addActionListener(new java.awt.event.ActionListener() {
  147. public void actionPerformed(java.awt.event.ActionEvent evt) {
  148. txtGLevelActionPerformed(evt);
  149. }
  150. });
  151. getContentPane().add(txtGLevel);
  152. txtGLevel.setBounds(180, 150, 180, 30);
  153.  
  154. txtSection.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 18)); // NOI18N
  155. txtSection.addActionListener(new java.awt.event.ActionListener() {
  156. public void actionPerformed(java.awt.event.ActionEvent evt) {
  157. txtSectionActionPerformed(evt);
  158. }
  159. });
  160. getContentPane().add(txtSection);
  161. txtSection.setBounds(180, 180, 180, 30);
  162.  
  163. txtCNumber.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 18)); // NOI18N
  164. txtCNumber.addActionListener(new java.awt.event.ActionListener() {
  165. public void actionPerformed(java.awt.event.ActionEvent evt) {
  166. txtCNumberActionPerformed(evt);
  167. }
  168. });
  169. getContentPane().add(txtCNumber);
  170. txtCNumber.setBounds(180, 220, 180, 30);
  171.  
  172. btnCreate.setText("CREATE");
  173. btnCreate.addActionListener(new java.awt.event.ActionListener() {
  174. public void actionPerformed(java.awt.event.ActionEvent evt) {
  175. btnCreateActionPerformed(evt);
  176. }
  177. });
  178. getContentPane().add(btnCreate);
  179. btnCreate.setBounds(79, 312, 71, 23);
  180.  
  181. btnUpdate.setText("UPDATE");
  182. getContentPane().add(btnUpdate);
  183. btnUpdate.setBounds(193, 312, 71, 23);
  184.  
  185. btnDelete.setText("DELETE");
  186. getContentPane().add(btnDelete);
  187. btnDelete.setBounds(297, 312, 69, 23);
  188.  
  189. tableData.setModel(new javax.swing.table.DefaultTableModel(
  190. new Object [][] {
  191. {null, null, null, null},
  192. {null, null, null, null},
  193. {null, null, null, null},
  194. {null, null, null, null}
  195. },
  196. new String [] {
  197. "Title 1", "Title 2", "Title 3", "Title 4"
  198. }
  199. ));
  200. jScrollPane1.setViewportView(tableData);
  201.  
  202. getContentPane().add(jScrollPane1);
  203. jScrollPane1.setBounds(440, 50, 452, 402);
  204. getContentPane().add(jLabel7);
  205. jLabel7.setBounds(193, 433, 0, 0);
  206.  
  207. jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/student/registry/tite.jpeg"))); // NOI18N
  208. jLabel8.setMaximumSize(new java.awt.Dimension(931, 569));
  209. jLabel8.setMinimumSize(new java.awt.Dimension(931, 569));
  210. jLabel8.setPreferredSize(new java.awt.Dimension(931, 569));
  211. getContentPane().add(jLabel8);
  212. jLabel8.setBounds(0, 0, 930, 570);
  213.  
  214. pack();
  215. }// </editor-fold>
  216.  
  217. private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
  218. // TODO add your handling code here:
  219. }
  220.  
  221. private void txtFNameActionPerformed(java.awt.event.ActionEvent evt) {
  222. // TODO add your handling code here:
  223. }
  224.  
  225. private void txtLNameActionPerformed(java.awt.event.ActionEvent evt) {
  226. // TODO add your handling code here:
  227. }
  228.  
  229. private void txtGLevelActionPerformed(java.awt.event.ActionEvent evt) {
  230. // TODO add your handling code here:
  231. }
  232.  
  233. private void txtSectionActionPerformed(java.awt.event.ActionEvent evt) {
  234. // TODO add your handling code here:
  235. }
  236.  
  237. private void txtCNumberActionPerformed(java.awt.event.ActionEvent evt) {
  238. // TODO add your handling code here:
  239. }
  240.  
  241. private void btnCreateActionPerformed(java.awt.event.ActionEvent evt) {
  242. try {
  243. String sql = "INSERT INTO studentinfo" + "(FIRSTNAME, LASTNAME, GRADELEVEL, SECTION, CN)" + "VALUES (?,?,?,?,?)";
  244. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sample","root","");
  245. pst = con.prepareStatement(sql);
  246. pst.setString(1 , txtFName.getText());
  247. pst.setString(2 , txtLName.getText());
  248. pst.setString(3 , txtGLevel.getText());
  249. pst.setString(4 , txtSection.getText());
  250. pst.setString(5 , txtCNumber.getText());
  251. pst.executeUpdate();
  252. JOptionPane.showMessageDialog(this, "Added Successfully");
  253. } catch (SQLException ex) {
  254. Logger.getLogger(StudentRegistry.class.getName()).log(Level.SEVERE, null, ex);
  255. }
  256. }
  257.  
  258. /**
  259. * @param args the command line arguments
  260. */
  261. public static void main(String args[]) {
  262. /* Set the Nimbus look and feel */
  263. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  264. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  265. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  266. */
  267. try {
  268. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  269. if ("Nimbus".equals(info.getName())) {
  270. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  271. break;
  272. }
  273. }
  274. } catch (ClassNotFoundException ex) {
  275. java.util.logging.Logger.getLogger(StudentRegistry.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  276. } catch (InstantiationException ex) {
  277. java.util.logging.Logger.getLogger(StudentRegistry.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  278. } catch (IllegalAccessException ex) {
  279. java.util.logging.Logger.getLogger(StudentRegistry.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  280. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  281. java.util.logging.Logger.getLogger(StudentRegistry.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  282. }
  283. //</editor-fold>
  284.  
  285. /* Create and display the form */
  286. java.awt.EventQueue.invokeLater(new Runnable() {
  287. public void run() {
  288. new StudentRegistry().setVisible(true);
  289. }
  290. });
  291. }
  292.  
  293. // Variables declaration - do not modify
  294. private javax.swing.JButton btnCreate;
  295. private javax.swing.JButton btnDelete;
  296. private javax.swing.JButton btnUpdate;
  297. private javax.swing.JLabel jLabel1;
  298. private javax.swing.JLabel jLabel2;
  299. private javax.swing.JLabel jLabel3;
  300. private javax.swing.JLabel jLabel4;
  301. private javax.swing.JLabel jLabel5;
  302. private javax.swing.JLabel jLabel6;
  303. private javax.swing.JLabel jLabel7;
  304. private javax.swing.JLabel jLabel8;
  305. private javax.swing.JScrollPane jScrollPane1;
  306. private javax.swing.JTextField jTextField1;
  307. private javax.swing.JTable tableData;
  308. private javax.swing.JTextField txtCNumber;
  309. private javax.swing.JTextField txtFName;
  310. private javax.swing.JTextField txtGLevel;
  311. private javax.swing.JTextField txtLName;
  312. private javax.swing.JTextField txtSection;
  313. // End of variables declaration
  314. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement