Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. package interfaceprojecto;
  2.  
  3. import java.awt.Dimension;
  4. import java.awt.FlowLayout;
  5. import java.awt.GridLayout;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.util.Arrays;
  9. import javax.swing.JFrame;
  10. import javax.swing.JPasswordField;//Esconder password
  11. import javax.swing.JFileChooser; //Escolher ficheiro
  12. import javax.swing.*;
  13.  
  14. class Login extends JFrame{
  15.  
  16. private final JTextField username;
  17. //private final JTextField password;
  18.  
  19. private final JPasswordField password;
  20.  
  21. private final JComboBox combo;
  22. private final JComboBox locais;
  23.  
  24. private final JLabel label1;
  25. private final JLabel label2;
  26.  
  27. //private final JButton login;
  28. //private final JButton registar; //Apenas existe login visto que a password
  29. //e atribuida ou tambem existe registar
  30. private final JButton botEntrar; //Para fazer login
  31. private final JButton botLimpa; //Decidir se limpa tudo ou apenas um dos campos
  32. private final JButton botSai;
  33.  
  34.  
  35.  
  36.  
  37. public Login() {
  38. this.setPreferredSize (new Dimension(600,450));
  39. this.setTitle("Login/Registar");
  40. this.setLocation (600,300); //Mais ou menos centrado
  41. this.setVisible(true);
  42. this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
  43. //this.setLayout(new FlowLayout());
  44.  
  45.  
  46. //final JPanel grid = new JPanel(new FlowLayout());
  47. this.setLayout (new GridLayout (7,2,15,15));
  48. //this.add(grid);
  49.  
  50.  
  51. label1 = new JLabel ("Username");
  52. this.add (label1);
  53. username = new JTextField();
  54. this.add(username);
  55. username.setPreferredSize (new Dimension(100,20));
  56. username.addActionListener (new ActionListener() {
  57. @Override
  58. public void actionPerformed(ActionEvent e) {
  59. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  60. }
  61. }); //Mudar o método abstrato
  62.  
  63.  
  64. label2 = new JLabel ("Password");
  65. this.add (label2);
  66. password = new JPasswordField(); //cria novo objeto
  67.  
  68. password.setEchoChar((char)0);
  69. //password = new JTextField();
  70. this.add(password); //adiciona ao container
  71. password.setPreferredSize (new Dimension(100,20));
  72. password.addActionListener (new ActionListener() {
  73. @Override
  74. public void actionPerformed(ActionEvent e) {
  75.  
  76. password.setToolTipText("A password tem que ter pelo menos 5 carateres");
  77.  
  78. }
  79. }); //Mudar o método abstrato
  80.  
  81. //char[] pass = password.getPassword();
  82. //String pass = new String(password.getPassword());
  83. char[] correctpass = {'b','a','t','a','t','a'};
  84. //String correctpass = "batata";
  85.  
  86. botEntrar = new JButton("Entrar");
  87. this.add(botEntrar);
  88. botEntrar.addActionListener(new ActionListener() {
  89. @Override
  90. public void actionPerformed(ActionEvent e) {
  91. username.getText();
  92. password.getPassword();
  93.  
  94.  
  95. if ((password.getPassword()).equals(correctpass)) {
  96. System.out.println("Password correta");
  97. } else {
  98. System.out.println ("Password incorreta");
  99. }
  100.  
  101.  
  102. }
  103. });
  104. //Dentro do metodo abstrato, verificar se o username esta nos registados
  105. //e se a password corresponde a password desse username
  106. //Se sim, login successful Se nao, erro
  107.  
  108.  
  109. botLimpa = new JButton("Limpa");
  110. this.add(botLimpa);
  111. botLimpa.addActionListener(new ActionListener() {
  112. @Override
  113. public void actionPerformed(ActionEvent e) {
  114. username.setText("");
  115. password.setText("");
  116. }
  117. });
  118.  
  119. botSai = new JButton ("Sai");
  120. this.add(botSai);
  121. botSai.addActionListener(new ActionListener() {
  122. @Override
  123. public void actionPerformed(ActionEvent e) {
  124. System.exit(0);
  125. }
  126. });
  127.  
  128.  
  129. JFrame self = this;
  130. combo = new JComboBox (new String[] {"Up","Down"});
  131. combo.addActionListener(new ActionListener(){
  132. @Override
  133. public void actionPerformed(ActionEvent event) {
  134. //JComboBox c = (JComboBox)event.getSource();
  135. int x = 200 * combo.getSelectedIndex() + 100;
  136. self.setLocation(x, x);
  137. }
  138. });
  139. this.add(combo);
  140.  
  141. locais = new JComboBox (new String[] {"Jardim", "Exposicao", "Bar"});
  142. locais.addActionListener(new ActionListener() {
  143. @Override
  144. public void actionPerformed(ActionEvent e) {
  145. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  146. }
  147. }); //Mudar metodo abstrato
  148. this.add (locais);
  149.  
  150.  
  151. this.pack();
  152. }
  153. }
  154.  
  155. interface Filter{
  156. int convert (int x);
  157. }
  158.  
  159. public class InterfaceProjecto {
  160. public static void main(String[] args) {
  161. Login Interface = new Login();
  162. }
  163.  
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement