Advertisement
Guest User

Untitled

a guest
Jan 11th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.EventQueue;
  3. import java.sql.*;
  4.  
  5. import javax.swing.JFrame;
  6. import javax.swing.JPanel;
  7. import javax.swing.border.EmptyBorder;
  8. import javax.swing.JLabel;
  9. import javax.swing.JOptionPane;
  10.  
  11. import java.awt.Font;
  12. import java.awt.Toolkit;
  13.  
  14. import javax.swing.JTextField;
  15. import javax.swing.JPasswordField;
  16. import javax.swing.JButton;
  17. import java.awt.event.ActionListener;
  18. import java.awt.event.WindowEvent;
  19. import java.awt.event.ActionEvent;
  20.  
  21. public class SignIn extends JFrame {
  22.  
  23. private JPanel contentPane;
  24. private JTextField Username;
  25. private JPasswordField Parola;
  26. private JTextField Numeutilizator;
  27.  
  28. /**
  29. * Launch the application.
  30. */
  31. public static void main(String[] args) {
  32. EventQueue.invokeLater(new Runnable() {
  33. public void run() {
  34. try {
  35. SignIn frame = new SignIn();
  36. frame.setVisible(true);
  37. } catch (Exception e) {
  38. e.printStackTrace();
  39. }
  40. }
  41. });
  42. }
  43.  
  44. /**
  45. * Create the frame.
  46. */
  47. public SignIn() {
  48. setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  49. setBounds(100, 100, 450, 300);
  50. contentPane = new JPanel();
  51. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  52. setContentPane(contentPane);
  53. contentPane.setLayout(null);
  54.  
  55. JLabel lblSignin = new JLabel("Creare Cont");
  56. lblSignin.setFont(new Font("Tahoma", Font.BOLD, 11));
  57. lblSignin.setBounds(165, 11, 106, 29);
  58. contentPane.add(lblSignin);
  59.  
  60. JLabel lblIntroducetiUsername = new JLabel("Introduceti Username");
  61. lblIntroducetiUsername.setBounds(44, 126, 147, 14);
  62. contentPane.add(lblIntroducetiUsername);
  63.  
  64. Username = new JTextField();
  65. Username.setBounds(44, 151, 119, 20);
  66. contentPane.add(Username);
  67. Username.setColumns(10);
  68.  
  69. JLabel lblIntroducetiParola = new JLabel("Introduceti Parola");
  70. lblIntroducetiParola.setBounds(44, 182, 119, 14);
  71. contentPane.add(lblIntroducetiParola);
  72.  
  73. Parola = new JPasswordField();
  74. Parola.setBounds(44, 207, 119, 20);
  75. contentPane.add(Parola);
  76.  
  77. JButton btnCreatiCont = new JButton("Creati Cont");
  78. btnCreatiCont.addActionListener(new ActionListener() {
  79. public void actionPerformed(ActionEvent arg0) {
  80. try{
  81. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/testegrila", "root" ,"");
  82. PreparedStatement posted = con.prepareStatement("INSERT INTO mytable (nume ,username, password) VALUES ('"+Numeutilizator.getText()+"','"+Username.getText()+"', '"+Parola.getText()+"')");
  83.  
  84. posted.executeUpdate();
  85. JOptionPane.showMessageDialog(null , "Cont creat");
  86.  
  87.  
  88. } catch(Exception e){System.out.print(e);}
  89. close();
  90.  
  91.  
  92. }
  93. });
  94. btnCreatiCont.setBounds(299, 206, 89, 23);
  95. contentPane.add(btnCreatiCont);
  96.  
  97. Numeutilizator = new JTextField();
  98. Numeutilizator.setBounds(44, 95, 119, 20);
  99. contentPane.add(Numeutilizator);
  100. Numeutilizator.setColumns(10);
  101.  
  102. JLabel Nume = new JLabel("Nume");
  103. Nume.setBounds(44, 70, 119, 14);
  104. contentPane.add(Nume);
  105. }
  106.  
  107. public void close() {
  108. WindowEvent winClosingEvent = new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
  109. Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement