Advertisement
Guest User

Untitled

a guest
Apr 17th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.45 KB | None | 0 0
  1. public class LoginC {
  2.  
  3. private JFrame frame; //Frame name frame
  4.  
  5. /**
  6. * Launch the application.
  7. */
  8. public static void main(String[] args) {
  9. EventQueue.invokeLater(new Runnable() {
  10. public void run() {
  11. try {
  12. LoginC window = new LoginC();
  13.  
  14. window.frame.setVisible(true);
  15.  
  16. } catch (Exception e) {
  17. e.printStackTrace();
  18. }
  19. }
  20. });
  21. }
  22.  
  23. Connection connection=null;
  24. private JTextField textField1;
  25. private JPasswordField passwordField;
  26. /**
  27. * Create the application.
  28. */
  29.  
  30. public LoginC() {
  31. initialize();
  32. connection=SqliteConnection.dbConnector();
  33. }
  34.  
  35. /**
  36. * Initialize the contents of the frame.
  37. */
  38. private void initialize() {
  39. frame = new JFrame();
  40. frame.setBounds(100, 100, 450, 300);
  41. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  42. frame.getContentPane().setLayout(null);
  43.  
  44. JLabel lblUserName = new JLabel("User Name");
  45. lblUserName.setFont(new Font("Times New Roman", Font.BOLD, 15));
  46. lblUserName.setBounds(134, 82, 84, 23);
  47. frame.getContentPane().add(lblUserName);
  48.  
  49. JLabel lblPassword = new JLabel("Password");
  50. lblPassword.setFont(new Font("Times New Roman", Font.BOLD, 15));
  51. lblPassword.setBounds(134, 125, 84, 14);
  52. frame.getContentPane().add(lblPassword);
  53.  
  54. textField1 = new JTextField();
  55. textField1.setBounds(244, 82, 147, 23);
  56. frame.getContentPane().add(textField1);
  57. textField1.setColumns(10);
  58.  
  59. passwordField = new JPasswordField();
  60. passwordField.setBounds(244, 121, 147, 23);
  61. frame.getContentPane().add(passwordField);
  62.  
  63. JButton btnLogin = new JButton("Login");
  64. btnLogin.addActionListener(new ActionListener() {
  65. public void actionPerformed(ActionEvent arg0) {
  66. try{
  67. String query
  68.  
  69. = " select * from Login where USERNAME=? and PASSWORD=?";
  70. //String query="select * from LoginTb as L1,LoginTb as L2 where L1.USERNAME=L2.USERNAME and L1.PASSWORD=L2.PASSWORD; ";
  71. PreparedStatement pst = connection.prepareStatement(query);
  72. pst.setString(1,textField1.getText() );
  73. pst.setString(2,passwordField.getText() );
  74.  
  75. ResultSet rs=pst.executeQuery(); // variable object r s to keep track of result
  76. int count =0;
  77. while (rs.next())
  78. {
  79. count=count+1;
  80. }
  81. if (count ==1)
  82. {
  83. JOptionPane.showMessageDialog(null, "USERNAME and PASSWORD is correct");
  84. frame.dispose ();
  85. student ts = new student(); // import student resource
  86. ts.setVisible(true);
  87.  
  88. }
  89. else if (count>1)
  90. {
  91. JOptionPane.showMessageDialog(null, "Duplicated USERNAME and PASSWORD is invalid");
  92. }
  93. else
  94. {
  95. JOptionPane.showMessageDialog(null, "USERNAME and PASSWORD is not correct Try again...");
  96. }
  97.  
  98. rs.close(); // close connectors
  99. pst.close();
  100.  
  101. } catch (Exception e)
  102.  
  103. {
  104. JOptionPane.showMessageDialog(null, e);
  105. }
  106. }
  107. });
  108. btnLogin.setFont(new Font("Times New Roman", Font.BOLD, 17));
  109. btnLogin.setBounds(198, 168, 89, 23);
  110. frame.getContentPane().add(btnLogin);
  111. }}
  112.  
  113. public class student extends JFrame {
  114.  
  115. private JPanel contentPane;
  116. private JPanel contentPane1;
  117. private JTextField textField;
  118. private JTextField textField_3;
  119. private JTextField textField_2;
  120. Connection connection=null;
  121.  
  122.  
  123. /**
  124. * Launch the application.
  125. */
  126. public static void main(String[] args) {
  127. EventQueue.invokeLater(new Runnable() {
  128. public void run() {
  129. try {
  130. student frame = new student();
  131. frame.setVisible(true);
  132. } catch (Exception e) {
  133. e.printStackTrace();
  134. }
  135. }
  136. });
  137. }
  138.  
  139. /**
  140. * Create the frame.
  141. */
  142. public student() {
  143. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  144. setBounds(100, 100, 450, 300);
  145. contentPane = new JPanel();
  146. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  147. setContentPane(contentPane);
  148. contentPane.setLayout(null);
  149.  
  150. JLabel lblstudent = new JLabel("Student Screen");
  151. lblstudent.setFont(new Font("Times New Roman", Font.BOLD, 18));
  152. lblstudent.setBounds(142, 10, 150, 43);
  153. contentPane.add(lblstudent);
  154.  
  155. JButton btnNewButton = new JButton("List Info");
  156. btnNewButton.addActionListener(new ActionListener() {
  157.  
  158. public void actionPerformed(ActionEvent e) {
  159. Info();
  160. setVisible(true);
  161. }
  162. });
  163. }
  164.  
  165.  
  166. protected void Info() {
  167. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  168. setBounds(100, 100, 585, 387);
  169. contentPane = new JPanel();
  170. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  171. setContentPane(contentPane);
  172. contentPane.setLayout(null);
  173.  
  174. JLabel lblNewLabel = new JLabel("Name");
  175. lblNewLabel.setFont(new Font("Times New Roman", Font.BOLD, 14));
  176. lblNewLabel.setBounds(97, 11, 46, 14);
  177. contentPane.add(lblNewLabel);
  178.  
  179. textField = new JTextField();
  180. textField.setBounds(20, 30, 199, 20);
  181. contentPane.add(textField);
  182. textField.setColumns(10);
  183.  
  184. textField_3 = new JTextField();
  185. textField_3.setBounds(242, 30, 86, 20);
  186. contentPane.add(textField_3);
  187. textField_3.setColumns(10);
  188.  
  189. textField_2 = new JTextField();
  190. textField_2.setBounds(338, 30, 86, 20);
  191. contentPane.add(textField_2);
  192. textField_2.setColumns(10);
  193.  
  194. JLabel lblNewLabel_1 = new JLabel("Grade Level");
  195. lblNewLabel_1.setFont(new Font("Times New Roman", Font.BOLD, 14));
  196. lblNewLabel_1.setBounds(242, 11, 76, 14);
  197. contentPane.add(lblNewLabel_1);
  198.  
  199. JLabel lblNewLabel_2 = new JLabel("Reading Level");
  200. lblNewLabel_2.setFont(new Font("Times New Roman", Font.BOLD, 14));
  201. lblNewLabel_2.setBounds(338, 11, 93, 14);
  202. contentPane.add(lblNewLabel_2);
  203.  
  204. JLabel lblNewLabel_3 = new JLabel("Current Book");
  205. lblNewLabel_3.setFont(new Font("Times New Roman", Font.BOLD, 14));
  206. lblNewLabel_3.setBounds(459, 11, 100, 14);
  207. contentPane.add(lblNewLabel_3);
  208.  
  209. try{
  210.  
  211. Class.forName("org.sqlite.JDBC");
  212. String path=student.class.getResource("Booklander.sqlite").getPath();
  213. Connection connection=DriverManager.getConnection("jdbc:sqlite:C:\Users\Gozie\Desktop\Database\Booklander.sqlite");
  214. String SQL="select firstName,GradeLevel,ReadingLevel from Student,Login where firstName=? AND GradeLevel=? AND ReadingLevel=?";
  215. Statement statement=connection.createStatement();
  216. ResultSet rs=statement.executeQuery(SQL);
  217.  
  218. while(rs.next())
  219. {
  220. String FN= rs.getString("firstName");
  221. int GL = Integer.parseInt("GradeLevel");
  222. int RL= Integer.parseInt("ReadingLevel");
  223.  
  224. textField.setText(FN);
  225. System.out.println(""+FN);
  226. textField_3.setText(String.valueOf(GL));
  227. System.out.println(GL);
  228. textField_2.setText(String.valueOf(RL));
  229.  
  230.  
  231.  
  232. }
  233. connection.close();
  234. statement.close();
  235.  
  236. }
  237. catch(Exception e){System.out.println("Error");
  238. }
  239.  
  240.  
  241. private static void addPopup(Component component, final JPopupMenu popup) {
  242. component.addMouseListener(new MouseAdapter() {
  243. public void mousePressed(MouseEvent e) {
  244. if (e.isPopupTrigger()) {
  245. showMenu(e);
  246. }
  247. }
  248. public void mouseReleased(MouseEvent e) {
  249. if (e.isPopupTrigger()) {
  250. showMenu(e);
  251. }
  252. }
  253. private void showMenu(MouseEvent e) {
  254. popup.show(e.getComponent(), e.getX(), e.getY());
  255. }
  256. });
  257. }
  258. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement