Advertisement
Guest User

Untitled

a guest
Jan 31st, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.Color;
  3. import java.awt.Dimension;
  4. import java.awt.Rectangle;
  5. import java.awt.Toolkit;
  6.  
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9.  
  10. import javax.swing.JApplet;
  11. import javax.swing.JButton;
  12. import javax.swing.JFrame;
  13. import javax.swing.JLabel;
  14. import javax.swing.JPasswordField;
  15. import javax.swing.JTextField;
  16. import javax.swing.UIManager;
  17.  
  18. public class Applety extends JApplet {
  19. private JButton jButton1 = new JButton();
  20. private JLabel lblUsername = new JLabel();
  21. private JLabel lblPassword = new JLabel();
  22. private JTextField txtUsername = new JTextField();
  23. private JPasswordField txtPassword = new JPasswordField();
  24. private JButton btnLogin = new JButton();
  25. private JLabel txtStatus = new JLabel();
  26.  
  27. public Applety() {
  28. }
  29.  
  30. private void jbInit() throws Exception {
  31. this.getContentPane().setLayout( null );
  32. lblUsername.setText("Username: ");
  33. lblUsername.setBounds(new Rectangle(25, 45, 70, 15));
  34. this.getContentPane().add(txtStatus, null);
  35. this.getContentPane().add(btnLogin, null);
  36. this.getContentPane().add(txtPassword, null);
  37. this.getContentPane().add(txtUsername, null);
  38. this.getContentPane().add(lblUsername, null);
  39. lblPassword.setText("Password: ");
  40. lblPassword.setBounds(new Rectangle(25, 65, 70, 15));
  41. lblUsername.setForeground(new Color(155, 50, 0));
  42. lblPassword.setForeground(new Color(155, 50, 0));
  43. txtUsername.setBounds(new Rectangle(110, 45, 70, 15));
  44. txtPassword.setBounds(new Rectangle(110, 65, 70, 15));
  45. txtPassword.addActionListener(new ActionListener() {
  46. public void actionPerformed(ActionEvent e) {
  47. txtPassword_actionPerformed(e);
  48. }
  49. });
  50. btnLogin.setText("Login");
  51. btnLogin.setBounds(new Rectangle(95, 140, 75, 21));
  52. btnLogin.addActionListener(new ActionListener() {
  53. public void actionPerformed(ActionEvent e) {
  54. btnLogin_actionPerformed(e);
  55. }
  56. });
  57. txtStatus.setText("");
  58. txtStatus.setBounds(new Rectangle(60, 90, 135, 40));
  59. txtStatus.setForeground(Color.red);
  60. this.getContentPane().add(lblPassword, null);
  61. }
  62.  
  63. public void init() {
  64. try {
  65. jbInit();
  66. } catch (Exception e) {
  67. e.printStackTrace();
  68. }
  69. }
  70.  
  71. public static void main(String[] args) {
  72. Applety applet = new Applety();
  73. JFrame frame = new JFrame();
  74. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  75. frame.getContentPane().add(applet, BorderLayout.CENTER);
  76. applet.init();
  77. applet.start();
  78. Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  79. frame.setSize(300, 230);
  80. frame.setTitle("Login form");
  81. Dimension frameSize = frame.getSize();
  82. frame.setLocation((d.width-frameSize.width)/9, (d.height-frameSize.height)/7);
  83. frame.setVisible(true);
  84. }
  85. static {
  86. try {
  87. } catch (Exception e) {
  88. }
  89. }
  90.  
  91. private void btnLogin_actionPerformed(ActionEvent e) {
  92. if (txtUsername.getText().equals("ahmedsofee") && txtPassword.getText().equals("55199")) {
  93. txtStatus.setText("wlcome admin!");
  94. txtStatus.setForeground(new Color(50, 200, 50));
  95. lblUsername.setVisible(false);
  96. txtUsername.setVisible(false);
  97. lblPassword.setVisible(false);
  98. txtPassword.setVisible(false);
  99. btnLogin.setVisible(false);
  100. //txtStatus.setBounds(new Rectangle(170, 1, 135, 40));
  101. for (int i = 0; i < 50; ++i) {
  102. txtStatus.setBounds(new Rectangle(130 + i, 1, 135, 40));
  103.  
  104. }
  105. }
  106. else {
  107. txtStatus.setForeground(new Color(200, 50, 50));
  108. if (txtUsername.getText().equals("") || txtPassword.getText().equals("")) {
  109. txtStatus.setText("Insufficient data!");
  110. }
  111. else if (!txtUsername.getText().equals("ahmedsofee")) {
  112. txtStatus.setText("Username is incorrect!");
  113. txtPassword.setText("");
  114. }
  115. else if (!txtPassword.getText().equals("55199")) {
  116. txtStatus.setText("Password is incorrect!");
  117. txtPassword.setText("");
  118. }
  119. }
  120. }
  121.  
  122. private void txtPassword_actionPerformed(ActionEvent e) {
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement