Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.58 KB | None | 0 0
  1. public void LoginFrame()
  2. {
  3. //creates new frame with 'choiceFrame' variable
  4. loginFrame = new JFrame("Employee Login!");
  5.  
  6. //sets size of frame
  7. loginFrame.setSize(215,125);
  8.  
  9. //frame will close when you hit close button
  10. loginFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  11.  
  12. //displays frame in middle of page
  13. loginFrame.setLocationRelativeTo(null);
  14.  
  15. //initializes labels and what they will display
  16. userName = new JLabel("Username");
  17. password = new JLabel("Password");
  18.  
  19. //initializes textfields and size
  20. userNameTextBox = new JTextField(10);
  21. passwordTextBox = new JPasswordField(10);
  22.  
  23. //creates new panel, hold all components and displays them on frame
  24. JPanel loginPanel = new JPanel();
  25.  
  26. //sets panel background to light gray
  27. loginPanel.setBackground(Color.lightGray);
  28.  
  29. //adds label to panel
  30. loginPanel.add(userName);
  31.  
  32. //sets textield background to light gray
  33. userNameTextBox.setBackground(Color.lightGray);
  34.  
  35. //add textfieled 'employeeFnameTextbox' to panel
  36. loginPanel.add(userNameTextBox);
  37.  
  38. //adds label to panel
  39. loginPanel.add(password);
  40.  
  41. //sets textield background to light gray
  42. passwordTextBox.setBackground(Color.lightGray);
  43.  
  44. //add textfieled 'employeeFnameTextbox' to panel
  45. loginPanel.add(passwordTextBox);
  46.  
  47. //sets 'loginButton' background/foreground to light gray
  48. loginButton.setBackground(Color.lightGray);
  49. loginButton.setForeground(Color.darkGray);
  50.  
  51. //adds button to panel
  52. loginPanel.add(loginButton);
  53.  
  54. //adds panel to frame
  55. loginFrame.add(loginPanel);
  56.  
  57. //sets 'welcomeFrame' to visible
  58. loginFrame.setVisible(true);
  59. }
  60.  
  61. /**
  62. When the login button is pressed it does required actions
  63. */
  64. public void LoginBtnAction()
  65. {
  66. loginButton.addActionListener(
  67. new ActionListener()
  68. {
  69. //method for events that will be performed when 'loginButton' is pressed
  70. public void actionPerformed(ActionEvent e)
  71. {
  72. try
  73. {
  74. //gets texts from specified text fields and assigns to instance variable
  75. userNameFromLogin = userNameTextBox.getText().trim();
  76. String password = passwordTextBox.getText().trim();
  77.  
  78. ArrayList<String> loginArray = new ArrayList<String>();
  79. Date date= new Date();
  80.  
  81. //sql statement that check if username and password exist
  82. String sql5 = "SELECT User_name,Password FROM Employee_Table WHERE User_name = '" + userName + "' and Password = '" + password + "'";
  83.  
  84. //execute query, assigning all records in db to 'rs5'
  85. rs5 = st.executeQuery(sql5);
  86.  
  87. //instance variables
  88. int count = 0;
  89.  
  90. //loops until reaches end up 'rs5'
  91. while(rs5.next())
  92. {
  93. count++;
  94. }
  95.  
  96. //statement and actions if 'userName' and 'password' match
  97. if(count == 1)
  98. {
  99. welcomeFrame.setVisible(true);
  100. loginFrame.setVisible(false);
  101.  
  102. userNameTextBox.setText("");
  103. passwordTextBox.setText("");
  104.  
  105. loginArray.add(userNameFromLogin);
  106. String timeStamp = ("User: " + loginArray.get(0) + "n" + "Time Stamp: " + new Timestamp(date.getTime()));
  107.  
  108. JOptionPane.showMessageDialog(null, timeStamp, "User Log", JOptionPane.INFORMATION_MESSAGE);
  109.  
  110. userNameLabel.setText(userNameFromLogin);
  111.  
  112. }
  113.  
  114. //statement and actions if 'userName' and 'password' do not match
  115. else
  116. {
  117. JOptionPane.showMessageDialog(null, "Username or password incorrect!");
  118. userNameTextBox.setText("");
  119. passwordTextBox.setText("");
  120. }
  121. }
  122.  
  123. catch(Exception ex)
  124. {
  125.  
  126. }
  127. }
  128. });
  129. }
  130.  
  131. /**
  132. Method that develops the Welcome Frame
  133. */
  134. public void WelcomeFrame()
  135. {
  136. //creates new frame with 'welcomeFrame' variable
  137. welcomeFrame = new JFrame("Welcome!");
  138.  
  139. //sets size of frame
  140. welcomeFrame.setSize(625,500);
  141.  
  142. //frame will close when you hit close button
  143. welcomeFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  144.  
  145. //displays frame in middle of page
  146. welcomeFrame.setLocationRelativeTo(null);
  147.  
  148. //creates new panel, hold all components and displays them on frame
  149. JPanel welcomePanel = new JPanel();
  150.  
  151. //sets welcomePanel to null
  152. welcomePanel.setLayout(null);
  153.  
  154. //sets label to image
  155. bannerImage = new ImageIcon(getClass().getResource("moes.jpg"));
  156. bannerLabel = new JLabel(bannerImage);
  157.  
  158. //sets location of image on panel
  159. bannerLabel.setBounds(0, 0, 610, 85);
  160.  
  161. //adds image to panel
  162. welcomePanel.add(bannerLabel);
  163.  
  164. //set label text
  165. versionLabel = new JLabel("current version: v4.0");
  166.  
  167. //sets location of label on panel
  168. versionLabel.setBounds(485, 435, 120, 20);
  169.  
  170. //add label to panel
  171. welcomePanel.add(versionLabel);
  172.  
  173. //sets 'aboutTextArea' size and specs
  174. aboutTextArea = new JTextArea("This application is intended to benifit both the employeesn and most importantly"
  175. +"the customers of Moes Barbeque");
  176.  
  177. //sets textarea background to light gray
  178. aboutTextArea.setBackground(Color.lightGray);
  179.  
  180. //sets location of textarea on panel
  181. aboutTextArea.setBounds(470, 80, 320, 300);
  182.  
  183. //sets textarea visibility to false
  184. aboutTextArea.setVisible(false);
  185.  
  186. //add 'aboutTextArea' to panel
  187. welcomePanel.add(aboutTextArea);
  188.  
  189. //sets panel background to light gray
  190. welcomePanel.setBackground(Color.white);
  191.  
  192. //sets 'homeButton' background/foreground to light gray
  193. homeButton.setBackground(Color.white);
  194. homeButton.setForeground(Color.darkGray);
  195.  
  196. //sets location of 'homeButton' on panel
  197. homeButton.setBounds(0, 120, 90, 20);
  198.  
  199. //sets border of button to false
  200. homeButton.setBorderPainted(false);
  201.  
  202. //adds button to panel
  203. welcomePanel.add(homeButton);
  204.  
  205. //sets 'employeeFormHomeButton' background/foreground to light gray
  206. employeeFormHomeButton.setBackground(Color.white);
  207. employeeFormHomeButton.setForeground(Color.darkGray);
  208.  
  209. //sets location of 'employeeFormHomeButton' on panel
  210. employeeFormHomeButton.setBounds(0, 160, 145, 20);
  211.  
  212. //sets border of button to false
  213. employeeFormHomeButton.setBorderPainted(false);
  214.  
  215. //adds button to panel
  216. welcomePanel.add(employeeFormHomeButton);
  217.  
  218. //sets 'employeeSearchHomeButton' background/foreground to light gray
  219. employeeSearchHomeButton.setBackground(Color.white);
  220. employeeSearchHomeButton.setForeground(Color.darkGray);
  221.  
  222. //sets location of 'employeeFormHomeButton' on panel
  223. employeeSearchHomeButton.setBounds(20, 190, 145, 20);
  224.  
  225. //sets border of button to false
  226. employeeSearchHomeButton.setBorderPainted(false);
  227.  
  228. //adds button to panel
  229. welcomePanel.add(employeeSearchHomeButton);
  230.  
  231. //sets 'customerFormHomeButton' background/foreground to light gray
  232. customerFormHomeButton.setBackground(Color.white);
  233. customerFormHomeButton.setForeground(Color.darkGray);
  234.  
  235. //sets location of 'customerFormHomeButton' on panel
  236. customerFormHomeButton.setBounds(0, 230, 145, 20);
  237.  
  238. //sets border of button to false
  239. customerFormHomeButton.setBorderPainted(false);
  240.  
  241. //adds button to panel
  242. welcomePanel.add(customerFormHomeButton);
  243.  
  244. //sets 'customerSearchHomeButton' background/foreground to light gray
  245. customerSearchHomeButton.setBackground(Color.white);
  246. customerSearchHomeButton.setForeground(Color.darkGray);
  247.  
  248. //sets location of 'customerSearchHomeButton' on panel
  249. customerSearchHomeButton.setBounds(20, 260, 145, 20);
  250.  
  251. //sets border of button to false
  252. customerSearchHomeButton.setBorderPainted(false);
  253.  
  254. //adds button to panel
  255. welcomePanel.add(customerSearchHomeButton);
  256.  
  257. //sets 'aboutButton' background/foreground to light gray
  258. aboutButton.setBackground(Color.white);
  259. aboutButton.setForeground(Color.darkGray);
  260.  
  261. //sets location of 'aboutButton' on panel
  262. aboutButton.setBounds(0, 300, 90, 20);
  263.  
  264. //sets border of button to false
  265. aboutButton.setBorderPainted(false);
  266.  
  267. //adds button to panel
  268. welcomePanel.add(aboutButton);
  269.  
  270. //sets 'logoutHomeButton' background/foreground to light gray
  271. logoutHomeButton.setBackground(Color.white);
  272. logoutHomeButton.setForeground(Color.darkGray);
  273.  
  274. //sets location of 'logoutHomeButton' on panel
  275. logoutHomeButton.setBounds(0, 340, 90, 20);
  276.  
  277. //sets border of button to false
  278. logoutHomeButton.setBorderPainted(false);
  279.  
  280. //adds button to panel
  281. welcomePanel.add(logoutHomeButton);
  282.  
  283. userNameLabel.setBounds(300, 350, 120, 70);
  284.  
  285. welcomePanel.add(userNameLabel);
  286.  
  287. //adds panel to frame
  288. welcomeFrame.add(welcomePanel);
  289.  
  290. //sets 'welcomeFrame' to visible
  291. welcomeFrame.setVisible(false);
  292. }
  293. /**
  294. Performs the welcome button frame actions
  295. */
  296. public void WelcomeBtnAction()
  297. {
  298. homeButton.addActionListener(
  299. new ActionListener()
  300. {
  301. //method for events that will be performed when 'employeeFormButton' is pressed
  302. public void actionPerformed(ActionEvent e)
  303. {
  304. //sets 'welcomeFrame' visiblity to true
  305. welcomeFrame.setVisible(true);
  306.  
  307. //sets size of frame
  308. welcomeFrame.setSize(625,500);
  309.  
  310. //sets 'aboutTextArea' visibility to false
  311. aboutTextArea.setVisible(false);
  312. }
  313. });
  314.  
  315. employeeFormHomeButton.addActionListener(
  316. new ActionListener()
  317. {
  318. //method for events that will be performed when 'employeeFormButton' is pressed
  319. public void actionPerformed(ActionEvent e)
  320. {
  321. employeeInputFrame.setVisible(true);
  322. welcomeFrame.setVisible(false);
  323. }
  324. });
  325.  
  326. employeeSearchHomeButton.addActionListener(
  327. new ActionListener()
  328. {
  329. //method for events that will be performed when 'employeeFormButton' is pressed
  330. public void actionPerformed(ActionEvent e)
  331. {
  332. //sets 'searchFrame' to visible
  333. searchFrame.setVisible(true);
  334.  
  335. //sets 'searchFrame' to different size when 'retrieveEmployeeButton' is pressed
  336. searchFrame.setSize(230,100);
  337.  
  338. //sets 'employeeID' to visible
  339. employeeID.setVisible(true);
  340.  
  341. //sets 'employeeIDTextBox' to visible
  342. employeeIDTextBox.setVisible(true);
  343.  
  344. //sets 'employeeIDSearchButton' to visible
  345. employeeIDSearchButton.setVisible(true);
  346.  
  347. //sets 'customerID' to not visible
  348. customerID.setVisible(false);
  349.  
  350. //sets 'customerIDTextBox' to not visible
  351. customerIDTextBox.setVisible(false);
  352.  
  353. //sets 'customerIDSearchButton' to not visible
  354. customerIDSearchButton.setVisible(false);
  355.  
  356. //sets 'welcomeFram; visibility to false
  357. welcomeFrame.setVisible(false);
  358. }
  359. });
  360.  
  361.  
  362. customerFormHomeButton.addActionListener(
  363. new ActionListener()
  364. {
  365. //method for events that will be performed when 'employeeFormButton' is pressed
  366. public void actionPerformed(ActionEvent e)
  367. {
  368. inputFrame.setVisible(true);
  369. welcomeFrame.setVisible(false);
  370. }
  371. });
  372.  
  373. customerSearchHomeButton.addActionListener(
  374. new ActionListener()
  375. {
  376. //method for events that will be performed when 'employeeFormButton' is pressed
  377. public void actionPerformed(ActionEvent e)
  378. {
  379. //sets 'searchFrame' to visible
  380. searchFrame.setVisible(true);
  381.  
  382. //sets 'searchFrame' to different size when 'retrieveEmployeeButton' is pressed
  383. searchFrame.setSize(230,100);
  384.  
  385. //sets 'customerID' to visible
  386. customerID.setVisible(true);
  387.  
  388. //sets 'customerIDTextBox' to visible
  389. customerIDTextBox.setVisible(true);
  390.  
  391. //sets 'customerIDSearchButton' to visible
  392. customerIDSearchButton.setVisible(true);
  393.  
  394. //sets 'customerID' to not visible
  395. employeeID.setVisible(false);
  396.  
  397. //sets 'customerIDTextBox' to not visible
  398. employeeIDTextBox.setVisible(false);
  399.  
  400. //sets 'customerIDSearchButton' to not visible
  401. employeeIDSearchButton.setVisible(false);
  402.  
  403. //sets 'welcomeFrame' visibility to false
  404. welcomeFrame.setVisible(false);
  405. }
  406. });
  407.  
  408. aboutButton.addActionListener(
  409. new ActionListener()
  410. {
  411. //method for events that will be performed when 'employeeFormButton' is pressed
  412. public void actionPerformed(ActionEvent e)
  413. {
  414. //sets size of frame
  415. welcomeFrame.setSize(820,500);
  416.  
  417. //sets textarea visibility to true
  418. aboutTextArea.setVisible(true);
  419. }
  420. });
  421.  
  422.  
  423. logoutHomeButton.addActionListener(
  424. new ActionListener()
  425. {
  426. //method for events that will be performed when 'employeeFormButton' is pressed
  427. public void actionPerformed(ActionEvent e)
  428. {
  429. loginFrame.setVisible(true);
  430. welcomeFrame.setVisible(false);
  431.  
  432. JOptionPane.showMessageDialog(null, "You have successfully logged out!");
  433. }
  434. });
  435. }
  436.  
  437. JLabel userNameLabel = new JLabel(userNameFromLogin);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement