Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.prog.ud4;
- import javax.swing.JFrame;
- import java.awt.GridBagLayout;
- import java.awt.GridLayout;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import java.awt.BorderLayout;
- import java.awt.FlowLayout;
- import java.awt.GridBagConstraints;
- import java.awt.Insets;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import javax.swing.JTextField;
- import javax.swing.JComboBox;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.JButton;
- public class altaClub {
- public altaClub(){
- JFrame frame = new JFrame();
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setTitle("Alta Club");
- JPanel panel1 = new JPanel(new GridLayout(3,0,0,0));
- JPanel panel2 = new JPanel(new GridLayout(3,1,0,0));
- JPanel buttons_panel = new JPanel(new FlowLayout());
- JLabel etiqueta1 = new JLabel("Nombre");
- JLabel etiqueta2 = new JLabel("Ciudad");
- JTextField texto1 = new JTextField(50);
- JTextField texto2 = new JTextField(50);
- JButton aceptar = new JButton("Aceptar");
- panel1.add(etiqueta1);
- panel2.add(texto1);
- panel1.add(etiqueta2);
- panel2.add(texto2);
- buttons_panel.add(aceptar);
- aceptar.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String nombre = texto1.getText().toString();
- String ciudad = texto2.getText().toString();
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection ("jdbc:mysql://localhost/prog","root", "");
- PreparedStatement pst = con.prepareStatement("insert into prog.club (nombre,ciudad) values(?,?)");
- pst.setString(1, nombre);
- pst.setString(2, ciudad);
- pst.executeUpdate();
- con.close();
- }
- catch(Exception ex){};
- }});
- frame.getContentPane().add(panel1, BorderLayout.WEST);
- frame.getContentPane().add(panel2, BorderLayout.CENTER);
- frame.getContentPane().add(buttons_panel, BorderLayout.PAGE_END);
- frame.pack();
- frame.setSize(350,200);
- frame.setLocation(350,450);
- frame.setVisible(true);
- }
- }
Add Comment
Please, Sign In to add comment