Guest User

Untitled

a guest
Nov 25th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. import java.awt.event.*;
  2. import javax.swing.*;
  3. import javax.swing.JOptionPane;
  4.  
  5. public class Sw extends JFrame implements ActionListener{
  6.  
  7. JLabel unLabel, pwLabel;
  8. JTextField unTextField, pwTextField;
  9. JButton okButton, clearButton, exitButton;
  10. public Sw()
  11. {
  12. setLayout(null);
  13. unLabel = new JLabel("Username:");
  14. pwLabel = new JLabel("Password:");
  15.  
  16. unTextField = new JTextField("");
  17. pwTextField = new JTextField("");
  18.  
  19. okButton = new JButton("OK");
  20. clearButton = new JButton("RESET");
  21. exitButton = new JButton("EXIT");
  22.  
  23. unLabel.setBounds(50, 50, 100, 20);
  24. pwLabel.setBounds(50, 80, 100, 20);
  25.  
  26. unTextField.setBounds(150, 50, 100, 20);
  27. pwTextField.setBounds(150, 80, 100, 20);
  28.  
  29. okButton.setBounds(50, 150, 100, 20);
  30. clearButton.setBounds(150, 150, 100, 20);
  31. exitButton.setBounds(250, 150, 100, 20);
  32.  
  33. add(unLabel);
  34. add(pwLabel);
  35. add(unTextField);
  36. add(pwTextField);
  37. add(okButton);
  38. add(clearButton);
  39. add(exitButton);
  40.  
  41. okButton.addActionListener(this);
  42. clearButton.addActionListener(this);
  43. exitButton.addActionListener(this);
  44.  
  45. }
  46.  
  47. public void actionPerformed(ActionEvent event)
  48. {
  49. if (event.getSource()==clearButton)
  50. {
  51. unTextField.setText("");
  52. pwTextField.setText("");
  53. }
  54. else if (event.getSource()==exitButton)
  55. {
  56. System.exit(0);
  57. }
  58. else
  59. {
  60. if((unTextField.getText().equals("admin"))&&(pwTextField.getText().equals("123")))
  61. {
  62.  
  63. Sw me = new Sw();
  64. me.setSize(500, 300);
  65. me.setVisible(true);
  66.  
  67.  
  68. }
  69. }
  70.  
  71. }
  72.  
  73.  
  74.  
  75. public static void main(String[] args)
  76. {
  77.  
  78. Sw login = new Sw();
  79. login.setSize(500, 300);
  80. login.setVisible(true);
  81.  
  82.  
  83. }
  84. }
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. import java.awt.event.*;
  97. import java.awt.*;
  98. import javax.swing.*;
  99. import javax.swing.JOptionPane;
  100. public class DianaPerez extends JFrame implements ActionListener{
  101.  
  102. JLabel SnLabel, LnLabel, FnLabel, SubLabel;
  103. JTextField SnTextField, LnTextField, FnTextfield, SubTextfield;
  104. JButton OkButton;
  105.  
  106. public DianaPerez()
  107. {
  108. setLayout(null);
  109. SnLabel = new JLabel("Student Number: ");
  110. LnLabel = new JLabel("Last Name: ");
  111. FnLabel = new JLabel("First Name: ");
  112. SubLabel = new JLabel("Subject: ");
  113.  
  114.  
  115. SnTextField = new JTextField("");
  116. LnTextField = new JTextField("");
  117. FnTextfield = new JTextField("");
  118. SubTextfield = new JTextField("");
  119.  
  120. OkButton = new JButton("OK");
  121.  
  122.  
  123.  
  124. SnLabel.setBounds(50, 50, 100, 20);
  125. LnLabel.setBounds(50, 80, 100, 20);
  126. FnLabel.setBounds(50, 110, 100, 20);
  127. SubLabel.setBounds(50, 140, 100, 20);
  128.  
  129. SnTextField.setBounds(150, 50, 100, 20);
  130. LnTextField.setBounds(150, 80, 100, 20);
  131. FnTextfield.setBounds(150, 110, 100, 20);
  132. SubTextfield.setBounds(150, 140, 100, 20);
  133.  
  134. OkButton.setBounds(110, 180, 100, 20);
  135.  
  136. add(SnLabel);
  137. add(LnLabel);
  138. add(FnLabel);
  139. add(SubLabel);
  140. add(SnTextField);
  141. add(LnTextField);
  142. add(FnTextfield);
  143. add(SubTextfield);
  144. add(OkButton);
  145.  
  146.  
  147. OkButton.addActionListener(this);
  148.  
  149. }
  150.  
  151. public void actionPerformed(ActionEvent event)
  152. {
  153. if (event.getSource()==OkButton)
  154. {
  155. JOptionPane.showMessageDialog(rootPane, "CONGRATULATIONS");
  156. }
  157.  
  158. else
  159. {
  160. System.exit(0);
  161.  
  162.  
  163. }
  164.  
  165. }
  166.  
  167.  
  168.  
  169. public static void main(String[] args)
  170. {
  171.  
  172. DianaPerez me = new DianaPerez();
  173. me.setSize(500, 300);
  174. me.setVisible(true);
  175.  
  176.  
  177. }
  178. }
Add Comment
Please, Sign In to add comment