Guest User

Untitled

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