Guest User

quersio altaclub

a guest
Jun 7th, 2016
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. package com.prog.ud4;
  2.  
  3.  
  4. import javax.swing.JFrame;
  5.  
  6. import java.awt.GridBagLayout;
  7. import java.awt.GridLayout;
  8.  
  9. import javax.swing.JLabel;
  10. import javax.swing.JPanel;
  11.  
  12. import java.awt.BorderLayout;
  13. import java.awt.FlowLayout;
  14. import java.awt.GridBagConstraints;
  15. import java.awt.Insets;
  16. import java.awt.event.ActionEvent;
  17. import java.awt.event.ActionListener;
  18. import java.sql.Connection;
  19. import java.sql.DriverManager;
  20. import java.sql.PreparedStatement;
  21.  
  22. import javax.swing.JTextField;
  23. import javax.swing.JComboBox;
  24. import javax.swing.DefaultComboBoxModel;
  25. import javax.swing.JButton;
  26.  
  27. public class altaClub {
  28.  
  29. public altaClub(){
  30.  
  31. JFrame frame = new JFrame();
  32. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  33. frame.setTitle("Alta Club");
  34.  
  35. JPanel panel1 = new JPanel(new GridLayout(3,0,0,0));
  36. JPanel panel2 = new JPanel(new GridLayout(3,1,0,0));
  37. JPanel buttons_panel = new JPanel(new FlowLayout());
  38.  
  39. JLabel etiqueta1 = new JLabel("Nombre");
  40. JLabel etiqueta2 = new JLabel("Ciudad");
  41.  
  42. JTextField texto1 = new JTextField(50);
  43. JTextField texto2 = new JTextField(50);
  44.  
  45.  
  46. JButton aceptar = new JButton("Aceptar");
  47.  
  48. panel1.add(etiqueta1);
  49. panel2.add(texto1);
  50. panel1.add(etiqueta2);
  51. panel2.add(texto2);
  52.  
  53. buttons_panel.add(aceptar);
  54. aceptar.addActionListener(new ActionListener() {
  55. public void actionPerformed(ActionEvent e) {
  56. String nombre = texto1.getText().toString();
  57. String ciudad = texto2.getText().toString();
  58.  
  59.  
  60.  
  61. try {
  62. Class.forName("com.mysql.jdbc.Driver");
  63. Connection con = DriverManager.getConnection ("jdbc:mysql://localhost/prog","root", "");
  64. PreparedStatement pst = con.prepareStatement("insert into prog.club (nombre,ciudad) values(?,?)");
  65. pst.setString(1, nombre);
  66.  
  67. pst.setString(2, ciudad);
  68.  
  69. pst.executeUpdate();
  70. con.close();
  71. }
  72.  
  73.  
  74. catch(Exception ex){};
  75. }});
  76.  
  77.  
  78. frame.getContentPane().add(panel1, BorderLayout.WEST);
  79. frame.getContentPane().add(panel2, BorderLayout.CENTER);
  80. frame.getContentPane().add(buttons_panel, BorderLayout.PAGE_END);
  81.  
  82. frame.pack();
  83. frame.setSize(350,200);
  84. frame.setLocation(350,450);
  85. frame.setVisible(true);
  86. }
  87. }
Add Comment
Please, Sign In to add comment