Guest User

Untitled

a guest
Oct 24th, 2017
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.72 KB | None | 0 0
  1.  
  2. import java.sql.Connection;
  3.  
  4.  
  5. public class frmRegister extends javax.swing.JFrame {
  6.  
  7. /**
  8. * Creates new form frmRegister
  9. */
  10. public frmRegister() {
  11. initComponents();
  12. }
  13.  
  14. /**
  15. * This method is called from within the constructor to initialize the form.
  16. * WARNING: Do NOT modify this code. The content of this method is always
  17. * regenerated by the Form Editor.
  18. */
  19. @SuppressWarnings("unchecked")
  20. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  21. private void initComponents() {
  22.  
  23. jLabel1 = new javax.swing.JLabel();
  24. jLabel2 = new javax.swing.JLabel();
  25. txtName = new javax.swing.JTextField();
  26. txtTele = new javax.swing.JTextField();
  27. btnSave = new javax.swing.JButton();
  28. btnQuery = new javax.swing.JButton();
  29.  
  30. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  31. addWindowListener(new java.awt.event.WindowAdapter() {
  32. public void windowOpened(java.awt.event.WindowEvent evt) {
  33. formWindowOpened(evt);
  34. }
  35. });
  36.  
  37. jLabel1.setText("Name");
  38.  
  39. jLabel2.setText("Telephone");
  40.  
  41. txtName.addActionListener(new java.awt.event.ActionListener() {
  42. public void actionPerformed(java.awt.event.ActionEvent evt) {
  43. txtNameActionPerformed(evt);
  44. }
  45. });
  46.  
  47. btnSave.setText("Save");
  48. btnSave.addActionListener(new java.awt.event.ActionListener() {
  49. public void actionPerformed(java.awt.event.ActionEvent evt) {
  50. btnSaveActionPerformed(evt);
  51. }
  52. });
  53.  
  54. btnQuery.setText("Go to Test ADMIN");
  55. btnQuery.addActionListener(new java.awt.event.ActionListener() {
  56. public void actionPerformed(java.awt.event.ActionEvent evt) {
  57. btnQueryActionPerformed(evt);
  58. }
  59. });
  60.  
  61. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  62. getContentPane().setLayout(layout);
  63. layout.setHorizontalGroup(
  64. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  65. .addGroup(layout.createSequentialGroup()
  66. .addGap(54, 54, 54)
  67. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  68. .addGroup(layout.createSequentialGroup()
  69. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  70. .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 77, Short.MAX_VALUE)
  71. .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  72. .addGap(18, 18, 18)
  73. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  74. .addComponent(txtName, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
  75. .addComponent(txtTele)))
  76. .addGroup(layout.createSequentialGroup()
  77. .addComponent(btnSave, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
  78. .addGap(31, 31, 31)
  79. .addComponent(btnQuery, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)))
  80. .addContainerGap(54, Short.MAX_VALUE))
  81. );
  82. layout.setVerticalGroup(
  83. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  84. .addGroup(layout.createSequentialGroup()
  85. .addGap(42, 42, 42)
  86. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  87. .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
  88. .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  89. .addGap(44, 44, 44)
  90. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  91. .addComponent(txtTele)
  92. .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  93. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
  94. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  95. .addComponent(btnQuery, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
  96. .addComponent(btnSave, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
  97. .addGap(35, 35, 35))
  98. );
  99.  
  100. pack();
  101. }// </editor-fold>
  102.  
  103. private void txtNameActionPerformed(java.awt.event.ActionEvent evt) {
  104. // TODO add your handling code here:
  105. }
  106.  
  107. private void formWindowOpened(java.awt.event.WindowEvent evt) {
  108. this.setTitle("Register Contact");
  109. }
  110.  
  111. private void btnQueryActionPerformed(java.awt.event.ActionEvent evt) {
  112. this.setVisible(false);
  113.  
  114. frmStart form = new frmStart();
  115.  
  116. form.setVisible(true);
  117.  
  118. }
  119.  
  120. private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {
  121. if( !"".equals(txtTele.getText()) && !"".equals(txtName.getText()) ) {
  122. String tel = txtTele.getText();
  123. String name = txtName.getText();
  124. conn cn = new conn();
  125. String url = "jdbc:firebirdsql://localhost:3050/C:\\PHONEBOOKFINAL.FDB";
  126. String driver = "org.firebirdsql.jdbc.FBDriver";
  127. String user = "SYSDBA";
  128. String password = "masterkey";
  129.  
  130. cn.connect(url,driver,user,password);
  131. cn.executeUpdate("INSERT INTO contact" + "(name,tel) VALUES ('" + name + "','" + tel + "')");
  132. cn.disconnect();
  133. txtName.setText("");
  134. txtTele.setText("");
  135. txtName.setFocusable(true);
  136.  
  137. }
  138. }
  139.  
  140. /**
  141. * @param args the command line arguments
  142. */
  143. public static void main(String args[]) {
  144. /* Set the Nimbus look and feel */
  145. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  146. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  147. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  148. */
  149. try {
  150. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  151. if ("Nimbus".equals(info.getName())) {
  152. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  153. break;
  154. }
  155. }
  156. } catch (ClassNotFoundException ex) {
  157. java.util.logging.Logger.getLogger(frmRegister.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  158. } catch (InstantiationException ex) {
  159. java.util.logging.Logger.getLogger(frmRegister.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  160. } catch (IllegalAccessException ex) {
  161. java.util.logging.Logger.getLogger(frmRegister.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  162. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  163. java.util.logging.Logger.getLogger(frmRegister.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  164. }
  165. //</editor-fold>
  166.  
  167. /* Create and display the form */
  168. java.awt.EventQueue.invokeLater(new Runnable() {
  169. public void run() {
  170. new frmRegister().setVisible(true);
  171. }
  172. });
  173. }
  174.  
  175. // Variables declaration - do not modify
  176. private javax.swing.JButton btnQuery;
  177. private javax.swing.JButton btnSave;
  178. private javax.swing.JLabel jLabel1;
  179. private javax.swing.JLabel jLabel2;
  180. private javax.swing.JTextField txtName;
  181. private javax.swing.JTextField txtTele;
  182. // End of variables declaration
  183. }
Add Comment
Please, Sign In to add comment