Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package components;
- import java.awt.event.*;
- /**
- *
- * @author Ethan
- */
- public class AccountManager extends javax.swing.JFrame {
- /**
- * Creates new form AccountManager
- */
- public AccountManager() {
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jScrollPane1 = new javax.swing.JScrollPane();
- jTable1 = new javax.swing.JTable();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setTitle("Account Manager");
- jTable1.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- {"Admin", "Admin", new Integer(1), new Boolean(true)},
- {"Username", "Password", new Integer(1), new Boolean(true)}
- },
- new String [] {
- "Username", "Password", "Account Type", "Active"
- }
- ) {
- Class[] types = new Class [] {
- java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Boolean.class
- };
- public Class getColumnClass(int columnIndex) {
- return types [columnIndex];
- }
- });
- jTable1.getTableHeader().setReorderingAllowed(false);
- jScrollPane1.setViewportView(jTable1);
- jButton1.setText("Add Account");
- class addAccount implements ActionListener{
- public void actionPerformed(ActionEvent e){
- //Action listener for button 1 that adds the row
- }
- }
- jButton1.addActionListener(new addAccount());
- jButton2.setText("Delete Account");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 580, Short.MAX_VALUE)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jButton1)
- .addGap(18, 18, 18)
- .addComponent(jButton2)
- .addGap(0, 0, Short.MAX_VALUE)))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton2))
- .addContainerGap(78, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Steel".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(AccountManager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(AccountManager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(AccountManager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(AccountManager.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new AccountManager().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTable jTable1;
- // End of variables declaration
- }
- //used to add the entry to database table
- String query = "insert into tableName (col1, col2, col3,col4) values ('data','data','data','data')";
- Class.forName("com.mysql.jdbc.Driver");
- //connection
- Connection conn = (Connection)
- //root and username and password for access to the database
- DriverManager.getConnection("jdbc:mysql://localhost:3306/NameOfDatabase","root","password");
- //create the statement that will be used
- Statement stmt=conn.createStatement();
- //executes the query statement
- stmt.executeUpdate(query);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement