Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.*;
- import javax.swing.*;
- import java.awt.*;
- import java.sql.*;
- class Admin implements ActionListener
- {
- JFrame f;
- JPanel p1;
- JLabel l1,l2,l3;
- JTextField t1,t2;
- JButton b1;
- Admin()
- {
- f=new JFrame("Admin");
- f.setSize(415,330);
- f.setResizable(false);
- f.setLocation(200,200);
- f.setLayout(null);
- f.setVisible(true);
- p1=new JPanel();
- p1.setBounds(0,0,420,50);
- p1.setBackground(Color.blue);
- f.add(p1);
- l1=new JLabel("STATE BANK OF INDIA");
- l1.setBounds(200,0,180,40);
- l1.setFont(new Font("Verdana",1,20));
- p1.add(l1);
- l2=new JLabel("User Name");
- l2.setBounds(60,80,100,30);
- f.add(l2);
- l3=new JLabel("Password");
- l3.setBounds(60,150,100,30);
- f.add(l3);
- t1=new JTextField();
- t1.setBounds(160,80,140,30);
- f.add(t1);
- t2=new JTextField();
- t2.setBounds(160,150,140,30);
- f.add(t2);
- b1=new JButton("Create Admin");
- b1.setBounds(160,210,140,30);
- b1.addActionListener(this);
- f.add(b1);
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- public void actionPerformed(ActionEvent ae)
- {
- if(ae.getSource()==b1)
- {
- String s1=t1.getText();
- String s2=t2.getText();
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bank","root","");
- Statement stat=con.createStatement();
- stat.executeUpdate("insert into Admin values('"+s1+"','"+s2+"')");
- JOptionPane.showMessageDialog(null,"inserted ");
- t1.setText("");
- t2.setText("");
- }
- catch(Exception e1)
- {
- JOptionPane.showMessageDialog(null,"ERROR");
- }
- }
- }
- public static void main(String args[])
- {
- new Admin();
- }
- }
Add Comment
Please, Sign In to add comment