Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package rentas;
- import java.awt.*;
- import javax.swing.*;
- import javax.swing.border.EmptyBorder;
- import java.awt.event.*;
- import java.sql.*;
- @SuppressWarnings("serial")
- public class Registro extends JFrame {
- private JPanel contentPane;
- private JTextField caja1, caja2, caja3, caja4, caja5, caja6;
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Registro frame = new Registro();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- public Registro() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 500);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- //Etiqueta Cliente//
- JLabel lblNewLabel = new JLabel("Cliente");
- lblNewLabel.setBounds(22, 33, 46, 14);
- contentPane.add(lblNewLabel);
- //Etiqueta Juego//
- JLabel lblNewLabel_1 = new JLabel("Juego");
- lblNewLabel_1.setBounds(22, 66, 46, 14);
- contentPane.add(lblNewLabel_1);
- //Etiqueta Tiempo//
- JLabel lblNewLabel_2 = new JLabel("Tiempo");
- lblNewLabel_2.setBounds(22, 99, 46, 14);
- contentPane.add(lblNewLabel_2);
- //Etiqueta de la BD//
- JLabel lblNewLabel_3 = new JLabel("Rentas Alola");
- lblNewLabel_3.setBounds(100, 3, 120, 30);
- contentPane.add(lblNewLabel_3);
- //Etiqueta Consola
- JLabel lblNewLabel_4 = new JLabel("Consola");
- lblNewLabel_4.setBounds(22, 132, 120, 30);
- contentPane.add(lblNewLabel_4);
- //Etiqueta fecha
- JLabel lblNewLabel_5 = new JLabel("Fecha");
- lblNewLabel_5.setBounds(22, 165, 120, 30);
- contentPane.add(lblNewLabel_5);
- //Etiqueta Socio
- JLabel lblNewLabel_6 = new JLabel("Socio");
- lblNewLabel_6.setBounds(22, 198, 120, 30);
- contentPane.add(lblNewLabel_6);
- //Crear caja de texto para capturar quien es el cliente
- caja1 = new JTextField();
- caja1.setBounds(102, 33, 175, 20);
- contentPane.add(caja1);
- caja1.setColumns(10);
- //Crear caja de texto para capturar el nombre del juego
- caja2 = new JTextField();
- caja2.setText("");
- caja2.setBounds(102, 66, 175, 20);
- contentPane.add(caja2);
- caja2.setColumns(10);
- //Crear caja de texto para capturar el tiempo de renta
- caja3 = new JTextField();
- caja3.setBounds(102, 99, 86, 20);
- contentPane.add(caja3);
- caja3.setColumns(10);
- //Crear caja de texto para la consola
- caja4 = new JTextField();
- caja4.setBounds(102, 132, 86, 20);
- contentPane.add(caja4);
- caja4.setColumns(10);
- //Caja para capturar la fecha
- caja5 = new JTextField();
- caja5.setBounds(102, 165, 86, 20);
- contentPane.add(caja5);
- caja5.setColumns(10);
- //Caja para capturar si es socio o no
- caja6 = new JTextField();
- caja6.setBounds(102, 198, 25, 20);
- contentPane.add(caja6);
- caja6.setColumns(10);
- //Boton Guardar//
- JButton boton1 = new JButton("GUARDAR");
- boton1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- try{
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- //Base de datos
- String db= "jdbc:odbc:Driver=Microsoft Access Driver (*.mdb);DBQ=E:\\JuegosFormaAlola.mdb"; //Direccion del archivo
- Connection cn= DriverManager.getConnection(db,"","");
- java.sql.Statement s = cn.createStatement();
- //Tabla y campos
- 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()+"')";
- s.executeUpdate(sql);
- JOptionPane.showMessageDialog(rootPane, "Registros guardados correctamente");
- } catch (Exception ex){
- JOptionPane.showMessageDialog(rootPane, "El error es " + ex);
- }
- }
- });
- boton1.setBounds(116,240,150,23);
- contentPane.add(boton1);
- //Boton2
- JButton boton2 = new JButton("LIMPIAR");
- boton2.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- caja1.setText("");
- caja2.setText("");
- caja3.setText("");
- caja4.setText("");
- caja5.setText("");
- caja6.setText("");
- }});
- boton2.setBounds(116,273,150,23);
- contentPane.add(boton2);
- JButton boton3 = new JButton("SELECCIONAR");
- boton3.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- try{
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- //Base de datos
- String db= "jdbc:odbc:Driver=Microsoft Access Driver (*.mdb);DBQ=E:\\JuegosFormaAlola.mdb"; //Direccion del archivo
- Connection cn= DriverManager.getConnection(db,"","");
- java.sql.Statement s = cn.createStatement();
- //Tabla y campos
- String sql="SELECT * FROM Registro";
- s.executeUpdate(sql);
- ResultSet result = s.executeQuery(sql);
- //de este resultado podés sacar más datos (es un set / objeto) por ejemplo
- int Nombre = result.getInt("Nombre");
- JOptionPane.showMessageDialog(rootPane, Nombre);
- } catch (Exception ex){
- JOptionPane.showMessageDialog(rootPane, "El error es " + ex);
- }
- }
- });
- boton3.setBounds(116,306,150,23);
- contentPane.add(boton3);
- JButton boton4 = new JButton("BORRAR");
- boton4.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- try{
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- //Base de datos
- String db= "jdbc:odbc:Driver=Microsoft Access Driver (*.mdb);DBQ=E:\\JuegosFormaAlola.mdb"; //Direccion del archivo
- Connection cn= DriverManager.getConnection(db,"","");
- java.sql.Statement s = cn.createStatement();
- //Tabla y campos
- String sql="SELECT * FROM Registro WHERE Nombre";
- s.executeUpdate(sql);
- ResultSet result = s.executeQuery(sql);
- //de este resultado podés sacar más datos (es un set / objeto) por ejemplo
- int Nombre = result.getInt("Nombre");
- JOptionPane.showMessageDialog(rootPane, Nombre);
- } catch (Exception ex){
- JOptionPane.showMessageDialog(rootPane, "El error es " + ex);
- }
- }
- });
- boton4.setBounds(116,339,150,23);
- contentPane.add(boton4);
- final JButton boton5 = new JButton("SALIR");
- boton5.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent ae){
- System.exit(0);
- }
- });
- boton5.setBounds(116,372,150,23);
- contentPane.add(boton5);
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement