Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import java.sql.*;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import java.awt.Font;
- import java.awt.Toolkit;
- import javax.swing.JTextField;
- import javax.swing.JPasswordField;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.WindowEvent;
- import java.awt.event.ActionEvent;
- public class SignIn extends JFrame {
- private JPanel contentPane;
- private JTextField Username;
- private JPasswordField Parola;
- private JTextField Numeutilizator;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- SignIn frame = new SignIn();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public SignIn() {
- setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- setBounds(100, 100, 450, 300);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JLabel lblSignin = new JLabel("Creare Cont");
- lblSignin.setFont(new Font("Tahoma", Font.BOLD, 11));
- lblSignin.setBounds(165, 11, 106, 29);
- contentPane.add(lblSignin);
- JLabel lblIntroducetiUsername = new JLabel("Introduceti Username");
- lblIntroducetiUsername.setBounds(44, 126, 147, 14);
- contentPane.add(lblIntroducetiUsername);
- Username = new JTextField();
- Username.setBounds(44, 151, 119, 20);
- contentPane.add(Username);
- Username.setColumns(10);
- JLabel lblIntroducetiParola = new JLabel("Introduceti Parola");
- lblIntroducetiParola.setBounds(44, 182, 119, 14);
- contentPane.add(lblIntroducetiParola);
- Parola = new JPasswordField();
- Parola.setBounds(44, 207, 119, 20);
- contentPane.add(Parola);
- JButton btnCreatiCont = new JButton("Creati Cont");
- btnCreatiCont.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- try{
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/testegrila", "root" ,"");
- PreparedStatement posted = con.prepareStatement("INSERT INTO mytable (nume ,username, password) VALUES ('"+Numeutilizator.getText()+"','"+Username.getText()+"', '"+Parola.getText()+"')");
- posted.executeUpdate();
- JOptionPane.showMessageDialog(null , "Cont creat");
- } catch(Exception e){System.out.print(e);}
- close();
- }
- });
- btnCreatiCont.setBounds(299, 206, 89, 23);
- contentPane.add(btnCreatiCont);
- Numeutilizator = new JTextField();
- Numeutilizator.setBounds(44, 95, 119, 20);
- contentPane.add(Numeutilizator);
- Numeutilizator.setColumns(10);
- JLabel Nume = new JLabel("Nume");
- Nume.setBounds(44, 70, 119, 14);
- contentPane.add(Nume);
- }
- public void close() {
- WindowEvent winClosingEvent = new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
- Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement