Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 27.85 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package projeto_rascunho;
  7.  
  8. import java.util.Random;
  9. import java.util.Scanner;
  10. import java.lang.Math;
  11. import java.util.StringTokenizer;
  12. import java.util.List;
  13. import java.util.ListIterator;
  14. import java.util.ArrayList;
  15. import java.io.*;
  16. import java.lang.Math;
  17. import java.util.StringTokenizer;
  18. //Para a interface
  19. import java.awt.Dimension;
  20. import java.awt.FlowLayout;
  21. import java.awt.GridLayout;
  22. import java.awt.event.ActionEvent;
  23. import java.awt.event.ActionListener;
  24. import java.awt.event.WindowEvent;
  25. import java.util.Arrays;
  26. import javax.swing.JFrame;
  27. import javax.swing.JPasswordField;//Esconder password
  28. import javax.swing.JFileChooser; //Escolher ficheiro
  29. import javax.swing.*;
  30.  
  31. /*----------------------------CONVIVIO NO DEI----------------------------------------*/
  32. class Convivio{
  33.    
  34.     public String nome_convivio;
  35.    
  36.     //public List<Locais> locais = new ArrayList<>();
  37.     //public List<Elemento_dei> registados = new ArrayList<>();
  38.    
  39.    
  40.     public Convivio(String nome_convivio){
  41.         this.nome_convivio = nome_convivio;
  42.     }
  43.     public void login(){
  44.        
  45.     } //Pedir username e password
  46.     public void inscricao_convivio(){ //Login e registar // ao registar verificar se ja existe o username
  47.        
  48.     } //Tem que pedir sempre o nome para verificar se pertence ao DEI  //Verificar sempre se ha username igual
  49.     public void show_locais(){ //Mostrar sempre depois da inscricao, ver numero atual de inscritos de cada um e a lotacao (se aplicavel)
  50.         List<Locais> locais = new ArrayList<>();
  51.         try(ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Locais_obj.txt"))){
  52.             locais = (ArrayList) oin.readObject();
  53.         }catch(IOException | ClassNotFoundException e){
  54.             System.out.println(e.getMessage());
  55.         }
  56.         for (Locais l : locais){
  57.             l.print();
  58.         }
  59.     }
  60.     public void escolha_locais(){ //ate cinco
  61.    
  62.     } //Na interface so ter 5 espacos //Ter um ficheiro objetos dos inscritos em cada local (secalhar)
  63.     public void show_guests(){ //Nao sei se mete aqui ou se se mete na class locais
  64.        
  65.     } //Ficheiro objetos para cada guest de cada bar
  66.     /*public double receita(){ //Nao interessa o que esta ca dentro por enquanto
  67.         List<Locais> locais = new ArrayList<>();
  68.         double receita = 0;
  69.         for (Locais l: locais){
  70.            double receita_local = 0;
  71.            receita += l.receita;
  72.         }
  73.         return receita;
  74.     }*/
  75. }
  76.  
  77.  
  78. /*----------------------------LOCAIS CONVIVIO-----------------------------------------*/
  79. class Locais implements Serializable{
  80.     private String coord_gps;
  81.     public String nome;
  82.    
  83.     public List<Inscrito> inscritos = new ArrayList<>();
  84.    
  85.     public Locais(String coord_gps,String nome){
  86.         this.coord_gps = coord_gps;
  87.         this.nome = nome;
  88.     }
  89.    
  90.     public void print(){
  91.         System.out.printf("%s\t%s\n",nome,coord_gps);    
  92.     }
  93. }
  94.  
  95. abstract class Parques extends Locais{
  96.  
  97.     public Parques(String coord_gps, String nome) {
  98.         super(coord_gps, nome);
  99.     }
  100. }
  101.  
  102. class Jardins extends Parques{
  103.     private int area; //em metros quadrados
  104.  
  105.     public Jardins(String coord_gps, String nome,int area) {
  106.         super(coord_gps, nome);
  107.         this.area = area;
  108.     }
  109. }
  110.  
  111. class Areas_desportivas extends Parques{
  112.     private String desportos[];
  113.  
  114.     public Areas_desportivas(String coord_gps, String nome,String desportos[]) {
  115.         super(coord_gps, nome);
  116.         this.desportos = desportos;
  117.     }
  118.    
  119.     @Override
  120.     public void print(){
  121.         System.out.printf("%s\n",nome);
  122.         for (int i = 0; i < desportos.length; i++){
  123.             System.out.printf("%s", desportos[i]);
  124.         }
  125.     }
  126. }
  127.  
  128. class Exposicoes extends Locais{
  129.     public String forma_artistica;
  130.     public int custo_ingresso;
  131.  
  132.     public Exposicoes(String coord_gps,String nome,String forma_artistica, int custo_ingresso) {
  133.         super(coord_gps, nome);
  134.         this.custo_ingresso = custo_ingresso;
  135.         this.forma_artistica = forma_artistica;
  136.     }
  137. }
  138.  
  139. class Bares extends Locais{
  140.        
  141.     private int lotacao;  
  142.     private int consumo_minimo; //Por pessoa
  143.    
  144.     public List<Elemento_dei> guest = new ArrayList<>();
  145.  
  146.     public Bares(String coord_gps,String nome, int lotacao, int consumo_minimo) {
  147.         super(coord_gps, nome);
  148.         this.lotacao = lotacao;
  149.         this.consumo_minimo = consumo_minimo;
  150.     }
  151.    
  152.     public void add_guest(){ //Fazer, meter num array e meter num ficheiro de obj
  153.        
  154.     }
  155. }
  156.  
  157. /*----------------------------ELEMENTOS DEI-----------------------------------------*/
  158. class Elemento_dei implements Serializable{
  159.     public String perfil;
  160.     public String nome;
  161.     public int idade;
  162.    
  163.     public Elemento_dei(String perfil, String nome,int idade){
  164.         this.perfil = perfil;
  165.         this.nome = nome;
  166.         this.idade = idade;
  167.     }
  168.    
  169.     public void print(){
  170.         System.out.printf("%s\t%d\t%s\n", nome,idade,perfil);
  171.     }
  172.    
  173. }
  174.  
  175. class Inscrito extends Elemento_dei{ //NOVO
  176.     public String username;
  177.     public String password;
  178.  
  179.     public Inscrito(String perfil, String nome, int idade, String username,String password) {
  180.         super(perfil, nome, idade);
  181.         this.username = username;
  182.         this.password = password;
  183.     }  
  184. }
  185.  
  186. class Estudante extends Elemento_dei{
  187.     private String curso;
  188.  
  189.     public Estudante(String perfil, String nome,int idade,String curso) {
  190.         super(perfil, nome, idade);
  191.         this.curso = curso;
  192.     }
  193.    
  194.     @Override
  195.     public String toString(){
  196.         return nome + perfil + idade;
  197.     }
  198. }
  199.  
  200. class Professor extends Elemento_dei{
  201.     private String tipo_prof;
  202.  
  203.     public Professor(String perfil, String nome, int idade, String tipo_prof) {
  204.         super(perfil, nome, idade);
  205.         this.tipo_prof = tipo_prof;
  206.     }
  207.    
  208.     @Override
  209.     public String toString(){
  210.         return nome;
  211.     }
  212. }
  213.  
  214. class Funcionario extends Elemento_dei{
  215.     private String tipo_func;
  216.  
  217.     public Funcionario(String perfil, String nome, int idade, String tipo_func) {
  218.         super(perfil, nome, idade);
  219.         this.tipo_func = tipo_func;
  220.     }
  221.    
  222.     @Override
  223.     public String toString(){
  224.         return nome;
  225.     }
  226. }
  227.  
  228. /*---------------------------------FICHEIROS-----------------------------------------*/
  229. class Ficheiros_Locais{
  230.    
  231.     public void ler_ficheiro_locais(){
  232.         List<Locais> locais = new ArrayList<>();
  233.         try{
  234.             BufferedReader reader = new BufferedReader(new FileReader("Locais.txt"));
  235.             String line;
  236.             while ((line = reader.readLine()) != null){
  237.                 String nome;
  238.                 int receita;
  239.                 String coordenadas;
  240.                 String tipo_local;
  241.                 String[] info = line.split("\t");
  242.                 nome = info[0];
  243.                 coordenadas = info[1];
  244.                 tipo_local = info[2];
  245.                 if(tipo_local.indexOf("parque") >= 0){
  246.                     String tipo_parque = info[3];
  247.                     if(tipo_parque.indexOf("jardim") >= 0){
  248.                         int area = Integer.valueOf(info[4].trim());
  249.                         Locais l = new Jardins(coordenadas,nome,area);
  250.                         locais.add(l);
  251.                     }
  252.                     else if(tipo_parque.indexOf("desportivo") >= 0){
  253.                         String desportos[] = new String[info.length - 4];
  254.                         int n = 0;
  255.                         for (int i = 4; i < info.length ; i++){ //Ver como se faz para meter varios desportos
  256.                            desportos[n] = info[i];
  257.                            n++;
  258.                         }
  259.                         Locais l = new Areas_desportivas(coordenadas,nome,desportos);
  260.                         locais.add(l);
  261.                     }
  262.                 }
  263.                 else if(tipo_local.indexOf("bar") >= 0){
  264.                     int lotacao = Integer.valueOf(info[3].trim());
  265.                     int consumo_minimo = Integer.valueOf(info[4].trim());
  266.                     Locais l = new Bares(coordenadas,nome,lotacao,consumo_minimo);
  267.                     locais.add(l);
  268.                 }
  269.                 else if(tipo_local.indexOf("exposicao") >= 0){
  270.                     int custo_ingresso = Integer.valueOf(info[3].trim());
  271.                     String forma_artistica = info[4];
  272.                     Locais l = new Exposicoes(coordenadas,nome,forma_artistica,custo_ingresso);
  273.                     locais.add(l);
  274.                 }
  275.        
  276.         }
  277.         }catch(IOException e){
  278.             System.out.print("ERRO");
  279.             System.out.printf("Ocorreu a exceçao %s ao ler o ficheiro\n", e);
  280.         }
  281.         escreve_ficheiro_dat_locais(locais);
  282.        
  283.     }
  284.     public void escreve_ficheiro_dat_locais(List<Locais> locais){
  285.          try{
  286.             ObjectOutputStream oS = new ObjectOutputStream(new FileOutputStream("Locais_obj.txt"));
  287.             oS.writeObject(locais);
  288.             oS.close();
  289.  
  290.         }catch(IOException e){
  291.             System.out.print("ERRO");
  292.             System.out.printf("Ocorreu a exceçao %s ao escrever no ficheiro\n", e);
  293.         }
  294.     }
  295. }
  296.  
  297. class Ficheiros_Elementos_dei{
  298.    
  299.    
  300.     public void ler_ficheiro_Elementos_dei(){
  301.         List<Elemento_dei> elementos_dei = new ArrayList<>(); //Ver se meter isto aqui esta correto
  302.         try{
  303.             BufferedReader reader = new BufferedReader(new FileReader("Elementos_DEI.txt"));
  304.             String line;
  305.             while ((line = reader.readLine()) != null){
  306.                 String nome;
  307.                 String perfil;
  308.                 int idade;
  309.                 String profissao;
  310.                 String[] info = line.split("\t");
  311.                 nome = info[0];
  312.                 perfil = info[1];
  313.                 idade = Integer.valueOf(info[2].trim());
  314.                 profissao = info[3];
  315.                 if(profissao.indexOf("aluno") >= 0){
  316.                     String curso = info[4];
  317.                     Elemento_dei e = new Estudante(perfil,nome,idade,curso);
  318.                     elementos_dei.add(e);
  319.                    
  320.                 }
  321.                 else if(profissao.indexOf("professor") >= 0){
  322.                     String tipo_prof = info[4];
  323.                     Elemento_dei e = new Professor(perfil, nome,idade,tipo_prof);
  324.                     elementos_dei.add(e);
  325.                    
  326.                 }
  327.                 else if(profissao.indexOf("funcionario") >= 0){
  328.                     String tipo_func = info[4];
  329.                     Elemento_dei e = new Funcionario(perfil,nome,idade, tipo_func);
  330.                     elementos_dei.add(e);
  331.                    
  332.                 }
  333.                 else{
  334.                     System.out.print("ERRO\n");
  335.                 }
  336.             }
  337.         }
  338.         catch(IOException e){
  339.             System.out.printf("Ocorreu a exceçao %s ao ler o ficheiro\n", e);
  340.         }
  341.        
  342.         escreve_ficheiro_dat_pessoas(elementos_dei);
  343.     }
  344.     public void escreve_ficheiro_dat_pessoas(List<Elemento_dei> inscritos){
  345.          try{
  346.             ObjectOutputStream oS = new ObjectOutputStream(new FileOutputStream("Pessoas_obj.txt"));
  347.             oS.writeObject(inscritos);
  348.             oS.close();
  349.  
  350.         }catch(IOException e){
  351.             System.out.printf("Ocorreu a exceçao %s ao escrever mo ficheiro\n", e);
  352.         }
  353.     } //Ver como fazer para ir atualizando
  354. }
  355.  
  356. /*----------------------------------------------------INTERFACE-------------------------------------------------------*/
  357.  
  358.  
  359. ////////////////////////////////////////////MENU////////////////////////////////////////////
  360.  
  361. class MenuInicial extends JFrame{ //O que por no registar? (opcoes)
  362.    
  363.     private final JLabel welcome; //Texto a dar as boas vindas
  364.     private final JButton botLogin;
  365.     private final JButton botRegistar;
  366.     private final JButton botSair;
  367.    
  368.     public MenuInicial(){
  369.         this.setPreferredSize (new Dimension(450,300));
  370.         this.setTitle("Menu Inicial");
  371.         this.setLocation (600,300); //Mais ou menos centrado
  372.         this.setVisible(true);
  373.         this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
  374.         this.setLayout (new GridLayout (4,2,20,20));
  375.    
  376.         welcome = new JLabel ("                                          Bem vindo ao Mega Convivio do DEI");
  377.         this.add (welcome);
  378.        
  379.         botLogin = new JButton("Login");
  380.         this.add(botLogin);
  381.         botLogin.addActionListener(new ActionListener() {
  382.         @Override
  383.         public void actionPerformed(ActionEvent e) {
  384.             Login Interface = new Login();
  385.             dispose();
  386.         }
  387.     });
  388.        
  389.         botRegistar = new JButton("Registar");
  390.         this.add(botRegistar);
  391.         botRegistar.addActionListener(new ActionListener() {
  392.         @Override
  393.         public void actionPerformed(ActionEvent e) {
  394.             Registar r = new Registar();
  395.             dispose();
  396.         }
  397.     });
  398.        
  399.         botSair = new JButton("Sair");
  400.         this.add(botSair);
  401.         botSair.addActionListener(new ActionListener() {
  402.         @Override
  403.         public void actionPerformed(ActionEvent e) {
  404.             System.exit(0);
  405.         }
  406.     });
  407.        
  408.         this.pack();
  409.     }
  410. }
  411.  
  412. ///////////////////////////////////////////REGISTAR////////////////////////////////////
  413.  
  414. class Registar extends JFrame{
  415.    
  416.     private final JTextField nome;
  417.     private final JTextField username;
  418.     private final JPasswordField password;
  419.     private final JPasswordField confirmapass;
  420.    
  421.     private final JComboBox showpass;
  422.    
  423.     private final JLabel label0;
  424.     private final JLabel label1;
  425.     private final JLabel label2;
  426.     private final JLabel label3;
  427.  
  428.    
  429.     private final JButton botEntrar; //Para fazer login
  430.     private final JButton botLimpa; //Decidir se limpa tudo ou apenas um dos campos
  431.     private final JButton botSai;
  432.     private final JButton botRetroceder;
  433.  
  434.  
  435.     public Registar() {
  436.         this.setPreferredSize (new Dimension(600,450));
  437.         this.setTitle("Registar");
  438.         this.setLocation (600,300); //Mais ou menos centrado
  439.         this.setVisible(true);
  440.         this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
  441.         //this.setLayout(new FlowLayout());
  442.  
  443.  
  444.         //final JPanel grid = new JPanel(new FlowLayout());    
  445.         this.setLayout (new GridLayout (7,2,15,15));
  446.         //this.add(grid);
  447.  
  448.  
  449.         label0 = new JLabel ("Nome");
  450.         this.add (label0);
  451.  
  452.         nome = new JTextField();
  453.         this.add(nome);
  454.         nome.setPreferredSize (new Dimension(100,20));
  455.         nome.addActionListener (new ActionListener() {
  456.             @Override
  457.             public void actionPerformed(ActionEvent e) {
  458.                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  459.             }
  460.         }); //Mudar o método abstrato
  461.  
  462.         label1 = new JLabel ("Escolher Username");
  463.         this.add (label1);
  464.  
  465.         username = new JTextField();
  466.         this.add(username);
  467.         username.setPreferredSize (new Dimension(100,20));
  468.         username.addActionListener (new ActionListener() {
  469.             @Override
  470.             public void actionPerformed(ActionEvent e) {
  471.                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  472.             }
  473.         }); //Mudar o método abstrato
  474.  
  475.  
  476.         label2 = new JLabel ("Escolher Password");
  477.         this.add (label2);
  478.  
  479.         password = new JPasswordField(); //cria novo objeto
  480.         this.add(password); //adiciona ao container  
  481.         password.setPreferredSize (new Dimension(100,20));
  482.         password.addActionListener (new ActionListener() {
  483.             @Override
  484.             public void actionPerformed(ActionEvent e) {              
  485.  
  486.                 password.setToolTipText("A password tem que ter pelo menos 5 carateres");
  487.  
  488.             }
  489.         }); //Mudar o método abstrato
  490.  
  491.  
  492.         label3 = new JLabel ("Confirmar Password");
  493.         this.add (label3);
  494.  
  495.         confirmapass = new JPasswordField();
  496.         this.add(confirmapass);
  497.         confirmapass.setPreferredSize (new Dimension(100,20));
  498.         confirmapass.addActionListener (new ActionListener() {
  499.             @Override
  500.             public void actionPerformed(ActionEvent e) {
  501.  
  502.                 if ((password.getPassword()).equals(confirmapass)){
  503.  
  504.                 }
  505.                 else{
  506.                     System.out.println("As passwords tem que ser iguais");
  507.                 }
  508.             }
  509.         }); //Mudar o método abstrato
  510.  
  511.         //SHOW PASSWORDDDDDDDDDDDDDDDD
  512.  
  513.         //char[] pass = password.getPassword();
  514.         //String pass = new String(password.getPassword());
  515.         char[] correctpass = {'b','a','t','a','t','a'};
  516.         //String correctpass = "batata";
  517.  
  518.         botEntrar = new JButton("Registar");
  519.         this.add(botEntrar);
  520.         botEntrar.addActionListener(new ActionListener() {
  521.             @Override
  522.             public void actionPerformed(ActionEvent e) {
  523.                 username.getText();
  524.                 password.getPassword();
  525.                 confirmapass.getPassword();
  526.  
  527.                 if (Arrays.equals(password.getPassword(),confirmapass.getPassword())) {
  528.                     System.out.println("Registo bem sucedido");
  529.                     Login escolhe = new Login();
  530.                     dispose();
  531.                 } else {
  532.                     JOptionPane.showMessageDialog(rootPane, "As passwords têm que ser iguais", "Erro", JOptionPane.ERROR_MESSAGE);
  533.                 }
  534.  
  535.  
  536.             }
  537.         });
  538.         //Dentro do metodo abstrato, verificar se o username esta nos registados
  539.         //e se a password corresponde a password desse username
  540.         //Se sim, login successful Se nao, erro
  541.  
  542.  
  543.         botLimpa = new JButton("Limpa");
  544.             this.add(botLimpa);
  545.             botLimpa.addActionListener(new ActionListener() {
  546.                 @Override
  547.                 public void actionPerformed(ActionEvent e) {
  548.                         username.setText("");
  549.                         password.setText("");
  550.                 }
  551.             });
  552.  
  553.  
  554.         botSai = new JButton ("Sai");
  555.             this.add(botSai);
  556.             botSai.addActionListener(new ActionListener() {
  557.                 @Override
  558.                 public void actionPerformed(ActionEvent e) {
  559.                     System.exit(0);
  560.             }
  561.             });            
  562.  
  563.  
  564.         botRetroceder = new JButton ("Retroceder");
  565.             this.add(botRetroceder);
  566.             botRetroceder.addActionListener(new ActionListener() {
  567.                 @Override
  568.                 public void actionPerformed(ActionEvent e) {
  569.                     MenuInicial m = new MenuInicial();
  570.                     dispose();
  571.             }
  572.             });
  573.  
  574.  
  575.         JFrame self = this;
  576.  
  577.         String [] opcao = new String []{"Mostrar Password","Esconder Password"};
  578.        // JComboBox<String> oplist = new JComboBox<>(opcao);
  579.  
  580.  
  581.         showpass = new JComboBox (opcao);
  582.         showpass.addActionListener(new ActionListener(){
  583.             @Override
  584.             public void actionPerformed(ActionEvent event) {
  585.                 JComboBox <String> oplist = (JComboBox<String>)event.getSource();
  586.                 String opcao = (String) oplist.getSelectedItem();
  587.  
  588.                 if (opcao.equals("Mostrar Password")){
  589.                     password.setEchoChar((char)0);
  590.                     confirmapass.setEchoChar((char)0);
  591.                 }
  592.                 else{
  593.                     password.setEchoChar('•');
  594.                     confirmapass.setEchoChar('•');
  595.                 }
  596.  
  597.  
  598.  
  599.             }
  600.         });
  601.         this.add(showpass);
  602.  
  603.  
  604.  
  605.         this.pack();
  606.         }
  607.     }
  608.  
  609. ///////////////////////////////////////LOGIN//////////////////////////////////////////////
  610.  
  611. class Login extends JFrame{
  612.    
  613.     private final JTextField username;
  614.     //private final JTextField password;
  615.    
  616.     private final JPasswordField password;
  617.    
  618.     private final JComboBox showpass;
  619.    
  620.     private final JLabel label1;
  621.     private final JLabel label2;
  622.    
  623.     private final JButton botEntrar; //Para fazer login
  624.     private final JButton botLimpa; //Decidir se limpa tudo ou apenas um dos campos
  625.     private final JButton botSai;
  626.     private final JButton botRetroceder;
  627.  
  628.     public Login() {
  629.         this.setPreferredSize (new Dimension(600,450));
  630.         this.setTitle("Login");
  631.         this.setLocation (600,300); //Mais ou menos centrado
  632.         this.setVisible(true);
  633.         this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
  634.         //this.setLayout(new FlowLayout());
  635.  
  636.  
  637.         //final JPanel grid = new JPanel(new FlowLayout());    
  638.         this.setLayout (new GridLayout (7,2,15,15));
  639.         //this.add(grid);
  640.  
  641.  
  642.         label1 = new JLabel ("Username");
  643.         this.add (label1);
  644.         username = new JTextField();
  645.         this.add(username);
  646.         username.setPreferredSize (new Dimension(100,20));
  647.         username.addActionListener (new ActionListener() {
  648.             @Override
  649.             public void actionPerformed(ActionEvent e) {
  650.                 throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  651.             }
  652.         }); //Mudar o método abstrato
  653.  
  654.  
  655.         label2 = new JLabel ("Password");
  656.         this.add (label2);
  657.         password = new JPasswordField(); //cria novo objeto
  658.  
  659.         //password.setEchoChar((char)0);
  660.         //password = new JTextField();
  661.         this.add(password); //adiciona ao container  
  662.         password.setPreferredSize (new Dimension(100,20));
  663.         password.addActionListener (new ActionListener() {
  664.             @Override
  665.             public void actionPerformed(ActionEvent e) {              
  666.  
  667.                 password.setToolTipText("A password tem que ter pelo menos 5 carateres");
  668.  
  669.             }
  670.         }); //Mudar o método abstrato    
  671.  
  672.         //char[] pass = password.getPassword();
  673.         //String pass = new String(password.getPassword());
  674.         char[] correctpass = {'b','a','t','a','t','a'};
  675.         //String correctpass = "batata";
  676.  
  677.         botEntrar = new JButton("Entrar");
  678.         this.add(botEntrar);
  679.         botEntrar.addActionListener(new ActionListener() {
  680.             @Override
  681.             public void actionPerformed(ActionEvent e) {
  682.                 username.getText();
  683.                 password.getPassword();
  684.  
  685.  
  686.             if(Arrays.equals(password.getPassword(), correctpass)){
  687.                 System.out.println("Password correta");
  688.                 dispose();
  689.                 MenuEscolha escolhe = new MenuEscolha();
  690.             } else {
  691.                 System.out.println ("Password incorreta");
  692.                 }
  693.  
  694.  
  695.             }
  696.         });
  697.         //Dentro do metodo abstrato, verificar se o username esta nos registados
  698.         //e se a password corresponde a password desse username
  699.         //Se sim, login successful Se nao, erro
  700.  
  701.  
  702.         botLimpa = new JButton("Limpa");
  703.             this.add(botLimpa);
  704.             botLimpa.addActionListener(new ActionListener() {
  705.                 @Override
  706.                 public void actionPerformed(ActionEvent e) {
  707.                         username.setText("");
  708.                         password.setText("");
  709.                 }
  710.             });
  711.  
  712.         botSai = new JButton ("Sai");
  713.             this.add(botSai);
  714.             botSai.addActionListener(new ActionListener() {
  715.                 @Override
  716.                 public void actionPerformed(ActionEvent e) {
  717.                     System.exit(0);
  718.             }
  719.             });
  720.  
  721.         botRetroceder = new JButton ("Retroceder");
  722.             this.add(botRetroceder);
  723.             botRetroceder.addActionListener(new ActionListener() {
  724.                 @Override
  725.                 public void actionPerformed(ActionEvent e) {
  726.                     MenuInicial m = new MenuInicial();
  727.                     //this.dispose();  //Remove JFrame 1
  728.                     //JFrame2.setVisible(true) //Show other frame
  729.                     dispose();
  730.                 }
  731.             });
  732.  
  733.  
  734.         JFrame self = this;
  735.  
  736.          String [] opcao = new String []{"Mostrar Password","Esconder Password"};
  737.        // JComboBox<String> oplist = new JComboBox<>(opcao);
  738.  
  739.         showpass = new JComboBox (opcao);
  740.         showpass.addActionListener(new ActionListener(){
  741.             @Override
  742.             public void actionPerformed(ActionEvent event) {
  743.                 JComboBox <String> oplist = (JComboBox<String>)event.getSource();
  744.                 String opcao = (String) oplist.getSelectedItem();
  745.  
  746.                 if (opcao.equals("Mostrar Password")){
  747.                     password.setEchoChar((char)0);
  748.                 }
  749.                 else{
  750.                     password.setEchoChar('•');
  751.                 }
  752.             }
  753.         });
  754.         this.add(showpass);
  755.  
  756.         this.pack();
  757.         }
  758. }
  759.  
  760. //////////////////////////////////MOSTRAR LOCAIS///////////////////////////////////////////
  761.  
  762. class MenuEscolha extends JFrame{
  763.        
  764.         private final JButton botEscolheLocal;
  765.         private final JButton botShowGuest;
  766.         private final JButton botReceitaMin;
  767.         private final JButton botRetroceder;
  768.        
  769.         public MenuEscolha(){
  770.             this.setPreferredSize (new Dimension(500,400));
  771.             this.setTitle("Menu Escolha");
  772.             this.setLocation (600,300); //Mais ou menos centrado
  773.             this.setVisible(true);
  774.             this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
  775.             this.setLayout(new GridLayout (5,1,30,30));
  776.        
  777.             botEscolheLocal = new JButton ("Mostra locais");
  778.             this.add(botEscolheLocal);
  779.            
  780.             botShowGuest = new JButton ("Mostra Guest Lists");
  781.             this.add(botShowGuest);
  782.            
  783.             botReceitaMin = new JButton ("Receita Minima Prevista");
  784.             this.add(botReceitaMin);
  785.            
  786.             botRetroceder = new JButton ("Retroceder");
  787.             this.add(botRetroceder);
  788.             botRetroceder.addActionListener(new ActionListener() {
  789.             @Override
  790.             public void actionPerformed(ActionEvent e) {
  791.                 Login Interface = new Login();
  792.                 dispose();
  793.             }
  794.         });  
  795.            
  796.         JFrame self = this;
  797.    
  798.         this.pack();
  799.         }      
  800.     }
  801.  
  802. ///////////////////////////////////////MOSTRA LOCAIS//////////////////////////////////////////////
  803.  
  804. class MostraLocais{
  805.    
  806.     private final JLabel label1;
  807.    
  808.    
  809.     public MostraLocais(){
  810.         List<Locais> locais = new ArrayList<>();
  811.         try(ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Locais_obj.txt"))){
  812.             locais = (ArrayList) oin.readObject();
  813.         }catch(IOException | ClassNotFoundException e){
  814.             System.out.println(e.getMessage());
  815.         }
  816.        
  817.        
  818.        
  819.        
  820.        
  821.         }
  822.    
  823.     this.pack();
  824. }
  825.  
  826. /*--------------------------------------MAIN----------------------------------------------*/
  827.  
  828. public class projeto_rascunho {
  829.    
  830.     public static void main(String[] args) {
  831.        
  832.         /*INICIALIZAR*/
  833.         Convivio c = new Convivio("Mega Convivio");
  834.        
  835.         Ficheiros_Elementos_dei a = new Ficheiros_Elementos_dei();
  836.         a.ler_ficheiro_Elementos_dei();
  837.         Ficheiros_Locais l = new Ficheiros_Locais();
  838.         l.ler_ficheiro_locais();
  839.        
  840.         /*INTERFACE*/
  841.         MenuInicial m = new MenuInicial();
  842.        
  843.        
  844.        
  845.        
  846.     }  
  847.    
  848. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement