Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. package Ventanas;
  2.  
  3. private JPanel contentPane;
  4. private BaseDatos Palomos=null;
  5. private JTextField txtCed;
  6. private JTextField txtNom;
  7. private JTextField txtApe;
  8.  
  9. private JTextField txtSueldo;
  10. private JTextField txtTel;
  11. private BaseDatos coco;
  12.  
  13. /**
  14. * Launch the application.
  15. */
  16.  
  17. public static void main(String[] args) {
  18. EventQueue.invokeLater(new Runnable() {
  19. public void run() {
  20. try {
  21. ingresoMozo frame = new ingresoMozo();
  22. frame.setVisible(true);
  23. } catch (Exception e) {
  24. e.printStackTrace();
  25. }
  26. }
  27. });
  28. }
  29.  
  30. /**
  31. * Create the frame.
  32. */
  33. public ingresoMozo() {
  34. setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
  35. setBounds(100, 100, 650, 650);
  36. contentPane = new JPanel();
  37. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  38. setContentPane(contentPane);
  39. contentPane.setLayout(null);
  40.  
  41. JLabel lblCedula = new JLabel("Cu00E9dula");
  42. lblCedula.setBounds(23, 99, 46, 14);
  43. contentPane.add(lblCedula);
  44.  
  45. JLabel lblNombre = new JLabel("Nombre");
  46. lblNombre.setBounds(23, 124, 46, 14);
  47. contentPane.add(lblNombre);
  48.  
  49. JLabel lblApellido = new JLabel("Apellido");
  50. lblApellido.setBounds(23, 150, 46, 14);
  51. contentPane.add(lblApellido);
  52.  
  53. JLabel lblTelfono = new JLabel("Telu00E9fono");
  54. lblTelfono.setBounds(23, 176, 46, 14);
  55. contentPane.add(lblTelfono);
  56.  
  57. JLabel lblMozoAadidoCorrectamenteerror = new JLabel("Mozo au00F1adido correctamente/error");
  58. lblMozoAadidoCorrectamenteerror.setFont(new Font("Tahoma", Font.PLAIN, 14));
  59. lblMozoAadidoCorrectamenteerror.setBounds(23, 239, 219, 20);
  60. contentPane.add(lblMozoAadidoCorrectamenteerror);
  61.  
  62. JLabel lblIngresarMozo = new JLabel("Datos de mozo");
  63. lblIngresarMozo.setFont(new Font("Tahoma", Font.BOLD, 14));
  64. lblIngresarMozo.setBounds(49, 52, 112, 20);
  65. contentPane.add(lblIngresarMozo);
  66.  
  67. JLabel lblIngresoDeMozo = new JLabel("Ingreso de mozo");
  68. lblIngresoDeMozo.setFont(new Font("Tahoma", Font.BOLD, 16));
  69. lblIngresoDeMozo.setBounds(260, 11, 160, 28);
  70. contentPane.add(lblIngresoDeMozo);
  71.  
  72. txtCed = new JTextField();
  73. txtCed.setBounds(78, 100, 129, 20);
  74. contentPane.add(txtCed);
  75. txtCed.setColumns(10);
  76.  
  77. txtNom = new JTextField();
  78. txtNom.setBounds(78, 125, 129, 20);
  79. contentPane.add(txtNom);
  80. txtNom.setColumns(10);
  81.  
  82. txtApe = new JTextField();
  83. txtApe.setBounds(78, 150, 129, 20);
  84. contentPane.add(txtApe);
  85. txtApe.setColumns(10);
  86.  
  87. String cedula, telefono;
  88. String nombre, apellido;
  89. nombre=txtNom.getText().toString();
  90. apellido=txtApe.getText().toString();
  91. cedula=txtCed.getText().toString();
  92. Integer ced=Integer.parseInt(cedula);
  93. telefono=txtTel.getText().toString();
  94. Integer tel=Integer.parseInt(telefono);
  95.  
  96. String consulta1 = "INSERT INTO `personas`(`nombre`, `apellido`, `telefono`, `ci`) VALUES ('" + nombre + "', '" + apellido + "' ,'" + tel + "', '" + ced + "');";
  97.  
  98.  
  99. JButton btnAceptar = new JButton("Aceptar");
  100. btnAceptar.addMouseListener(new MouseAdapter() {
  101. @Override
  102. public void mouseClicked(MouseEvent e) {
  103.  
  104.  
  105.  
  106. coco.ejecutar(consulta1);
  107.  
  108.  
  109.  
  110.  
  111. }});
  112.  
  113.  
  114. btnAceptar.setBounds(104, 285, 89, 23);
  115. contentPane.add(btnAceptar);
  116.  
  117. JButton btnLimpiarDatos = new JButton("Limpiar datos");
  118. btnLimpiarDatos.setBounds(260, 285, 112, 23);
  119. contentPane.add(btnLimpiarDatos);
  120.  
  121. JLabel lblSueldo = new JLabel("Sueldo");
  122. lblSueldo.setBounds(23, 201, 46, 14);
  123. contentPane.add(lblSueldo);
  124.  
  125. txtSueldo = new JTextField();
  126. txtSueldo.setBounds(78, 198, 129, 20);
  127. contentPane.add(txtSueldo);
  128. txtSueldo.setColumns(10);
  129.  
  130. txtTel = new JTextField();
  131. txtTel.setBounds(75, 173, 86, 20);
  132. contentPane.add(txtTel);
  133. txtTel.setColumns(10);
  134.  
  135. }
  136.  
  137. public Connection getConexion() {
  138. return conexion;
  139. }
  140. public void setConexion(Connection conexion) {
  141. this.conexion = conexion;
  142. }
  143.  
  144. public boolean ejecutar(String sql) {
  145. try {
  146. Statement sentencia = getConexion().createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
  147. sentencia.executeUpdate(sql);
  148. sentencia.close();
  149. } catch (SQLException e) {
  150. e.printStackTrace();
  151. return false;
  152. }
  153. return true;
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement