Advertisement
Guest User

Java Login 1

a guest
Oct 31st, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. Login.java
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6. import java.sql.*;
  7.  
  8. public class Login extends JFrame implements ActionListener
  9. {
  10. JLabel l1, l2, l3;
  11. JTextField tf1;
  12. JButton btn1;
  13. JPasswordField p1;
  14.  
  15. Login()
  16. {
  17. setTitle("Login Form in Windows Form");
  18. setVisible(true);
  19. setSize(800, 800);
  20. setLayout(null);
  21. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  22.  
  23. l1 = new JLabel("Login Form in Windows Form:");
  24. l1.setForeground(Color.blue);
  25. l1.setFont(new Font("Serif", Font.BOLD, 20));
  26.  
  27. l2 = new JLabel("Enter Email:");
  28. l3 = new JLabel("Enter Password:");
  29. tf1 = new JTextField();
  30. p1 = new JPasswordField();
  31. btn1 = new JButton("Submit");
  32.  
  33. l1.setBounds(100, 30, 400, 30);
  34. l2.setBounds(80, 70, 200, 30);
  35. l3.setBounds(80, 110, 200, 30);
  36. tf1.setBounds(300, 70, 200, 30);
  37. p1.setBounds(300, 110, 200, 30);
  38. btn1.setBounds(150, 160, 100, 30);
  39.  
  40. add(l1);
  41. add(l2);
  42. add(tf1);
  43. add(l3);
  44. add(p1);
  45. add(btn1);
  46. btn1.addActionListener(this);
  47. }
  48.  
  49. public void actionPerformed(ActionEvent e)
  50. {
  51. showData();
  52. }
  53.  
  54. public void showData()
  55. {
  56. JFrame f1 = new JFrame();
  57. JLabel l, l0;
  58.  
  59. String str1 = tf1.getText();
  60. char[] p = p1.getPassword();
  61. String str2 = new String(p);
  62. try
  63. {
  64. Class.forName("oracle.jdbc.driver.OracleDriver");
  65. Connection con = DriverManager.getConnection("jdbc:oracle:thin:@mcndesktop07:1521:xe", "sandeep", "welcome");
  66. PreparedStatement ps = con.prepareStatement("select name from reg where email=? and pass=?");
  67. ps.setString(1, str1);
  68. ps.setString(2, str2);
  69. ResultSet rs = ps.executeQuery();
  70. if (rs.next())
  71. {
  72. f1.setVisible(true);
  73. f1.setSize(600, 600);
  74. f1.setLayout(null);
  75. l = new JLabel();
  76. l0 = new JLabel("you are succefully logged in..");
  77. l0.setForeground(Color.blue);
  78. l0.setFont(new Font("Serif", Font.BOLD, 30));
  79. l.setBounds(60, 50, 400, 30);
  80. l0.setBounds(60, 100, 400, 40);
  81.  
  82. f1.add(l);
  83. f1.add(l0);
  84. l.setText("Welcome " + rs.getString(1));
  85. l.setForeground(Color.red);
  86. l.setFont(new Font("Serif", Font.BOLD, 30));
  87.  
  88. } else
  89. {
  90. JOptionPane.showMessageDialog(null,
  91. "Incorrect email-Id or password..Try Again with correct detail");
  92. }
  93. }
  94. catch (Exception ex)
  95. {
  96. System.out.println(ex);
  97. }
  98. }
  99.  
  100. public static void main(String arr[])
  101. {
  102. new Login();
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement