Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package projeto_rascunho;
- import java.awt.BorderLayout;
- import java.util.Random;
- import java.util.Scanner;
- import java.lang.Math;
- import java.util.StringTokenizer;
- import java.util.List;
- import java.util.ListIterator;
- import java.util.ArrayList;
- import java.io.*;
- import java.lang.Math;
- import java.util.StringTokenizer;
- //Para a interface
- 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.*;
- /**Classe principal do programa
- * @author João Perdigão e Rodrigo Oliveira
- * @version 1.0
- * @since Release 17/12/2017
- */
- /*----------------------------CONVIVIO NO DEI----------------------------------------*/
- class Convivio {
- /**
- * classe de criação do convivio
- */
- public String nome_convivio;
- //public List<Locais> locais = new ArrayList<>();
- //public List<Elemento_dei> registados = new ArrayList<>();
- public Convivio(String nome_convivio){
- this.nome_convivio = nome_convivio;
- }
- /**
- * Por enquanto ainda nao serve para nada
- *
- */
- public void login(){
- } //Pedir username e password
- public void inscricao_convivio(String nome, String username,String password,String perfil,int idade,List<Locais> locais){
- List<Inscrito> inscritos = new ArrayList<>();
- try(ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Inscritos_obj.txt"))){
- inscritos = (ArrayList) oin.readObject();
- }catch(IOException | ClassNotFoundException e){
- System.out.println(e.getMessage());
- }
- Inscrito x = new Inscrito(perfil, nome, idade,username,password,locais);
- inscritos.add(x);
- Ficheiros_Elementos_dei f = new Ficheiros_Elementos_dei();
- f.escreve_ficheiro_dat_inscritos(inscritos);
- } //Tem que pedir sempre o nome para verificar se pertence ao DEI //Verificar sempre se ha username igual
- public void show_locais(){ //Mostrar sempre depois da inscricao, ver numero atual de inscritos de cada um e a lotacao (se aplicavel)
- List<Locais> locais = new ArrayList<>();
- try(ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Locais_obj.txt"))){
- locais = (ArrayList) oin.readObject();
- }catch(IOException | ClassNotFoundException e){
- System.out.println(e.getMessage());
- }
- for (Locais l : locais){
- l.print();
- }
- }
- public void escolha_locais(){
- } //Na interface so ter 5 espacos //Ter um ficheiro objetos dos inscritos em cada local (secalhar)
- public void show_guests(){ //Nao sei se mete aqui ou se se mete na class locais
- } //Ficheiro objetos para cada guest de cada bar
- /*public double receita(){ //Nao interessa o que esta ca dentro por enquanto
- List<Locais> locais = new ArrayList<>();
- double receita = 0;
- for (Locais l: locais){
- double receita_local = 0;
- receita += l.receita;
- }
- return receita;
- }*/
- }
- /*----------------------------LOCAIS CONVIVIO-----------------------------------------*/
- class Locais implements Serializable{
- private String coord_gps;
- public String nome;
- public List<Inscrito> inscritos = new ArrayList<>(); //provavelmente para tirar
- public Locais(String coord_gps,String nome){
- this.coord_gps = coord_gps;
- this.nome = nome;
- }
- public void print(){
- System.out.printf("%s\t%s\n",nome,coord_gps);
- }
- }
- abstract class Parques extends Locais{
- public Parques(String coord_gps, String nome) {
- super(coord_gps, nome);
- }
- }
- class Jardins extends Parques{
- private int area; //em metros quadrados
- public Jardins(String coord_gps, String nome,int area) {
- super(coord_gps, nome);
- this.area = area;
- }
- public int receita_prevista(List<Inscrito> inscritos){
- return 0;
- }
- public String info(){
- return "";
- }
- }
- class Areas_desportivas extends Parques{
- private String desportos[];
- public Areas_desportivas(String coord_gps, String nome,String desportos[]) {
- super(coord_gps, nome);
- this.desportos = desportos;
- }
- @Override
- public void print(){
- System.out.printf("%s\n",nome);
- for (int i = 0; i < desportos.length; i++){
- System.out.printf("%s", desportos[i]);
- }
- }
- public int receita_prevista(List<Inscrito> inscritos){
- return 0;
- }
- }
- class Exposicoes extends Locais{
- public String forma_artistica;
- public int custo_ingresso;
- public Exposicoes(String coord_gps,String nome,String forma_artistica, int custo_ingresso) {
- super(coord_gps, nome);
- this.custo_ingresso = custo_ingresso;
- this.forma_artistica = forma_artistica;
- }
- public int receita_prevista(List<Inscrito> inscritos){
- int receita = 0;
- for (Inscrito i : inscritos){
- if (i.perfil.indexOf("Aluno") >= 0){
- receita += custo_ingresso * 0.9; //Os 10% de desconto para alunos
- }
- else{
- receita += custo_ingresso;
- }
- }
- return receita;
- }
- }
- class Bares extends Locais{
- private int lotacao;
- private int consumo_minimo; //Por pessoa
- public List<Inscrito> guest = new ArrayList<>();
- public Bares(String coord_gps,String nome, int lotacao, int consumo_minimo) {
- super(coord_gps, nome);
- this.lotacao = lotacao;
- this.consumo_minimo = consumo_minimo;
- }
- public void add_guest(Inscrito i,List<Inscrito> guest){
- int maximo_guest = (int)(lotacao * 0.3);
- if (guest.size() == maximo_guest){
- if (i.perfil.indexOf("Boemio") >= 0){
- for (Inscrito ins : inscritos){
- }
- }
- }
- else{
- inscritos.add(i);
- }
- Ficheiros_Elementos_dei f = new Ficheiros_Elementos_dei();
- f.escreve_ficheiro_dat_inscritos(inscritos);
- }
- public int receita_prevista(List<Inscrito> inscritos){
- return consumo_minimo*inscritos.size();
- }
- }
- /*----------------------------ELEMENTOS DEI-----------------------------------------*/
- class Elemento_dei implements Serializable{
- public String perfil;
- public String nome;
- public int idade;
- public Elemento_dei(String perfil, String nome,int idade){
- this.perfil = perfil;
- this.nome = nome;
- this.idade = idade;
- }
- public void print(){
- System.out.printf("%s\t%d\t%s\n", nome,idade,perfil);
- }
- }
- class Inscrito extends Elemento_dei{
- public String username;
- public String password;
- public List<Locais> locais = new ArrayList<>(); //Maximo de 5 locais
- public Inscrito(String perfil, String nome, int idade, String username,String password,List<Locais> locais) {
- super(perfil, nome, idade);
- this.username = username;
- this.password = password;
- this.locais = locais;
- }
- @Override
- public void print(){
- System.out.printf("%s\t%s\t%s\t%s\t%s\n", nome,perfil,idade,username,password);
- }
- }
- class Estudante extends Elemento_dei{
- private String curso;
- public Estudante(String perfil, String nome,int idade,String curso) {
- super(perfil, nome, idade);
- this.curso = curso;
- }
- @Override
- public String toString(){
- return nome + perfil + idade;
- }
- }
- class Professor extends Elemento_dei{
- private String tipo_prof;
- public Professor(String perfil, String nome, int idade, String tipo_prof) {
- super(perfil, nome, idade);
- this.tipo_prof = tipo_prof;
- }
- @Override
- public String toString(){
- return nome;
- }
- }
- class Funcionario extends Elemento_dei{
- private String tipo_func;
- public Funcionario(String perfil, String nome, int idade, String tipo_func) {
- super(perfil, nome, idade);
- this.tipo_func = tipo_func;
- }
- @Override
- public String toString(){
- return nome;
- }
- }
- /*---------------------------------FICHEIROS-----------------------------------------*/
- class Ficheiros_Locais{
- public void ler_ficheiro_locais(){
- List<Locais> locais = new ArrayList<>();
- try{
- BufferedReader reader = new BufferedReader(new FileReader("Locais.txt"));
- String line;
- while ((line = reader.readLine()) != null){
- String nome;
- String coordenadas;
- String tipo_local;
- String[] info = line.split("\t");
- nome = info[0];
- coordenadas = info[1];
- tipo_local = info[2];
- if(tipo_local.indexOf("parque") >= 0){
- String tipo_parque = info[3];
- if(tipo_parque.indexOf("jardim") >= 0){
- int area = Integer.valueOf(info[4].trim());
- Locais l = new Jardins(coordenadas,nome,area);
- locais.add(l);
- }
- else if(tipo_parque.indexOf("desportivo") >= 0){
- String desportos[] = new String[info.length - 4];
- int n = 0;
- for (int i = 4; i < info.length ; i++){
- desportos[n] = info[i];
- n++;
- }
- Locais l = new Areas_desportivas(coordenadas,nome,desportos);
- locais.add(l);
- }
- }
- else if(tipo_local.indexOf("bar") >= 0){
- int lotacao = Integer.valueOf(info[3].trim());
- int consumo_minimo = Integer.valueOf(info[4].trim());
- Locais l = new Bares(coordenadas,nome,lotacao,consumo_minimo);
- locais.add(l);
- }
- else if(tipo_local.indexOf("exposicao") >= 0){
- int custo_ingresso = Integer.valueOf(info[3].trim());
- String forma_artistica = info[4];
- Locais l = new Exposicoes(coordenadas,nome,forma_artistica,custo_ingresso);
- locais.add(l);
- }
- }
- }catch(IOException e){
- System.out.print("ERRO");
- System.out.printf("Ocorreu a exceçao %s ao ler o ficheiro\n", e);
- }
- escreve_ficheiro_dat_locais(locais);
- }
- public void escreve_ficheiro_dat_locais(List<Locais> locais){
- try{
- ObjectOutputStream oS = new ObjectOutputStream(new FileOutputStream("Locais_obj.txt"));
- oS.writeObject(locais);
- oS.close();
- }catch(IOException e){
- System.out.print("ERRO");
- System.out.printf("Ocorreu a exceçao %s ao escrever no ficheiro\n", e);
- }
- }
- }
- class Ficheiros_Elementos_dei{
- public void ler_ficheiro_Elementos_dei(){
- List<Elemento_dei> elementos_dei = new ArrayList<>(); //Ver se meter isto aqui esta correto
- try{
- BufferedReader reader = new BufferedReader(new FileReader("Elementos_DEI.txt"));
- String line;
- while ((line = reader.readLine()) != null){
- String nome;
- String perfil;
- int idade;
- String profissao;
- String[] info = line.split(";");
- nome = info[0];
- perfil = info[1];
- idade = Integer.valueOf(info[2].trim());
- profissao = info[3];
- if(profissao.indexOf("aluno") >= 0){
- String curso = info[4];
- Elemento_dei e = new Estudante(perfil,nome,idade,curso);
- elementos_dei.add(e);
- }
- else if(profissao.indexOf("professor") >= 0){
- String tipo_prof = info[4];
- Elemento_dei e = new Professor(perfil, nome,idade,tipo_prof);
- elementos_dei.add(e);
- }
- else if(profissao.indexOf("funcionario") >= 0){
- String tipo_func = info[4];
- Elemento_dei e = new Funcionario(perfil,nome,idade, tipo_func);
- elementos_dei.add(e);
- }
- else{
- System.out.print("ERRO\n");
- }
- }
- }
- catch(IOException e){
- System.out.printf("Ocorreu a exceçao %s ao ler o ficheiro\n", e);
- }
- escreve_ficheiro_dat_pessoas(elementos_dei);
- }
- public void escreve_ficheiro_dat_pessoas(List<Elemento_dei> pessoas){
- try{
- ObjectOutputStream oS = new ObjectOutputStream(new FileOutputStream("Pessoas_obj.txt"));
- oS.writeObject(pessoas);
- oS.close();
- }catch(IOException e){
- System.out.printf("Ocorreu a exceçao %s ao escrever mo ficheiro\n", e);
- }
- } //Ver como fazer para ir atualizando
- public void escreve_ficheiro_dat_inscritos(List<Inscrito> inscritos){
- try{
- ObjectOutputStream oS = new ObjectOutputStream(new FileOutputStream("Inscritos_obj.txt"));
- oS.writeObject(inscritos);
- oS.close();
- }catch(IOException e){
- System.out.printf("Ocorreu a exceçao %s ao escrever mo ficheiro\n", e);
- }
- } //Ver como fazer para ir atualizando
- }
- /*----------------------------------------------------INTERFACE-------------------------------------------------------*/
- ////////////////////////////////////////////MENU////////////////////////////////////////////
- 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 String nome1;
- public String username1;
- public String password1;
- public Registar() {
- Convivio c = new Convivio("Mega Convivio");
- 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) {
- nome1 = nome.getText();
- }
- }); //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) {
- username1 = username.getText();
- }
- }); //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";
- //REGISTO
- botEntrar = new JButton("Registar");
- this.add(botEntrar);
- botEntrar.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- username.getText();
- password.getPassword();
- confirmapass.getPassword();
- String pass = "";
- List<Elemento_dei> pessoas = new ArrayList<>();
- try(ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Pessoas_obj.txt"))){
- pessoas = (ArrayList) oin.readObject();
- }catch(IOException | ClassNotFoundException n){
- System.out.println(n.getMessage());
- }
- List<Inscrito> inscritos = new ArrayList<>();
- try(ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Inscritos_obj.txt"))){
- inscritos = (ArrayList) oin.readObject();
- }catch(IOException | ClassNotFoundException n){
- System.out.println(n.getMessage());
- }
- int n = 0;
- String perfil = null;
- int idade = 0;
- String nome1 = null;
- int y = 0;
- if (Arrays.equals(password.getPassword(),confirmapass.getPassword())) {
- char [] pass_char = password.getPassword();
- for (int i = 0; i < pass_char.length ; i++){
- pass += pass_char[i];
- }
- password1 = pass;
- for (Elemento_dei el : pessoas){
- if ((nome.getText().indexOf(el.nome)) >= 0){
- n = 1;
- y = 0;
- for (Inscrito i : inscritos){
- if(!username.getText().toUpperCase().equals(i.username.toUpperCase()) && !nome.getText().toUpperCase().equals(i.nome.toUpperCase())){
- y += 1;
- }
- else{
- n = 1;
- break;
- }
- }
- if (y == inscritos.size()){ //Se nao houver nenhum igual
- n = 2;
- perfil = el.perfil;
- nome1 = el.nome;
- idade = el.idade;
- }
- }
- }
- if(n == 1){
- JOptionPane.showMessageDialog(rootPane, "Username ja escolhido ou ja esta inscrito no convivio", "Erro", JOptionPane.ERROR_MESSAGE);
- Registar r = new Registar();
- dispose();
- }
- else if (n == 0){
- JOptionPane.showMessageDialog(rootPane, "Nome nao consta na base de dados!", "Erro", JOptionPane.ERROR_MESSAGE);
- Registar r = new Registar();
- dispose();
- }
- else if (y == inscritos.size()){//Se nao houver nenhum igual
- List<Locais> locais = new ArrayList<>();
- c.inscricao_convivio(nome1,username.getText(),password1,perfil,idade,locais);
- JOptionPane.showMessageDialog(rootPane, "Registo bem sucedido!", ":)", JOptionPane.INFORMATION_MESSAGE);
- Login escolhe = new Login();
- 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());
- botEntrar = new JButton("Entrar");
- this.add(botEntrar);
- botEntrar.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- String pass = "";
- List<Inscrito> inscritos = new ArrayList<>();
- try(ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Inscritos_obj.txt"))){
- inscritos = (ArrayList) oin.readObject();
- }catch(IOException | ClassNotFoundException n){
- System.out.println(n.getMessage());
- }
- username.getText();
- password.getPassword();
- char [] pass_char = password.getPassword();
- for (int i = 0; i < pass_char.length ; i++){
- pass += pass_char[i];
- }
- String nome = null;
- int idade = 0;
- String username1 = null;
- String password1 = null;
- String perfil = null;
- List<Locais> locais = new ArrayList<>();
- int n = 0;
- for (Inscrito i : inscritos){
- if(i.username.indexOf(username.getText()) >= 0 && i.password.indexOf(pass) >= 0){
- n = 1;
- nome = i.nome;
- idade = i.idade;
- username1 = i.username;
- password1 = i.password;
- perfil = i.perfil;
- locais = i.locais;
- }
- }
- if(n == 1){
- dispose();
- Inscrito i = new Inscrito(perfil,nome,idade,username1,password1,locais);
- MenuEscolha escolhe = new MenuEscolha(i); //tratar deste i
- } else {
- JOptionPane.showMessageDialog(rootPane, "Password ou username errados!", "Erro", JOptionPane.ERROR_MESSAGE);
- dispose();
- Login l = new Login();
- }
- }
- });
- //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();
- } //Ja feito em principio
- }
- //////////////////////////////////MENU ESCOLHA///////////////////////////////////////////
- class MenuEscolha extends JFrame{
- private final JButton botMostraLocais;
- private final JButton botShowGuest;
- private final JButton botReceitaMin;
- private final JButton botRetroceder;
- public MenuEscolha(Inscrito i){
- this.setPreferredSize (new Dimension(500,400));
- this.setTitle("Menu Escolha");
- 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));
- botMostraLocais = new JButton ("Mostra Locais");
- this.add(botMostraLocais);
- botMostraLocais.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- MostraLocais m = new MostraLocais(i);
- dispose();
- }
- });
- botShowGuest = new JButton ("Mostra 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;
- this.pack();
- }
- }
- ///////////////////////////////////////MOSTRA LOCAIS//////////////////////////////////////////////
- class MostraLocais extends JFrame{
- private final JTextArea box;
- private final JButton botEscolhe;
- private final JButton botRetroceder;
- private static final int SPACE = 3;
- public MostraLocais(Inscrito i){
- this.setTitle("Menu");
- this.setPreferredSize (new Dimension(600, 450));
- this.setDefaultCloseOperation(EXIT_ON_CLOSE);
- this.setLocation(600,300);
- this.setVisible(true);
- //this.setLayout(new GridLayout (4,2,60,60));
- box = new JTextArea (20,20);
- box.setEditable(false);
- this.add(box);
- botEscolhe = new JButton ("Escolher Locais");
- this.add(botEscolhe);
- botEscolhe.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- EscolheLocais esc = new EscolheLocais(i);
- dispose();
- }
- });
- botRetroceder = new JButton ("Retroceder");
- this.add(botRetroceder);
- botRetroceder.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- MenuEscolha s = new MenuEscolha(i);
- dispose();
- }
- });
- //JPanel
- JPanel textAreaGrid = new JPanel(new GridLayout(1, 0, SPACE, SPACE));
- textAreaGrid.add(new JScrollPane(box));
- JPanel buttonPanel = new JPanel(new GridLayout(2, 0, SPACE, SPACE));
- buttonPanel.add(botEscolhe);
- buttonPanel.add(botRetroceder);
- getRootPane().setBorder(BorderFactory.createEmptyBorder(SPACE, SPACE, SPACE, SPACE));
- setLayout(new BorderLayout(SPACE, SPACE));
- add(textAreaGrid, BorderLayout.CENTER);
- add(buttonPanel, BorderLayout.PAGE_END);
- box.add(new JScrollPane(new JTextArea(50, 50)), BorderLayout.PAGE_START);
- JScrollPane scrollPane = new JScrollPane (box);
- JScrollPane scroll = new JScrollPane (box,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
- this.add(scroll);
- this.setVisible (true);
- List<Locais> locais = new ArrayList<>();
- try(ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Locais_obj.txt"))){
- locais = (ArrayList) oin.readObject();
- }catch(IOException | ClassNotFoundException e){
- System.out.println(e.getMessage());
- }
- for (Locais l : locais){
- box.append(l.nome);
- box.append("\n\n");
- }
- this.pack();
- }
- }
- //////////////////////////////////////ESCOLHA LOCAIS//////////////////////////////////////////
- class EscolheLocais extends JFrame{
- private final JComboBox local1;
- private final JComboBox local2;
- private final JComboBox local3;
- private final JComboBox local4;
- private final JComboBox local5;
- private final JLabel label1;
- private final JLabel label2;
- private final JLabel label3;
- private final JLabel label4;
- private final JLabel label5;
- private final JButton botRetroceder;
- private final JButton botGuardar;
- public EscolheLocais(Inscrito i){
- this.setPreferredSize (new Dimension(600,450));
- this.setTitle("Escolhe Locais");
- this.setLocation (600,300); //Mais ou menos centrado
- this.setVisible(true);
- this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
- this.setLayout(new GridLayout (7,2,20,20));
- List<Locais> locais = new ArrayList<>();
- try(ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Locais_obj.txt"))){
- locais = (ArrayList) oin.readObject();
- }catch(IOException | ClassNotFoundException e){
- System.out.println(e.getMessage());
- }
- label1 = new JLabel ("Local 1");
- this.add (label1);
- local1 = new JComboBox ();
- for (Locais l : locais){
- local1.addItem(l.nome);
- }
- this.add(local1);
- label2 = new JLabel ("Local 2");
- this.add (label2);
- local2 = new JComboBox ();
- for (Locais l : locais){
- local2.addItem(l.nome);
- }
- this.add(local2);
- label3 = new JLabel ("Local 3");
- this.add (label3);
- local3 = new JComboBox ();
- for (Locais l : locais){
- local3.addItem(l.nome);
- }
- this.add(local3);
- label4 = new JLabel ("Local 4");
- this.add (label4);
- local4 = new JComboBox ();
- for (Locais l : locais){
- local4.addItem(l.nome);
- }
- this.add(local4);
- label5 = new JLabel ("Local 5");
- this.add (label5);
- local5 = new JComboBox ();
- for (Locais l : locais){
- local5.addItem(l.nome);
- }
- this.add(local5);
- botGuardar = new JButton ("Guardar");
- this.add(botGuardar);
- botRetroceder = new JButton ("Retroceder");
- this.add(botRetroceder);
- botRetroceder.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- MostraLocais m = new MostraLocais(i);
- dispose();
- }
- });
- this.pack();
- }
- }
- /*--------------------------------------MAIN----------------------------------------------*/
- public class projeto_racunho {
- public static void main(String[] args) {
- /*INICIALIZAR*/
- Convivio c = new Convivio("Mega Convivio");
- Ficheiros_Elementos_dei a = new Ficheiros_Elementos_dei();
- a.ler_ficheiro_Elementos_dei();
- Ficheiros_Locais l = new Ficheiros_Locais();
- l.ler_ficheiro_locais();
- /*INTERFACE*/
- MenuInicial m = new MenuInicial();
- List<Inscrito> inscritos = new ArrayList<>();
- try(ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Inscritos_obj.txt"))){
- inscritos = (ArrayList) oin.readObject();
- }catch(IOException | ClassNotFoundException n){
- System.out.println(n.getMessage());
- }
- for (Inscrito i : inscritos){
- i.print();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement