Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. package uk.ac.hw.macs.CompanyDatabase;
  2. /*
  3. DBMS Application
  4. Monica Farrow
  5. (Adapted from a similar class in Core Java by Horstmann)
  6. A dialog box to obtain type of database,username and password,
  7. */
  8.  
  9. import java.awt.*;
  10. import javax.swing.*;
  11. import java.awt.event.*;
  12.  
  13. class UserPassDialog extends JDialog
  14. implements ActionListener
  15. {
  16. private JTextField username;
  17. private JPasswordField password;
  18. private JButton okButton;
  19.  
  20. public UserPassDialog(JFrame parent)
  21. {
  22. super(parent, "Log on", true);
  23. setSize(240,160);
  24.  
  25. //panel for username and password text fields
  26. JPanel userpassPanel = new JPanel();
  27. userpassPanel.setLayout(new GridLayout(2,2));
  28.  
  29. userpassPanel.add(new JLabel("User name:"));
  30. userpassPanel.add(username = new JTextField(""));
  31.  
  32. userpassPanel.add(new JLabel("Password:"));
  33. userpassPanel.add(password = new JPasswordField(""));
  34. password.setBackground(Color.lightGray);
  35.  
  36.  
  37. getContentPane().add("Center",userpassPanel);
  38.  
  39. //Panel for button
  40. Panel pOK = new Panel();
  41. okButton = new JButton("OK");
  42. okButton.addActionListener(this);
  43. pOK.add(okButton);
  44. getContentPane().add("South",pOK);
  45.  
  46.  
  47. }
  48.  
  49. //come here when OK button clicked
  50. public void actionPerformed(ActionEvent e)
  51. {
  52. Object source = e.getSource();
  53. if (source == okButton)
  54. {
  55. setVisible(false);
  56. }
  57.  
  58. }
  59.  
  60. //show Dialog
  61. public LogOn showDialog()
  62. {
  63. this.setVisible(true);
  64. String un = username.getText();
  65. String pw = new String (password.getPassword());
  66. return new LogOn(un,pw);
  67. }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement