Skip to content

Commit

Permalink
Create acc.java
Browse files Browse the repository at this point in the history
  • Loading branch information
alamsyah54 authored Oct 5, 2021
1 parent 04de25c commit 72dc6e4
Showing 1 changed file with 298 additions and 0 deletions.
298 changes: 298 additions & 0 deletions acc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
/*
* 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 banking;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.*;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
/**
*
* @author Mohit_Pc
*/
public class Account extends javax.swing.JFrame {

/**
* Creates new form Account
*/
public Account() {
initComponents();
txtf_id.requestFocus();
}

/**
* 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">//GEN-BEGIN:initComponents
private void initComponents() {

jPanel1 = new javax.swing.JPanel();
lbl_name = new javax.swing.JLabel();
txtf_id = new javax.swing.JTextField();
lbl_age = new javax.swing.JLabel();
txtf_name = new javax.swing.JTextField();
lbl_sal = new javax.swing.JLabel();
txtf_depos = new javax.swing.JTextField();
btn_insertrec = new javax.swing.JButton();
btn_exit = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
textf_ex = new javax.swing.JTextArea();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel1.setBackground(new java.awt.Color(204, 255, 204));
jPanel1.setLayout(null);

lbl_name.setText("Enter 4 Digit Customer Id-->");
jPanel1.add(lbl_name);
lbl_name.setBounds(31, 28, 150, 28);

txtf_id.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtf_idActionPerformed(evt);
}
});
jPanel1.add(txtf_id);
txtf_id.setBounds(240, 30, 130, 20);

lbl_age.setText("Enter Customer's Name-->");
jPanel1.add(lbl_age);
lbl_age.setBounds(30, 94, 160, 20);

txtf_name.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtf_nameActionPerformed(evt);
}
});
jPanel1.add(txtf_name);
txtf_name.setBounds(240, 90, 140, 20);

lbl_sal.setText("Enter Initial Deposit Amount(Not < Rs.1000)->");
jPanel1.add(lbl_sal);
lbl_sal.setBounds(10, 150, 230, 20);

txtf_depos.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtf_deposActionPerformed(evt);
}
});
jPanel1.add(txtf_depos);
txtf_depos.setBounds(240, 150, 140, 20);

btn_insertrec.setText("INSERT RECORD");
btn_insertrec.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_insertrecActionPerformed(evt);
}
});
jPanel1.add(btn_insertrec);
btn_insertrec.setBounds(210, 230, 170, 30);

btn_exit.setText("EXIT");
btn_exit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_exitActionPerformed(evt);
}
});
jPanel1.add(btn_exit);
btn_exit.setBounds(210, 270, 170, 23);

textf_ex.setBackground(new java.awt.Color(204, 255, 255));
textf_ex.setColumns(20);
textf_ex.setRows(5);
jScrollPane2.setViewportView(textf_ex);

jPanel1.add(jScrollPane2);
jScrollPane2.setBounds(0, 340, 790, 210);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 922, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 554, Short.MAX_VALUE)
);

pack();
}// </editor-fold>//GEN-END:initComponents

private void txtf_idActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtf_idActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtf_idActionPerformed

private void txtf_nameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtf_nameActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtf_nameActionPerformed

private void txtf_deposActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtf_deposActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtf_deposActionPerformed

private void btn_insertrecActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_insertrecActionPerformed
// TODO add your handling code here:
Connection con=null;
PreparedStatement ps=null;
ArrayList l=new ArrayList();
if(evt.getSource()==btn_insertrec)
{
try
{
int cust_id=-1,cust_deposit=-1;
String cust_name=null;
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@Mohit:1521:xe","scott","tiger");
if(txtf_id.getText().trim().isEmpty() || txtf_id.getText()=="")
l.add("Customer id cannot be empty");
else
{
cust_id=Integer.parseInt(txtf_id.getText());
}
if(txtf_name.getText().trim().isEmpty())
l.add("Customer name cannot be empty");
else{
cust_name=txtf_name.getText();
}
if(txtf_depos.getText().trim().isEmpty())
l.add("Deposit Amount cannot be empty");
else{
cust_deposit=Integer.parseInt(txtf_depos.getText());
}
Iterator itr=l.iterator();
while(itr.hasNext())
{
textf_ex.append(itr.next().toString());
textf_ex.append("\n");
}

if(con!=null)
{
ps=con.prepareStatement("insert into customer values(?,?,?)");
}
if(ps!=null)
{
ps.setInt(1,cust_id);
ps.setString(2,cust_name);
ps.setFloat(3,cust_deposit);
int result=ps.executeUpdate();
if(result==0){
textf_ex.append("Record not inserted...");
textf_ex.append("\n");}
else{
textf_ex.append("Record inserted...");
textf_ex.append("\n");
}
}

}catch(ClassNotFoundException cnf)
{
textf_ex.append(cnf.toString());
textf_ex.append("\n");
}catch(SQLException sq)
{
textf_ex.append(sq.toString());
textf_ex.append("\n");
}catch(Exception ex)
{
textf_ex.append(ex.toString());
textf_ex.append("\n");
}finally
{
try
{
if(ps!=null)
ps.close();

}catch(SQLException sqe)
{
textf_ex.append(sqe.toString());
}
try
{
if(con!=null)
con.close();

}catch(SQLException sqe)
{
textf_ex.append(sqe.toString());
}

}

}
txtf_id.setText("");
txtf_name.setText("");
txtf_depos.setText("");
}//GEN-LAST:event_btn_insertrecActionPerformed

private void btn_exitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_exitActionPerformed
// TODO add your handling code here:
if(evt.getSource()==btn_exit)
{
setVisible(false);
new Menu().setVisible(true);
}
}//GEN-LAST:event_btn_exitActionPerformed

/**
* @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 ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Account.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Account.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Account.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Account.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 Account().setVisible(true);
}
});
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btn_exit;
private javax.swing.JButton btn_insertrec;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JLabel lbl_age;
private javax.swing.JLabel lbl_name;
private javax.swing.JLabel lbl_sal;
private javax.swing.JTextArea textf_ex;
private javax.swing.JTextField txtf_depos;
private javax.swing.JTextField txtf_id;
private javax.swing.JTextField txtf_name;
// End of variables declaration//GEN-END:variables

}

0 comments on commit 72dc6e4

Please sign in to comment.