program to create an admission form using Javax Swing - TopicsExpress



          

program to create an admission form using Javax Swing : @P-3# import java.sql.*; public class AccessConnection { static String uri = "jdbc:odbc:student"; private Connection getAccessConnection() { Connection con = null; try { con = DriverManager.getConnection(uri, "", ""); return con; } catch (Exception e) { e.printStackTrace(); return null; } } public int insertAdmissinData(String prn, String name, String date, double fees, String pmode, String course, String edu, String admitty) throws SQLException { Connection con = null; Statement st = null; String sql = "insert into Admission values ( + prn + , + name + , + date + ," + fees + ", + pmode + , + course + , + edu + , + admitty + )"; try { con = getAccessConnection(); st = con.createStatement(); int result = st.executeUpdate(sql); return 0; } catch (Exception e) { e.printStackTrace(); return -1; } finally { if (con != null) { con.close(); } if (st != null) { st.close(); } } } } /** --------------------------------- Here is code for jframe -------------------------------- */ import javax.swing.JOptionPane; public class AdmissionFrm extends javax.swing.JFrame { /** Creates new form AdmissionFrm */ public AdmissionFrm() { initComponents(); } @SuppressWarnings("unchecked") // private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); txtPrn = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); txtName = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); txtFees = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); dateAdmitdate = new org.gui.JCalendarCombo(); jLabel6 = new javax.swing.JLabel(); cmbPaymentMode = new javax.swing.JComboBox(); jLabel7 = new javax.swing.JLabel(); txtEducation = new javax.swing.JTextField(); jLabel8 = new javax.swing.JLabel(); txtCourse = new javax.swing.JTextField(); jLabel9 = new javax.swing.JLabel(); txtAdmissionType = new javax.swing.JTextField(); btnSave = new javax.swing.JButton(); btnClear = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setText("Student Admission Application"); jLabel2.setText(" Prn:"); jLabel3.setText("Name:"); jLabel4.setText("Fees :"); jLabel5.setText("Date :"); jLabel6.setText("Payment Mode:"); cmbPaymentMode.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Cheque", "Cash" })); jLabel7.setText("Educataion:"); jLabel8.setText("Course :"); jLabel9.setText("Admission Type:"); btnSave.setText("Save"); btnSave.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSaveActionPerformed(evt); } }); btnClear.setText("Reset"); btnClear.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnClearActionPerformed(evt); } }); 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) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel3) .addComponent(jLabel2) .addComponent(jLabel4) .addComponent(jLabel5) .addComponent(jLabel6) .addComponent(jLabel7) .addComponent(jLabel8)) .addComponent(jLabel9)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(txtAdmissionType, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE) .addComponent(txtPrn, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE) .addComponent(txtName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE) .addComponent(txtFees, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE) .addComponent(dateAdmitdate, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE) .addComponent(cmbPaymentMode, javax.swing.GroupLayout.Alignment.LEADING, 0, 179, Short.MAX_VALUE) .addComponent(txtEducation, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE) .addComponent(txtCourse, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(btnSave) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnClear) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))) .addGap(89, 89, 89)) .addGroup(layout.createSequentialGroup() .addGap(21, 21, 21) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(66, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(txtPrn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(txtFees, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel5) .addComponent(dateAdmitdate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6) .addComponent(cmbPaymentMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel7) .addComponent(txtEducation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel8) .addComponent(txtCourse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel9) .addComponent(txtAdmissionType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnClear) .addComponent(btnSave)) .addGap(20, 20, 20)) ); pack(); }// private void clear(){ txtAdmissionType.setText(""); txtCourse.setText(""); txtEducation.setText(""); txtFees.setText(""); txtName.setText(""); txtPrn.setText(""); } private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) { try { String prn = txtPrn.getText(); String name = txtName.getText(); String date = dateAdmitdate.getSelectedDate(); double fees = Double.parseDouble(txtFees.getText()); String pmode = cmbPaymentMode.getSelectedItem().toString(); String course = txtCourse.getText(); String edu = txtEducation.getText(); String admitty = txtAdmissionType.getText(); AccessConnection ac=new AccessConnection(); int result =ac.insertAdmissinData(prn, name, date, fees, pmode, course, edu, admitty); clear(); if(result==0){ JOptionPane.showMessageDialog(null, "Succesfully Saved.","Information",JOptionPane.INFORMATION_MESSAGE); }else{ JOptionPane.showMessageDialog(null, "Errors Occured.","Error",JOptionPane.ERROR_MESSAGE); } } catch (Exception e) { e.printStackTrace(); } } private void btnClearActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: clear(); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new AdmissionFrm().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton btnClear; private javax.swing.JButton btnSave; private javax.swing.JComboBox cmbPaymentMode; private org.gui.JCalendarCombo dateAdmitdate; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JTextField txtAdmissionType; private javax.swing.JTextField txtCourse; private javax.swing.JTextField txtEducation; private javax.swing.JTextField txtFees; private javax.swing.JTextField txtName; private javax.swing.JTextField txtPrn; // End of variables declaration }
Posted on: Sat, 06 Jul 2013 06:46:05 +0000

Trending Topics



Recently Viewed Topics




© 2015