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 static java.util.Collections.swap;
- import java.util.Iterator;
- 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,String tipo){
- 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,tipo);
- 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 int add_guest(Inscrito i,Bares b){
- int maximo_guest = (int)(b.lotacao * 0.1);
- int n = 0;
- String nome = null;
- if (b.guest.size() == maximo_guest){
- if (i.perfil.indexOf("Boemio") >= 0){
- for (Inscrito ins : b.guest){
- if (ins.perfil.indexOf("Boemio") < 0){ //ver o nome do ultimo a entrar que nao seja "boemio" e se há
- nome = ins.nome;
- }
- else{ //Nao pode ser inscrito
- n = 0;
- }
- }
- Iterator <Inscrito> iterator = b.guest.iterator();
- while (iterator.hasNext()){
- Inscrito ins = iterator.next();{
- if (nome.indexOf(ins.nome) >= 0){ //verifcar se nome != null para pode ser realizada a troca
- int x = 0;
- for (Inscrito inscrito : b.guest){
- if(!inscrito.nome.equals(i.nome)){
- x += 0;
- }
- }
- if(x == b.guest.size()){
- iterator.remove(); //Remove o ultimo inscrito que nao e "boemio"
- b.guest.add(i); //Adiciona o inscrito que e "boemio"
- n = 1;
- }
- else n = 0;
- }
- else{ //Nao pode ser inscrito
- n = 0;
- }
- }
- }
- }
- else{ //Nao pode ser inscrito
- n = 0;
- }
- }
- else{ //Pode ser inscrito
- int x = 0;
- for (Inscrito inscrito : b.guest){
- if(!inscrito.nome.equals(i.nome)){
- x += 1;
- }
- }
- if(x == b.guest.size()){
- b.guest.add(i);
- n = 1;
- }
- else n = 0;
- }
- return n;
- }
- public int conta_inscritos(String nome_local){
- int num_inscritos = 0;
- 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());
- }
- for (Inscrito i : inscritos){
- for (Locais l : i.locais){
- if(l.nome.indexOf(nome_local) >= 0){
- num_inscritos += 1;
- }
- }
- }
- return num_inscritos;
- }
- public int receita_minima_prevista_total(Convivio c){
- int receita = 0;
- 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){
- receita += l.receita_prevista(c);
- }
- return receita;
- }
- }
- /*----------------------------LOCAIS CONVIVIO-----------------------------------------*/
- class Locais implements Serializable{
- private String coord_gps;
- public String nome;
- public String tipo_local;
- public Locais(String coord_gps,String nome,String tipo_local){
- this.coord_gps = coord_gps;
- this.nome = nome;
- this.tipo_local = tipo_local;
- }
- public int receita_prevista(Convivio c){
- return 0;
- }
- public void print(){
- System.out.printf("%s\n",nome);
- }
- }
- abstract class Parques extends Locais{
- public Parques(String coord_gps, String nome,String tipo_local) {
- super(coord_gps, nome,tipo_local);
- }
- }
- class Jardins extends Parques{
- private int area; //em metros quadrados
- public Jardins(String coord_gps, String nome,int area,String tipo_local) {
- super(coord_gps, nome,tipo_local);
- this.area = area;
- }
- @Override
- public int receita_prevista(Convivio c){
- return 0;
- }
- @Override
- public void print(){
- System.out.printf("%s\n",nome);
- }
- }
- class Areas_desportivas extends Parques{
- private String desportos[];
- public Areas_desportivas(String coord_gps, String nome,String desportos[],String tipo_local) {
- super(coord_gps, nome,tipo_local);
- 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]);
- }
- }
- @Override
- public int receita_prevista(Convivio c){
- 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,String tipo_local) {
- super(coord_gps, nome,tipo_local);
- this.custo_ingresso = custo_ingresso;
- this.forma_artistica = forma_artistica;
- }
- @Override
- public int receita_prevista(Convivio c){
- int receita = 0;
- 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());
- }
- for (Inscrito i : inscritos){
- for (Locais loc : i.locais){
- if (nome.indexOf(loc.nome) >= 0 && i.tipo.indexOf("aluno") >= 0){
- receita += (custo_ingresso * 0.90);
- }
- else if(nome.indexOf(loc.nome) >= 0 && i.tipo.indexOf("aluno") < 0){
- receita += custo_ingresso;
- }
- }
- }
- return receita;
- }
- @Override
- public void print(){
- System.out.printf("%s\n",nome);
- }
- }
- class Bares extends Locais{
- public 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, String tipo_local,List<Inscrito> guest) {
- super(coord_gps, nome,tipo_local);
- this.lotacao = lotacao;
- this.consumo_minimo = consumo_minimo;
- this.guest = guest;
- }
- @Override
- public int receita_prevista(Convivio c){
- int n_inscritos;
- n_inscritos = c.conta_inscritos(nome);
- return consumo_minimo * n_inscritos;
- }
- @Override
- public void print(){
- System.out.printf("%s com lotacao:%d\n",nome,lotacao);
- }
- }
- /*----------------------------ELEMENTOS DEI-----------------------------------------*/
- class Elemento_dei implements Serializable{
- public String perfil;
- public String nome;
- public int idade;
- public String tipo;
- public Elemento_dei(String perfil, String nome,int idade,String tipo){
- this.perfil = perfil;
- this.nome = nome;
- this.idade = idade;
- this.tipo = tipo;
- }
- public void print(){
- System.out.printf("%s\t%d\n", nome,idade);
- }
- }
- 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,String tipo) {
- super(perfil, nome, idade,tipo);
- 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,String tipo) {
- super(perfil, nome, idade,tipo);
- this.curso = curso;
- this.tipo = tipo;
- }
- @Override
- public void print(){
- System.out.printf("%s\t%s\t%s\n", nome,perfil,curso);
- }
- }
- class Professor extends Elemento_dei{
- private String tipo_prof;
- public Professor(String perfil, String nome, int idade, String tipo_prof,String tipo) {
- super(perfil, nome, idade,tipo);
- this.tipo_prof = tipo_prof;
- }
- @Override
- public void print(){
- System.out.printf("%s\t%s\n", nome,perfil);
- }
- }
- class Funcionario extends Elemento_dei{
- private String tipo_func;
- public Funcionario(String perfil, String nome, int idade, String tipo_func,String tipo) {
- super(perfil, nome, idade,tipo);
- this.tipo_func = tipo_func;
- }
- @Override
- public void print(){
- System.out.printf("%s\t%s\n", nome,perfil);
- }
- }
- /*---------------------------------FICHEIROS-----------------------------------------*/
- class Ficheiros_Locais{
- public void ler_ficheiro_locais(){
- List<Locais> locais = new ArrayList<>();
- List<Bares> bares = 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,tipo_parque);
- 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,tipo_parque);
- locais.add(l);
- }
- }
- else if(tipo_local.indexOf("bar") >= 0){
- List<Inscrito> guest = new ArrayList<>();
- int lotacao = Integer.valueOf(info[3].trim());
- int consumo_minimo = Integer.valueOf(info[4].trim());
- Locais l = new Bares(coordenadas,nome,lotacao,consumo_minimo,tipo_local,guest);
- locais.add(l);
- Bares b = new Bares(coordenadas,nome,lotacao,consumo_minimo,tipo_local,guest);
- bares.add(b);
- }
- 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,tipo_local);
- 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);
- escreve_ficheiro_dat_locais_bares(bares);
- }
- 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);
- }
- }
- public void escreve_ficheiro_dat_locais_bares(List<Bares> bares){
- try{
- ObjectOutputStream oS = new ObjectOutputStream(new FileOutputStream("Bares_obj.txt"));
- oS.writeObject(bares);
- 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,profissao);
- 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,profissao);
- 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,profissao);
- 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);
- }
- }
- }
- /*----------------------------------------------------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(Convivio c){
- 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", SwingConstants.CENTER);
- this.add (welcome);
- botLogin = new JButton("Login");
- this.add(botLogin);
- botLogin.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Login Interface = new Login(c);
- dispose();
- }
- });
- botRegistar = new JButton("Registar");
- this.add(botRegistar);
- botRegistar.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Registar r = new Registar(c);
- 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) {
- 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
- 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;
- String tipo = null;
- 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;
- tipo = el.tipo;
- }
- }
- }
- if(n == 1){
- JOptionPane.showMessageDialog(rootPane, "Username ja escolhido ou ja esta inscrito no convivio", "Erro", JOptionPane.ERROR_MESSAGE);
- Registar r = new Registar(c);
- dispose();
- }
- else if (n == 0){
- JOptionPane.showMessageDialog(rootPane, "Nome nao consta na base de dados!", "Erro", JOptionPane.ERROR_MESSAGE);
- Registar r = new Registar(c);
- dispose();
- }
- else if (y == inscritos.size()){//Se nao houver nenhum igual
- List<Locais> locais = new ArrayList<>();
- System.out.println(tipo);
- c.inscricao_convivio(nome1,username.getText(),password1,perfil,idade,locais,tipo);
- JOptionPane.showMessageDialog(rootPane, "Registo bem sucedido!", ":)", JOptionPane.INFORMATION_MESSAGE);
- Login escolhe = new Login(c);
- 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(c);
- 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(Convivio c) {
- 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 GridLayout (7,2,15,15));
- 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
- 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
- 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<>();
- String tipo = null;
- int n = 0;
- for (Inscrito i : inscritos){
- if(!username.getText().equals(""))
- 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;
- tipo = i.tipo;
- break;
- }
- else{
- n = 0;
- }
- else{
- n = 0;
- }
- }
- if(n == 1){
- dispose();
- Inscrito i = new Inscrito(perfil,nome,idade,username1,password1,locais,tipo);
- MenuEscolha escolhe = new MenuEscolha(i,c);
- }
- else {
- JOptionPane.showMessageDialog(rootPane, "Password ou username errados!", "Erro", JOptionPane.ERROR_MESSAGE);
- dispose();
- Login l = new Login(c);
- }
- }
- });
- //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(c);
- //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, Convivio c){
- 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,c);
- dispose();
- }
- });
- botShowGuest = new JButton ("Guest Lists");
- this.add(botShowGuest);
- botShowGuest.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Guests g = new Guests(i,c);
- dispose();
- }
- });
- botReceitaMin = new JButton ("Receita Minima Prevista");
- this.add(botReceitaMin);
- botReceitaMin.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- MostraReceita m = new MostraReceita(i,c);
- dispose();
- }
- });
- botRetroceder = new JButton ("Retroceder");
- this.add(botRetroceder);
- botRetroceder.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Login Interface = new Login(c);
- 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,Convivio c){
- 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,c);
- dispose();
- }
- });
- botRetroceder = new JButton ("Retroceder");
- this.add(botRetroceder);
- botRetroceder.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- MenuEscolha s = new MenuEscolha(i,c);
- 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());
- }
- List <Integer> n_inscritos = new ArrayList<>();
- for (Locais l : locais){
- n_inscritos.add(c.conta_inscritos(l.nome));
- }
- System.out.println(n_inscritos);
- for(int out = n_inscritos.size()-1; out>1; out--) {
- for(int j = 0; j < out;j ++){
- int n = j+1;
- if(n_inscritos.get(j) <= n_inscritos.get(n)) {
- int temp = n_inscritos.get(j);
- n_inscritos.set(j, n_inscritos.get(n));
- n_inscritos.set(n, temp);
- }
- }
- }
- System.out.println(n_inscritos);
- int q;
- Iterator <Integer> iterator = n_inscritos.iterator();
- while (iterator.hasNext()){
- Integer integ = iterator.next();
- Iterator <Locais> it = locais.iterator();
- while (iterator.hasNext()){
- Locais l = it.next();
- if(c.conta_inscritos(l.nome) == integ){
- box.append(l.nome + " com " + c.conta_inscritos(l.nome) + " inscrito(s)." );
- box.append("\n\n");
- it.remove();
- break;
- }
- }
- }
- System.out.println(n_inscritos);
- 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 JTextArea box_ins;
- 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;
- private static final int SPACE = 3;
- String escolha1 = null;
- String escolha2 = null;
- String escolha3 = null;
- String escolha4 = null;
- String escolha5 = null;
- public EscolheLocais(Inscrito i, Convivio c){
- 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,SPACE, SPACE)); //Ver ao certo para que serve
- 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());
- }
- box_ins = new JTextArea (5,5);
- box_ins.setEditable(false);
- label1 = new JLabel ("Local 1");
- local1 = new JComboBox ();
- local1.addItem("");
- for (Locais l : locais){
- local1.addItem(l.nome);
- }
- local1.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent event) {
- //JComboBox <String> oplist = (JComboBox<String>)event.getSource();
- escolha1 = (String) local1.getSelectedItem();
- }
- });
- label2 = new JLabel ("Local 2");
- local2 = new JComboBox ();
- local2.addItem("");
- for (Locais l : locais){
- local2.addItem(l.nome);
- }
- local2.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent event) {
- //JComboBox <String> oplist = (JComboBox<String>)event.getSource();
- escolha2 = (String) local2.getSelectedItem();
- }
- });
- label3 = new JLabel ("Local 3");
- local3 = new JComboBox ();
- local3.addItem("");
- for (Locais l : locais){
- local3.addItem(l.nome);
- }
- local3.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent event) {
- //JComboBox <String> oplist = (JComboBox<String>)event.getSource();
- escolha3 = (String) local3.getSelectedItem();
- }
- });
- label4 = new JLabel ("Local 4");
- local4 = new JComboBox ();
- local4.addItem("");
- for (Locais l : locais){
- local4.addItem(l.nome);
- }
- local4.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent event) {
- //JComboBox <String> oplist = (JComboBox<String>)event.getSource();
- escolha4 = (String) local4.getSelectedItem();
- }
- });
- label5 = new JLabel ("Local 5");
- local5 = new JComboBox ();
- local5.addItem("");
- for (Locais l : locais){
- local5.addItem(l.nome);
- }
- local5.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent event) {
- //JComboBox <String> oplist = (JComboBox<String>)event.getSource();
- escolha5 = (String) local5.getSelectedItem();
- }
- });
- for(Locais l : i.locais){
- box_ins.append(l.nome + '\n');
- }
- botGuardar = new JButton ("Guardar");
- this.add(botGuardar);
- botGuardar.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent event) {
- 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());
- }
- /************************Adicionar locais*******************************/
- box_ins.setText(null);
- List<Locais> locais_novos = new ArrayList<>();
- List<Locais> locais_velhos = new ArrayList<>();
- 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());
- }
- /**************Local 1************/
- for (Locais l : locais){
- if (l.nome.equals(escolha1)){
- if (!locais_novos.contains(l)){
- locais_novos.add(l);
- box_ins.append(escolha1 + '\n');
- }
- }
- }
- /**************Local 2************/
- for (Locais l : locais){
- if (l.nome.equals(escolha2)){
- if (!locais_novos.contains(l)){
- locais_novos.add(l);
- box_ins.append(escolha2 + '\n');
- }
- }
- }
- /************Local 3**************/
- for (Locais l : locais){
- if (l.nome.equals(escolha3)){
- if (!locais_novos.contains(l)){
- locais_novos.add(l);
- box_ins.append(escolha3 + '\n');
- }
- }
- }
- /************Local 4**************/
- for (Locais l : locais){
- if (l.nome.equals(escolha4)){
- if (!locais_novos.contains(l)){
- locais_novos.add(l);
- box_ins.append(escolha4 + '\n');
- }
- }
- }
- /************Local 5**************/
- for (Locais l : locais){
- if (l.nome.equals(escolha5)){
- if (!locais_novos.contains(l)){
- locais_novos.add(l);
- box_ins.append(escolha5 + '\n');
- }
- }
- }
- /****************Gravar locais***************/
- for (Inscrito ins : inscritos){
- if(ins.nome.equals(i.nome)){
- ins.locais = locais_novos;
- locais_velhos = i.locais;
- i.locais = locais_novos;
- }
- }
- Ficheiros_Elementos_dei f = new Ficheiros_Elementos_dei();
- f.escreve_ficheiro_dat_inscritos(inscritos);
- /************************Verificar Guests*******************************/
- List<Bares> bares = new ArrayList<>();
- try(ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Bares_obj.txt"))){
- bares = (ArrayList) oin.readObject();
- }catch(IOException | ClassNotFoundException x){
- System.out.println(x.getMessage());
- }
- int x = 0;
- for(Locais loc : locais_velhos){
- if(loc.tipo_local.equals("bar")){
- for(Bares b : bares){
- if(b.nome.equals(loc.nome)){
- x = 0;
- for(Locais locai : locais_novos){
- if(!locai.nome.equals(b.nome)){
- x += 1;
- }
- }
- if(x == locais_novos.size()){
- Iterator <Inscrito> iterator = b.guest.iterator();
- while (iterator.hasNext()){
- Inscrito ins = iterator.next();
- if(ins.nome.equals(i.nome)){
- iterator.remove();
- //System.out.println(b.guest);
- }
- }
- }
- }
- }
- }
- }
- Ficheiros_Locais a = new Ficheiros_Locais();
- a.escreve_ficheiro_dat_locais_bares(bares);
- }
- });
- botRetroceder = new JButton ("Retroceder");
- this.add(botRetroceder);
- botRetroceder.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- MostraLocais m = new MostraLocais(i,c);
- dispose();
- }
- });
- //JPanel
- JPanel textAreaGrid = new JPanel(new GridLayout(1,0, SPACE, SPACE));
- JScrollPane scroll = new JScrollPane (box_ins,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
- textAreaGrid.add (scroll);
- JPanel buttonPanel = new JPanel (new GridLayout(2,0, SPACE, SPACE));
- buttonPanel.add(botGuardar);
- buttonPanel.add(botRetroceder);
- JPanel locPanel = new JPanel (new GridLayout (5, 0, SPACE, SPACE));
- locPanel.add(label1);
- locPanel.add(local1);
- locPanel.add(label2);
- locPanel.add(local2);
- locPanel.add(label3);
- locPanel.add(local3);
- locPanel.add(label4);
- locPanel.add(local4);
- locPanel.add(label5);
- locPanel.add(local5);
- this.add(locPanel, BorderLayout.PAGE_START);
- this.add(textAreaGrid, BorderLayout.CENTER);
- this.add(buttonPanel, BorderLayout.PAGE_END);
- this.pack();
- }
- }
- /////////////////////////////////////GUESTS////////////////////////////////////////////////
- class Guests extends JFrame{
- private final JTextArea box;
- private final JButton botInscreve_Guest;
- private final JButton botRetroceder;
- private static final int SPACE = 3;
- public Guests(Inscrito i,Convivio c){
- this.setTitle("Menu");
- this.setPreferredSize (new Dimension(600, 450));
- this.setDefaultCloseOperation(EXIT_ON_CLOSE);
- this.setLocation(600,300);
- this.setVisible(true);
- box = new JTextArea (20,20);
- box.setEditable(false);
- this.add(box);
- botInscreve_Guest = new JButton ("Inscreve Guest");
- this.add(botInscreve_Guest);
- botInscreve_Guest.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Inscreve_Guest g = new Inscreve_Guest(i,c);
- dispose();
- }
- });
- botRetroceder = new JButton ("Retroceder");
- this.add(botRetroceder);
- botRetroceder.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- MenuEscolha s = new MenuEscolha(i,c);
- dispose();
- }
- });
- 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(botInscreve_Guest);
- 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);
- box.setText(null);
- List<Bares> bares = new ArrayList<>();
- try(ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Bares_obj.txt"))){
- bares = (ArrayList) oin.readObject();
- }catch(IOException | ClassNotFoundException e){
- System.out.println(e.getMessage());
- }
- box.setText(null);
- for (Bares l : bares){
- box.append("\n" + l.nome + ":\n");
- for (Inscrito insc : l.guest){
- box.append("\t-" + insc.nome + "-->" + insc.perfil + "\n");
- }
- }
- box.append("\n\n");
- this.pack();
- }
- }
- ///////////////////////////INSCREVE GUEST///////////////////////////////////////////////
- class Inscreve_Guest extends JFrame{
- private final JButton botRetroceder;
- private final JButton botInscrever;
- private final JLabel titulo;
- private final JLabel labelbar;
- private final JTextField nomebar;
- private static final int SPACE = 3;
- public Inscreve_Guest(Inscrito i, Convivio c){
- this.setPreferredSize (new Dimension(400,250));
- this.setTitle("Inscrição no Bar");
- this.setLocation (600,300); //Mais ou menos centrado
- this.setVisible(true);
- this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
- this.setLayout (new GridLayout (5,2,10,10));
- titulo = new JLabel ("Escolha o bar pretendido", SwingConstants.CENTER);
- this.add (titulo);
- labelbar = new JLabel ("Nome do Bar: ");
- //this.add (labelbar);
- nomebar = new JTextField();
- //this.add(nomebar);
- nomebar.setPreferredSize (new Dimension(5,10));
- nomebar.addActionListener (new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- //Guardar nome do bar numa variável
- }
- }); //Mudar o método abstrato
- JPanel panel = new JPanel(new BorderLayout());
- panel.add(labelbar,BorderLayout.WEST);
- panel.add(nomebar,BorderLayout.CENTER);
- this.add(panel);
- botInscrever = new JButton ("Inscrever");
- this.add(botInscrever);
- botInscrever.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- List<Bares> bares = new ArrayList<>();
- try(ObjectInputStream oin = new ObjectInputStream(new FileInputStream("Bares_obj.txt"))){
- bares = (ArrayList) oin.readObject();
- }catch(IOException | ClassNotFoundException x){
- System.out.println(x.getMessage());
- }
- int v = 0; //Verifica se esta inscrito no bar
- for (Locais loc : i.locais){
- if(loc.nome.equals(nomebar.getText())){
- v += 1;
- for (Bares l : bares){
- if(l.nome.equals(nomebar.getText())){
- v += 1;
- int n = c.add_guest(i,l);
- Ficheiros_Locais a = new Ficheiros_Locais();
- a.escreve_ficheiro_dat_locais_bares(bares);
- if (n == 0){
- JOptionPane.showMessageDialog(rootPane, "ERRO1!", "Erro", JOptionPane.ERROR_MESSAGE);
- }
- else{
- JOptionPane.showMessageDialog(rootPane, "Inscricao na guest efetuada com sucesso!", ":)", JOptionPane.INFORMATION_MESSAGE);
- }
- }
- }
- }
- }
- if(v == 1){
- JOptionPane.showMessageDialog(rootPane, "ERRO2!", "Erro", JOptionPane.ERROR_MESSAGE);
- }
- if(v == 0){
- JOptionPane.showMessageDialog(rootPane, "ERRO3!", "Erro", JOptionPane.ERROR_MESSAGE);
- }
- Guests g = new Guests(i,c);
- dispose();
- }
- });
- botRetroceder = new JButton ("Retroceder");
- this.add(botRetroceder);
- botRetroceder.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- Guests g = new Guests(i,c);
- dispose();
- }
- });
- this.pack();
- }
- }
- ///////////////////////////////////////MOSTRA RECEITA//////////////////////////////////////////////
- class MostraReceita extends JFrame{
- private final JTextArea box;
- private final JTextArea boxtotal;
- private final JButton botRetroceder;
- private static final int SPACE = 3;
- public MostraReceita(Inscrito i,Convivio c){
- this.setTitle("Menu");
- this.setPreferredSize (new Dimension(600, 450));
- this.setDefaultCloseOperation(EXIT_ON_CLOSE);
- this.setLocation(600,300);
- this.setVisible(true);
- box = new JTextArea (20,20);
- box.setEditable(false);
- boxtotal = new JTextArea (5,20);
- boxtotal.setEditable(false);
- botRetroceder = new JButton ("Retroceder");
- botRetroceder.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- MenuEscolha s = new MenuEscolha(i,c);
- dispose();
- }
- });
- JScrollPane scroll = new JScrollPane (box,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
- this.setLayout(new BorderLayout(SPACE, SPACE));
- this.add(boxtotal, BorderLayout.CENTER);
- this.add(scroll, BorderLayout.PAGE_START);
- this.add(botRetroceder, BorderLayout.PAGE_END);
- 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){ //Ver da lotacao e da ordenacao
- box.append(l.nome + " com receita prevista de " + l.receita_prevista(c) + " euros.");
- box.append("\n\n");
- }
- boxtotal.append("Receita total prevista de " + c.receita_minima_prevista_total(c) + " euros.");
- 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(); //APAGAR ESTA MERDA POR FAVOR
- /*INTERFACE*/
- MenuInicial m = new MenuInicial(c);
- 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