Advertisement
Guest User

Untitled

a guest
Dec 5th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.12 KB | None | 0 0
  1. package rentas;
  2. import java.awt.*;
  3. import javax.swing.*;
  4. import javax.swing.border.EmptyBorder;
  5. import java.awt.event.*;
  6. import java.sql.*;
  7. @SuppressWarnings("serial")
  8. public class Registro extends JFrame {
  9. private JPanel contentPane;
  10. private JTextField caja1, caja2, caja3, caja4, caja5, caja6;
  11. public static void main(String[] args) {
  12. EventQueue.invokeLater(new Runnable() {
  13. public void run() {
  14. try {
  15. Registro frame = new Registro();
  16. frame.setVisible(true);
  17. } catch (Exception e) {
  18. e.printStackTrace();
  19. }
  20. }
  21. });
  22. }
  23. public Registro() {
  24. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  25. setBounds(100, 100, 450, 500);
  26. contentPane = new JPanel();
  27. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  28. setContentPane(contentPane);
  29. contentPane.setLayout(null);
  30. //Etiqueta Cliente//
  31. JLabel lblNewLabel = new JLabel("Cliente");
  32. lblNewLabel.setBounds(22, 33, 46, 14);
  33. contentPane.add(lblNewLabel);
  34. //Etiqueta Juego//
  35. JLabel lblNewLabel_1 = new JLabel("Juego");
  36. lblNewLabel_1.setBounds(22, 66, 46, 14);
  37. contentPane.add(lblNewLabel_1);
  38. //Etiqueta Tiempo//
  39. JLabel lblNewLabel_2 = new JLabel("Tiempo");
  40. lblNewLabel_2.setBounds(22, 99, 46, 14);
  41. contentPane.add(lblNewLabel_2);
  42. //Etiqueta de la BD//
  43. JLabel lblNewLabel_3 = new JLabel("Rentas Alola");
  44. lblNewLabel_3.setBounds(100, 3, 120, 30);
  45. contentPane.add(lblNewLabel_3);
  46. //Etiqueta Consola
  47. JLabel lblNewLabel_4 = new JLabel("Consola");
  48. lblNewLabel_4.setBounds(22, 132, 120, 30);
  49. contentPane.add(lblNewLabel_4);
  50. //Etiqueta fecha
  51. JLabel lblNewLabel_5 = new JLabel("Fecha");
  52. lblNewLabel_5.setBounds(22, 165, 120, 30);
  53. contentPane.add(lblNewLabel_5);
  54. //Etiqueta Socio
  55. JLabel lblNewLabel_6 = new JLabel("Socio");
  56. lblNewLabel_6.setBounds(22, 198, 120, 30);
  57. contentPane.add(lblNewLabel_6);
  58. //Crear caja de texto para capturar quien es el cliente
  59. caja1 = new JTextField();
  60. caja1.setBounds(102, 33, 175, 20);
  61. contentPane.add(caja1);
  62. caja1.setColumns(10);
  63. //Crear caja de texto para capturar el nombre del juego
  64. caja2 = new JTextField();
  65. caja2.setText("");
  66. caja2.setBounds(102, 66, 175, 20);
  67. contentPane.add(caja2);
  68. caja2.setColumns(10);
  69. //Crear caja de texto para capturar el tiempo de renta
  70. caja3 = new JTextField();
  71. caja3.setBounds(102, 99, 86, 20);
  72. contentPane.add(caja3);
  73. caja3.setColumns(10);
  74. //Crear caja de texto para la consola
  75. caja4 = new JTextField();
  76. caja4.setBounds(102, 132, 86, 20);
  77. contentPane.add(caja4);
  78. caja4.setColumns(10);
  79. //Caja para capturar la fecha
  80. caja5 = new JTextField();
  81. caja5.setBounds(102, 165, 86, 20);
  82. contentPane.add(caja5);
  83. caja5.setColumns(10);
  84. //Caja para capturar si es socio o no
  85. caja6 = new JTextField();
  86. caja6.setBounds(102, 198, 25, 20);
  87. contentPane.add(caja6);
  88. caja6.setColumns(10);
  89. //Boton Guardar//
  90. JButton boton1 = new JButton("GUARDAR");
  91. boton1.addActionListener(new ActionListener() {
  92. public void actionPerformed(ActionEvent arg0) {
  93. try{
  94. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  95. //Base de datos
  96. String db= "jdbc:odbc:Driver=Microsoft Access Driver (*.mdb);DBQ=E:\\JuegosFormaAlola.mdb"; //Direccion del archivo
  97. Connection cn= DriverManager.getConnection(db,"","");
  98. java.sql.Statement s = cn.createStatement();
  99. //Tabla y campos
  100. String sql="insert into Registro (Cliente,Juego,Tiempo,Consola,Fecha,Socio)"+"values('"+Registro.this.caja1.getText()+"',"+"'"+Registro.this.caja2.getText()+"','"+Registro.this.caja3.getText()+"','"+Registro.this.caja4.getText()+"','"+Registro.this.caja5.getText()+"','"+Registro.this.caja6.getText()+"')";
  101. s.executeUpdate(sql);
  102. JOptionPane.showMessageDialog(rootPane, "Registros guardados correctamente");
  103. } catch (Exception ex){
  104. JOptionPane.showMessageDialog(rootPane, "El error es " + ex);
  105. }
  106. }
  107. });
  108. boton1.setBounds(116,240,150,23);
  109. contentPane.add(boton1);
  110. //Boton2
  111. JButton boton2 = new JButton("LIMPIAR");
  112. boton2.addActionListener(new ActionListener() {
  113. public void actionPerformed(ActionEvent arg0) {
  114. caja1.setText("");
  115. caja2.setText("");
  116. caja3.setText("");
  117. caja4.setText("");
  118. caja5.setText("");
  119. caja6.setText("");
  120. }});
  121. boton2.setBounds(116,273,150,23);
  122. contentPane.add(boton2);
  123. JButton boton3 = new JButton("SELECCIONAR");
  124. boton3.addActionListener(new ActionListener() {
  125. public void actionPerformed(ActionEvent arg0) {
  126. try{
  127. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  128. //Base de datos
  129. String db= "jdbc:odbc:Driver=Microsoft Access Driver (*.mdb);DBQ=E:\\JuegosFormaAlola.mdb"; //Direccion del archivo
  130. Connection cn= DriverManager.getConnection(db,"","");
  131. java.sql.Statement s = cn.createStatement();
  132. //Tabla y campos
  133. String sql="SELECT * FROM Registro";
  134. s.executeUpdate(sql);
  135. ResultSet result = s.executeQuery(sql);
  136. //de este resultado podés sacar más datos (es un set / objeto) por ejemplo
  137. int Nombre = result.getInt("Nombre");
  138. JOptionPane.showMessageDialog(rootPane, Nombre);
  139. } catch (Exception ex){
  140. JOptionPane.showMessageDialog(rootPane, "El error es " + ex);
  141. }
  142. }
  143. });
  144. boton3.setBounds(116,306,150,23);
  145. contentPane.add(boton3);
  146. JButton boton4 = new JButton("BORRAR");
  147. boton4.addActionListener(new ActionListener() {
  148. public void actionPerformed(ActionEvent arg0) {
  149. try{
  150. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  151. //Base de datos
  152. String db= "jdbc:odbc:Driver=Microsoft Access Driver (*.mdb);DBQ=E:\\JuegosFormaAlola.mdb"; //Direccion del archivo
  153. Connection cn= DriverManager.getConnection(db,"","");
  154. java.sql.Statement s = cn.createStatement();
  155. //Tabla y campos
  156. String sql="SELECT * FROM Registro WHERE Nombre";
  157. s.executeUpdate(sql);
  158. ResultSet result = s.executeQuery(sql);
  159. //de este resultado podés sacar más datos (es un set / objeto) por ejemplo
  160. int Nombre = result.getInt("Nombre");
  161. JOptionPane.showMessageDialog(rootPane, Nombre);
  162. } catch (Exception ex){
  163. JOptionPane.showMessageDialog(rootPane, "El error es " + ex);
  164. }
  165. }
  166. });
  167. boton4.setBounds(116,339,150,23);
  168. contentPane.add(boton4);
  169. final JButton boton5 = new JButton("SALIR");
  170. boton5.addActionListener(new ActionListener(){
  171. public void actionPerformed(ActionEvent ae){
  172. System.exit(0);
  173. }
  174.  
  175.  
  176. });
  177. boton5.setBounds(116,372,150,23);
  178. contentPane.add(boton5);
  179.  
  180. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement