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.awt.event.WindowEvent;
- import java.util.Arrays;
- import javax.swing.JFrame;
- import javax.swing.JPasswordField;//Esconder password
- import javax.swing.JFileChooser; //Escolher ficheiro
- import javax.swing.*;
- class MenuInicial extends JFrame{ //O que por no registar? (opcoes)
- private final JLabel welcome; //Texto a dar as boas vindas
- private final JButton botLogin;
- private final JButton botRegistar;
- private final JButton botSair;
- public MenuInicial(){
- this.setPreferredSize (new Dimension(450,300));
- this.setTitle("Menu Inicial");
- this.setLocation (600,300); //Mais ou menos centrado
- this.setVisible(true);
- this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
- this.setLayout (new GridLayout (4,2,20,20));
- welcome = new JLabel (" Bem vindo ao Mega Convivio do DEI");
- this.add (welcome);
- botLogin = new JButton("Login");
- this.add(botLogin);
- botLogin.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Login Interface = new Login();
- dispose();
- }
- });
- botRegistar = new JButton("Registar");
- this.add(botRegistar);
- botRegistar.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Registar r = new Registar();
- dispose();
- }
- });
- botSair = new JButton("Sair");
- this.add(botSair);
- botSair.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- this.pack();
- }
- }
- /***************************REGISTAR**************************************************************************************************/
- class Registar extends JFrame{
- private final JTextField nome;
- private final JTextField username;
- private final JPasswordField password;
- private final JPasswordField confirmapass;
- private final JComboBox showpass;
- private final JLabel label0;
- private final JLabel label1;
- private final JLabel label2;
- private final JLabel label3;
- private final JButton botEntrar; //Para fazer login
- private final JButton botLimpa; //Decidir se limpa tudo ou apenas um dos campos
- private final JButton botSai;
- private final JButton botRetroceder;
- public Registar() {
- this.setPreferredSize (new Dimension(600,450));
- this.setTitle("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);
- label0 = new JLabel ("Nome");
- this.add (label0);
- nome = new JTextField();
- this.add(nome);
- nome.setPreferredSize (new Dimension(100,20));
- nome.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
- label1 = new JLabel ("Escolher 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 ("Escolher Password");
- this.add (label2);
- password = new JPasswordField(); //cria novo objeto
- 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
- label3 = new JLabel ("Confirmar Password");
- this.add (label3);
- confirmapass = new JPasswordField();
- this.add(confirmapass);
- confirmapass.setPreferredSize (new Dimension(100,20));
- confirmapass.addActionListener (new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- if ((password.getPassword()).equals(confirmapass)){
- }
- else{
- System.out.println("As passwords tem que ser iguais");
- }
- }
- }); //Mudar o método abstrato
- //SHOW PASSWORDDDDDDDDDDDDDDDD
- //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();
- confirmapass.getPassword();
- if (Arrays.equals(password.getPassword(),confirmapass.getPassword())) {
- System.out.println("Registo bem sucedido");
- EscolhaLocais escolhe = new EscolhaLocais();
- dispose();
- } else {
- JOptionPane.showMessageDialog(rootPane, "As passwords têm que ser iguais", "Erro", JOptionPane.ERROR_MESSAGE);
- }
- }
- });
- //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);
- }
- });
- botRetroceder = new JButton ("Retroceder");
- this.add(botRetroceder);
- botRetroceder.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- MenuInicial m = new MenuInicial();
- dispose();
- }
- });
- JFrame self = this;
- String [] opcao = new String []{"Mostrar Password","Esconder Password"};
- // JComboBox<String> oplist = new JComboBox<>(opcao);
- showpass = new JComboBox (opcao);
- showpass.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent event) {
- JComboBox <String> oplist = (JComboBox<String>)event.getSource();
- String opcao = (String) oplist.getSelectedItem();
- if (opcao.equals("Mostrar Password")){
- password.setEchoChar((char)0);
- confirmapass.setEchoChar((char)0);
- }
- else{
- password.setEchoChar('•');
- confirmapass.setEchoChar('•');
- }
- }
- });
- this.add(showpass);
- this.pack();
- }
- }
- /***************************LOGIN********************************************************************************************/
- class Login extends JFrame{
- private final JTextField username;
- //private final JTextField password;
- private final JPasswordField password;
- private final JComboBox showpass;
- private final JLabel label1;
- private final JLabel label2;
- private final JButton botEntrar; //Para fazer login
- private final JButton botLimpa; //Decidir se limpa tudo ou apenas um dos campos
- private final JButton botSai;
- private final JButton botRetroceder;
- public Login() {
- this.setPreferredSize (new Dimension(600,450));
- this.setTitle("Login");
- 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(Arrays.equals(password.getPassword(), correctpass)){
- System.out.println("Password correta");
- dispose();
- EscolhaLocais escolhe = new EscolhaLocais();
- } 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);
- }
- });
- botRetroceder = new JButton ("Retroceder");
- this.add(botRetroceder);
- botRetroceder.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- MenuInicial m = new MenuInicial();
- //this.dispose(); //Remove JFrame 1
- //JFrame2.setVisible(true) //Show other frame
- dispose();
- }
- });
- JFrame self = this;
- String [] opcao = new String []{"Mostrar Password","Esconder Password"};
- // JComboBox<String> oplist = new JComboBox<>(opcao);
- showpass = new JComboBox (opcao);
- showpass.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent event) {
- JComboBox <String> oplist = (JComboBox<String>)event.getSource();
- String opcao = (String) oplist.getSelectedItem();
- if (opcao.equals("Mostrar Password")){
- password.setEchoChar((char)0);
- }
- else{
- password.setEchoChar('•');
- }
- }
- });
- this.add(showpass);
- this.pack();
- }
- }
- /***************************ESCOLHA_LOCAIS************************************************************************************/
- class EscolhaLocais extends JFrame{
- private final JComboBox locais;
- private final JButton botEscolheLocal;
- private final JButton botShowGuest;
- private final JButton botReceitaMin;
- private final JButton botRetroceder;
- public EscolhaLocais(){
- this.setPreferredSize (new Dimension(500,400));
- this.setTitle("Escolha Locais");
- this.setLocation (600,300); //Mais ou menos centrado
- this.setVisible(true);
- this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
- this.setLayout(new GridLayout (5,1,30,30));
- botEscolheLocal = new JButton ("Escolhe locais");
- this.add(botEscolheLocal);
- botShowGuest = new JButton ("Show Guest Lists");
- this.add(botShowGuest);
- botReceitaMin = new JButton ("Receita Minima Prevista");
- this.add(botReceitaMin);
- botRetroceder = new JButton ("Retroceder");
- this.add(botRetroceder);
- botRetroceder.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Login Interface = new Login();
- dispose();
- }
- });
- JFrame self = this;
- 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) {
- MenuInicial m = new MenuInicial();
- //Login Interface = new Login();
- //Registar r = new Registar();
- //EscolhaLocais escolhe = new EscolhaLocais();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement