Advertisement
Guest User

Untitled

a guest
Apr 7th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.84 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 components;
  7.  
  8. import java.awt.event.*;
  9.  
  10. /**
  11. *
  12. * @author Ethan
  13. */
  14. public class AccountManager extends javax.swing.JFrame {
  15.  
  16. /**
  17. * Creates new form AccountManager
  18. */
  19. public AccountManager() {
  20. initComponents();
  21. }
  22.  
  23. /**
  24. * This method is called from within the constructor to initialize the form.
  25. * WARNING: Do NOT modify this code. The content of this method is always
  26. * regenerated by the Form Editor.
  27. */
  28. @SuppressWarnings("unchecked")
  29. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  30. private void initComponents() {
  31.  
  32. jScrollPane1 = new javax.swing.JScrollPane();
  33. jTable1 = new javax.swing.JTable();
  34. jButton1 = new javax.swing.JButton();
  35. jButton2 = new javax.swing.JButton();
  36.  
  37. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  38. setTitle("Account Manager");
  39.  
  40. jTable1.setModel(new javax.swing.table.DefaultTableModel(
  41. new Object [][] {
  42. {"Admin", "Admin", new Integer(1), new Boolean(true)},
  43. {"Username", "Password", new Integer(1), new Boolean(true)}
  44. },
  45. new String [] {
  46. "Username", "Password", "Account Type", "Active"
  47. }
  48. ) {
  49. Class[] types = new Class [] {
  50. java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Boolean.class
  51. };
  52.  
  53. public Class getColumnClass(int columnIndex) {
  54. return types [columnIndex];
  55. }
  56. });
  57. jTable1.getTableHeader().setReorderingAllowed(false);
  58. jScrollPane1.setViewportView(jTable1);
  59.  
  60. jButton1.setText("Add Account");
  61.  
  62. class addAccount implements ActionListener{
  63.  
  64. public void actionPerformed(ActionEvent e){
  65. //Action listener for button 1 that adds the row
  66. }
  67. }
  68. jButton1.addActionListener(new addAccount());
  69.  
  70. jButton2.setText("Delete Account");
  71.  
  72. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  73. getContentPane().setLayout(layout);
  74. layout.setHorizontalGroup(
  75. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  76. .addGroup(layout.createSequentialGroup()
  77. .addContainerGap()
  78. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  79. .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 580, Short.MAX_VALUE)
  80. .addGroup(layout.createSequentialGroup()
  81. .addComponent(jButton1)
  82. .addGap(18, 18, 18)
  83. .addComponent(jButton2)
  84. .addGap(0, 0, Short.MAX_VALUE)))
  85. .addContainerGap())
  86. );
  87. layout.setVerticalGroup(
  88. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  89. .addGroup(layout.createSequentialGroup()
  90. .addContainerGap()
  91. .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
  92. .addGap(18, 18, 18)
  93. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  94. .addComponent(jButton1)
  95. .addComponent(jButton2))
  96. .addContainerGap(78, Short.MAX_VALUE))
  97. );
  98.  
  99. pack();
  100. }// </editor-fold>
  101.  
  102. /**
  103. * @param args the command line arguments
  104. */
  105. public static void main(String args[]) {
  106. /* Set the Nimbus look and feel */
  107. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  108. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  109. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  110. */
  111. try {
  112. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  113. if ("Steel".equals(info.getName())) {
  114. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  115. break;
  116. }
  117. }
  118. } catch (ClassNotFoundException ex) {
  119. java.util.logging.Logger.getLogger(AccountManager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  120. } catch (InstantiationException ex) {
  121. java.util.logging.Logger.getLogger(AccountManager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  122. } catch (IllegalAccessException ex) {
  123. java.util.logging.Logger.getLogger(AccountManager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  124. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  125. java.util.logging.Logger.getLogger(AccountManager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  126. }
  127. //</editor-fold>
  128.  
  129. /* Create and display the form */
  130. java.awt.EventQueue.invokeLater(new Runnable() {
  131. public void run() {
  132. new AccountManager().setVisible(true);
  133. }
  134. });
  135. }
  136.  
  137. // Variables declaration - do not modify
  138. private javax.swing.JButton jButton1;
  139. private javax.swing.JButton jButton2;
  140. private javax.swing.JScrollPane jScrollPane1;
  141. private javax.swing.JTable jTable1;
  142. // End of variables declaration
  143. }
  144.  
  145. //used to add the entry to database table
  146. String query = "insert into tableName (col1, col2, col3,col4) values ('data','data','data','data')";
  147. Class.forName("com.mysql.jdbc.Driver");
  148. //connection
  149. Connection conn = (Connection)
  150. //root and username and password for access to the database
  151. DriverManager.getConnection("jdbc:mysql://localhost:3306/NameOfDatabase","root","password");
  152. //create the statement that will be used
  153. Statement stmt=conn.createStatement();
  154. //executes the query statement
  155. stmt.executeUpdate(query);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement