Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package interfaceprojecto;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.Arrays;
- import javax.swing.JFrame;
- import javax.swing.JPasswordField;//Esconder password
- import javax.swing.JFileChooser; //Escolher ficheiro
- import javax.swing.*;
- class Login extends JFrame{
- private final JTextField username;
- //private final JTextField password;
- private final JPasswordField password;
- private final JComboBox combo;
- private final JComboBox locais;
- private final JLabel label1;
- private final JLabel label2;
- //private final JButton login;
- //private final JButton registar; //Apenas existe login visto que a password
- //e atribuida ou tambem existe registar
- private final JButton botEntrar; //Para fazer login
- private final JButton botLimpa; //Decidir se limpa tudo ou apenas um dos campos
- private final JButton botSai;
- public Login() {
- this.setPreferredSize (new Dimension(600,450));
- this.setTitle("Login/Registar");
- this.setLocation (600,300); //Mais ou menos centrado
- this.setVisible(true);
- this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
- //this.setLayout(new FlowLayout());
- //final JPanel grid = new JPanel(new FlowLayout());
- this.setLayout (new GridLayout (7,2,15,15));
- //this.add(grid);
- label1 = new JLabel ("Username");
- this.add (label1);
- username = new JTextField();
- this.add(username);
- username.setPreferredSize (new Dimension(100,20));
- username.addActionListener (new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- }); //Mudar o método abstrato
- label2 = new JLabel ("Password");
- this.add (label2);
- password = new JPasswordField(); //cria novo objeto
- password.setEchoChar((char)0);
- //password = new JTextField();
- this.add(password); //adiciona ao container
- password.setPreferredSize (new Dimension(100,20));
- password.addActionListener (new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- password.setToolTipText("A password tem que ter pelo menos 5 carateres");
- }
- }); //Mudar o método abstrato
- //char[] pass = password.getPassword();
- //String pass = new String(password.getPassword());
- char[] correctpass = {'b','a','t','a','t','a'};
- //String correctpass = "batata";
- botEntrar = new JButton("Entrar");
- this.add(botEntrar);
- botEntrar.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- username.getText();
- password.getPassword();
- if ((password.getPassword()).equals(correctpass)) {
- System.out.println("Password correta");
- } else {
- System.out.println ("Password incorreta");
- }
- }
- });
- //Dentro do metodo abstrato, verificar se o username esta nos registados
- //e se a password corresponde a password desse username
- //Se sim, login successful Se nao, erro
- botLimpa = new JButton("Limpa");
- this.add(botLimpa);
- botLimpa.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- username.setText("");
- password.setText("");
- }
- });
- botSai = new JButton ("Sai");
- this.add(botSai);
- botSai.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- JFrame self = this;
- combo = new JComboBox (new String[] {"Up","Down"});
- combo.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent event) {
- //JComboBox c = (JComboBox)event.getSource();
- int x = 200 * combo.getSelectedIndex() + 100;
- self.setLocation(x, x);
- }
- });
- this.add(combo);
- locais = new JComboBox (new String[] {"Jardim", "Exposicao", "Bar"});
- locais.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- }); //Mudar metodo abstrato
- this.add (locais);
- this.pack();
- }
- }
- interface Filter{
- int convert (int x);
- }
- public class InterfaceProjecto {
- public static void main(String[] args) {
- Login Interface = new Login();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement