Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. package jp_3;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Container;
  5. import java.awt.FlowLayout;
  6. import java.awt.GridBagConstraints;
  7. import java.awt.GridBagLayout;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import java.util.concurrent.TimeUnit;
  11.  
  12. import javax.swing.JButton;
  13. import javax.swing.JFrame;
  14. import javax.swing.JLabel;
  15. import javax.swing.JPanel;
  16. import javax.swing.JPasswordField;
  17. import javax.swing.JTextField;
  18.  
  19. public class MyFrame extends JFrame {
  20. private String user = "dominika";
  21. private char[] pass = {'1','2','3','4','5'};
  22. JTextField login = new JTextField("",15);
  23. JPasswordField haslo = new JPasswordField("",15);
  24. JLabel loginLabel = new JLabel("Login:");
  25. JLabel hasloLabel = new JLabel("Haslo:");
  26. JPanel p = new JPanel(new GridBagLayout());
  27. Container cp = getContentPane();
  28. int licznik = 0;
  29.  
  30. public MyFrame()
  31. {
  32. super("Logowanie");
  33. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  34.  
  35. GridBagConstraints px = new GridBagConstraints();
  36.  
  37. setSize(220, 160);
  38. setLocation(50,50);
  39. setLayout(new FlowLayout());
  40.  
  41. px.fill = GridBagConstraints.HORIZONTAL;
  42. px.gridx = 0;
  43. px.gridy = 0;
  44. p.add(loginLabel, px);
  45.  
  46. px.fill = GridBagConstraints.HORIZONTAL;
  47. px.gridx = 0;
  48. px.gridy = 1;
  49. p.add(login, px);
  50.  
  51. px.fill = GridBagConstraints.HORIZONTAL;
  52. px.gridx = 0;
  53. px.gridy = 2;
  54. p.add(hasloLabel, px);
  55.  
  56. px.fill = GridBagConstraints.HORIZONTAL;
  57. px.gridx = 0;
  58. px.gridy = 3;
  59. p.add(haslo, px);
  60.  
  61. add(p);
  62.  
  63. //add(new JButton("Ok"));
  64. OkButton Ok = new OkButton();
  65. add(Ok);
  66. AnulujButton Anuluj = new AnulujButton();
  67. add(Anuluj);
  68.  
  69. Ok.addActionListener( new ActionListener()
  70. {
  71. @Override
  72. public void actionPerformed(ActionEvent e)
  73. {
  74. /* if(s == "abcd") {
  75. //System.out.print("dobrze");
  76. p.setBackground(Color.GREEN);
  77. cp.setBackground(Color.GREEN);
  78. }
  79. else {
  80. //System.out.print("zle\n");
  81. p.setBackground(Color.RED);
  82. cp.setBackground(Color.RED);
  83. }*/
  84. if( (login.getText() == user) && (haslo.getPassword() == pass) ) {
  85. //System.out.print("dobrze");
  86. p.setBackground(Color.GREEN);
  87. cp.setBackground(Color.GREEN);
  88. }
  89. else {
  90. //System.out.print("zle\n");
  91. //System.out.print(username.getText());
  92. p.setBackground(Color.RED);
  93. cp.setBackground(Color.RED);
  94. }
  95. }
  96.  
  97. });
  98.  
  99. setVisible(true);
  100. }
  101.  
  102. class OkButton extends JButton {
  103. OkButton() {
  104. super("Ok");
  105. //addActionListener(this);
  106. }
  107. //@Override
  108. /*public void actionPerformed(ActionEvent e) {
  109. licznik++;
  110. if (licznik < 3)
  111. {
  112. p.setBackground(Color.GREEN);
  113. cp.setBackground(Color.GREEN);
  114. }
  115. else
  116. {
  117. p.setBackground(Color.RED);
  118. cp.setBackground(Color.RED);
  119. licznik = 0;
  120. }
  121. }*/
  122. }
  123. class AnulujButton extends JButton //implements ActionListener
  124. {
  125. AnulujButton() {
  126. super("Anuluj");
  127. // addActionListener(this);
  128. }
  129. /*@Override
  130. public void actionPerformed(ActionEvent e) {
  131. licznik++;
  132. if (licznik < 3)
  133. {
  134. p.setBackground(Color.GREEN);
  135. cp.setBackground(Color.GREEN);
  136. }
  137. else
  138. {
  139. p.setBackground(Color.RED);
  140. cp.setBackground(Color.RED);
  141. licznik = 0;
  142. }
  143. }*/
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement