Advertisement
Guest User

PAP

a guest
May 18th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 105.28 KB | None | 0 0
  1. package pap;
  2.  
  3. import java.awt.EventQueue;
  4.  
  5. import javax.swing.JFrame;
  6. import javax.swing.GroupLayout;
  7. import javax.swing.GroupLayout.Alignment;
  8. import javax.swing.JTextPane;
  9. import javax.swing.JLabel;
  10. import javax.swing.JOptionPane;
  11. import javax.swing.JButton;
  12. import java.awt.event.ActionListener;
  13. import java.awt.event.FocusAdapter;
  14. import java.awt.event.FocusEvent;
  15. import java.sql.Array;
  16. import java.sql.Connection;
  17. import java.sql.DriverManager;
  18. import java.sql.PreparedStatement;
  19. import java.sql.ResultSet;
  20. import java.sql.SQLException;
  21. import java.sql.Statement;
  22. import java.text.SimpleDateFormat;
  23. import java.time.LocalDate;
  24. import java.time.format.DateTimeFormatter;
  25. import java.util.Date;
  26. import java.awt.event.ActionEvent;
  27. import javax.swing.LayoutStyle.ComponentPlacement;
  28. import javax.swing.JPanel;
  29. import java.awt.GridLayout;
  30. import java.awt.CardLayout;
  31. import java.awt.Color;
  32.  
  33. import javax.swing.BoxLayout;  
  34. import javax.swing.DefaultComboBoxModel;
  35. import javax.swing.DefaultListModel;
  36.  
  37. import java.awt.GridBagLayout;
  38. import java.awt.GridBagConstraints;
  39. import java.awt.Insets;
  40. import javax.swing.JTextField;
  41. import javax.swing.JRadioButton;
  42. import javax.swing.JPasswordField;
  43. import javax.swing.JComboBox;
  44. import javax.swing.JMenuBar;
  45. import javax.swing.JMenu;
  46. import javax.swing.JMenuItem;
  47. import javax.swing.JList;
  48. import java.awt.Component;
  49. import javax.swing.Box;
  50. import javax.swing.JScrollPane;
  51. import javax.swing.JTable;
  52. import javax.swing.table.DefaultTableModel;
  53.  
  54. public class MedClinic {
  55.     /** Panels */
  56.     private JFrame frame;
  57.     private JPanel panelRegisto;
  58.     private JPanel panelLogin;
  59.     private JPanel panelPerfil;
  60.     private JPanel panelPassword;
  61.     private JPanel panelForgot;
  62.     private JPanel panelMensagem;
  63.     private JPanel panelLer;
  64.    
  65.     /** TextFields */
  66.    
  67.     private JTextField textNome;
  68.     private JTextField textApelido;
  69.     private JTextField textUsername;
  70.     private JTextField textDataNascimento;
  71.     private JTextField textContacto;
  72.     private JTextField textEmail;
  73.     private JTextField textMorada;
  74.     private JTextField textID;
  75.     private JTextField textUsernameLogin;
  76.     private JTextField passwordVelha;
  77.     private JTextField passwordNova;
  78.     private JTextField passwordConfirmar;
  79.     private JTextField textUsernameForgot;
  80.     private JTextField passwordNovaForgot;
  81.     private JTextField passwordConfirmarForgot;
  82.     private JTextField textDestinatario;
  83.     private JTextField textAssunto;
  84.     private JTextField textNomePerfil;
  85.     private JTextField textApelidoPerfil;
  86.     private JTextField textIDPerfil;
  87.     private JTextField textUsernamePerfil;
  88.     private JTextField textDataNascimentoPerfil;
  89.     private JTextField textEmailPerfil;
  90.     private JTextField textContactoPerfil;
  91.     private JTextField textMoradaPerfil;
  92.     private JTextField textTipoSanguePerfil;
  93.     private JTextField textSexoPerfil;
  94.     private JTextField passwordLogin;
  95.     private JTextField passwordRegisto;
  96.     private JTextField textEmailForgot;
  97.     private JTextField textOrigemLer;
  98.     private JTextField textAssuntoLer;
  99.     private JTextField textCategorialer;
  100.     private JTextField textDataLer;
  101.    
  102.     /** TextPanes */
  103.    
  104.     private JTextPane textCorpoLer;
  105.     private JTextPane textCorpo;
  106.    
  107.     /** ComboBoxes */
  108.    
  109.     private JComboBox comboBoxFiltroOrigem;
  110.     private JComboBox comboBoxFiltroCategoria;
  111.     private JComboBox comboBoxDestinatario;
  112.     private JComboBox comboBoxIdentificador;
  113.    
  114.    
  115.     /** Butões do panelPerfil */
  116.    
  117.     private JButton btnEditar;
  118.     private JButton btnGuardar;
  119.    
  120.     /** Menu Items */
  121.     private JMenuItem mntmLogin;
  122.     private JMenuItem mntmRegisto;
  123.     private JMenuItem mntmLogout;
  124.     private JMenuItem mntmCancelar;
  125.     private JMenuItem mntmPerfil;
  126.     private JMenuItem mntmEscrever;
  127.     private JMenuItem mntmInbox;
  128.    
  129. /** Variaveis */
  130.    
  131.     private int idCliente;
  132.     private String currentFilter;
  133.     private String currentEmail;
  134.     private int currentUserID = 0;
  135.    
  136.     /** List Models */
  137.    
  138.     private DefaultTableModel modeloInbox = new DefaultTableModel();
  139.     private JTable tableMensagem;
  140.    
  141.    
  142.    
  143.    
  144.     /** Tabelas */
  145.    
  146.     public void MensagensCliente(){
  147.         modeloInbox.setRowCount(0);
  148.         String query = "SELECT emailID, origem_idCliente, categoria, assunto, data FROM mail_cliente_cliente WHERE destino_idCliente = '" + currentUserID + "'";
  149.         try {
  150.             modeloInbox.setRowCount(0);
  151.             Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
  152.             PreparedStatement inst = lig.prepareStatement(query);
  153.             ResultSet resultado = inst.executeQuery();
  154.             while (resultado.next()) {
  155.                 int id = resultado.getInt("emailID");
  156.                 String nome = "";
  157.                 String apelido = "";
  158.                 String origem = resultado.getString("origem_idCliente");
  159.                 String categoria = resultado.getString("categoria");
  160.                 String assunto = resultado.getString("assunto");
  161.                 String data = resultado.getString("data");
  162.                
  163.                 try {
  164.                     PreparedStatement inst1 = lig.prepareStatement("SELECT nome, apelido FROM cliente WHERE idCliente = '" + origem + "'");
  165.                     ResultSet resultado1 = inst1.executeQuery();
  166.                     while (resultado1.next()) {
  167.                         nome = resultado1.getString("nome");
  168.                         apelido = resultado1.getString("apelido");
  169.                        
  170.                     }
  171.                 } catch (SQLException ex) {
  172.                     JOptionPane.showMessageDialog(null, "BD indísponivel!1" + ex.getMessage());
  173.                 }
  174.                 String nomeApelido = nome + " " + apelido;
  175.                 modeloInbox.addRow(new Object[] {id, nomeApelido, categoria, assunto, data});
  176.             }
  177.             lig.close();
  178.         } catch (SQLException ex) {
  179.             JOptionPane.showMessageDialog(null, "BD indísponivel!" + ex.getMessage());
  180.         }
  181.     }
  182.    
  183.     public void MensagensClienteCategoria(){
  184.         modeloInbox.setRowCount(0);
  185.         String categoria = (String) comboBoxFiltroCategoria.getSelectedItem();
  186.         if(!(categoria == "Todas")) {
  187.             String query = "SELECT emailID, origem_idCliente, categoria, assunto, data FROM mail_cliente_cliente WHERE destino_idCliente = '" + currentUserID + "' AND categoria = '" + categoria + "'";
  188.             try {
  189.                 modeloInbox.setRowCount(0);
  190.                 Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
  191.                 PreparedStatement inst = lig.prepareStatement(query);
  192.                 ResultSet resultado = inst.executeQuery();
  193.                 while (resultado.next()) {
  194.                     int id = resultado.getInt("emailID");
  195.                     String nome = "";
  196.                     String apelido = "";
  197.                     String origem = resultado.getString("origem_idCliente");
  198.                     categoria = resultado.getString("categoria");
  199.                     String assunto = resultado.getString("assunto");
  200.                     String data = resultado.getString("data");
  201.                     try {
  202.                         PreparedStatement inst1 = lig.prepareStatement("SELECT nome, apelido FROM cliente WHERE idCliente = '" + origem + "'");
  203.                         ResultSet resultado1 = inst1.executeQuery();
  204.                         while (resultado1.next()) {
  205.                             nome = resultado1.getString("nome");
  206.                             apelido = resultado1.getString("apelido");
  207.                            
  208.                         }
  209.                     } catch (SQLException ex) {
  210.                         JOptionPane.showMessageDialog(null, "BD indísponivel!1" + ex.getMessage());
  211.                     }
  212.                     String nomeApelido = nome + " " + apelido;
  213.                     modeloInbox.addRow(new Object[] {id, nomeApelido, categoria, assunto, data});
  214.                 }
  215.                 lig.close();
  216.             } catch (SQLException ex) {
  217.                 JOptionPane.showMessageDialog(null, "BD indísponivel!" + ex.getMessage());
  218.             }
  219.         }
  220.         else {
  221.             String query = "SELECT emailID, origem_idCliente, categoria, assunto, data FROM mail_cliente_cliente WHERE destino_idCliente = '" + currentUserID + "'";
  222.             try {
  223.                 modeloInbox.setRowCount(0);
  224.                 Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
  225.                 PreparedStatement inst = lig.prepareStatement(query);
  226.                 ResultSet resultado = inst.executeQuery();
  227.                 while (resultado.next()) {
  228.                     int id = resultado.getInt("emailID");
  229.                     String nome = "";
  230.                     String apelido = "";
  231.                     String origem = resultado.getString("origem_idCliente");
  232.                     categoria = resultado.getString("categoria");
  233.                     String assunto = resultado.getString("assunto");
  234.                     String data = resultado.getString("data");
  235.                     try {
  236.                         PreparedStatement inst1 = lig.prepareStatement("SELECT nome, apelido FROM cliente WHERE idCliente = '" + origem + "'");
  237.                         ResultSet resultado1 = inst1.executeQuery();
  238.                         while (resultado1.next()) {
  239.                             nome = resultado1.getString("nome");
  240.                             apelido = resultado1.getString("apelido");
  241.                            
  242.                         }
  243.                     } catch (SQLException ex) {
  244.                         JOptionPane.showMessageDialog(null, "BD indísponivel!1" + ex.getMessage());
  245.                     }
  246.                     String nomeApelido = nome + " " + apelido; 
  247.                     modeloInbox.addRow(new Object[] {id, nomeApelido, categoria, assunto, data});
  248.                 }
  249.                 lig.close();
  250.             } catch (SQLException ex) {
  251.                 JOptionPane.showMessageDialog(null, "BD indísponivel!" + ex.getMessage());
  252.             }
  253.         }
  254.     }
  255.    
  256.    
  257.     /** Setup do Perfil */
  258.     public void perfilSetup() {
  259.         try {
  260.             Connection ligPerfil = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
  261.             Statement instPerfil = ligPerfil.createStatement();
  262.             ResultSet resultadoPerfil = instPerfil
  263.                     .executeQuery("SELECT *  FROM cliente where idCliente = '" + currentUserID + "'");
  264.             while (resultadoPerfil.next()) {
  265.                 //preencher os campos do perfil com os dados da base de dados respetivos ao username
  266.                 textIDPerfil.setText(resultadoPerfil.getString("idCliente"));
  267.                 textNomePerfil.setText(resultadoPerfil.getString("nome"));
  268.                 textApelidoPerfil.setText(resultadoPerfil.getString("apelido"));
  269.                 textUsernamePerfil.setText(resultadoPerfil.getString("username"));
  270.                 textDataNascimentoPerfil.setText(resultadoPerfil.getString("dataNascimento"));
  271.                 textTipoSanguePerfil.setText(resultadoPerfil.getString("tipoSangue"));
  272.                 textSexoPerfil.setText(resultadoPerfil.getString("sexo"));
  273.                 textContactoPerfil.setText(resultadoPerfil.getString("contacto"));
  274.                 textEmailPerfil.setText(resultadoPerfil.getString("email"));
  275.                 textMoradaPerfil.setText(resultadoPerfil.getString("morada"));
  276.                
  277.             }
  278.             ligPerfil.close();
  279.         } catch (SQLException ex) {
  280.             JOptionPane.showMessageDialog(null, "BD indísponivel! | " +ex.getMessage());
  281.         }
  282.     }
  283.    
  284.     /**
  285.      * Launch the application.
  286.      */
  287.     public static void main(String[] args) {
  288.         EventQueue.invokeLater(new Runnable() {
  289.             public void run() {
  290.                 try {
  291.                     MedClinic window = new MedClinic();
  292.                     window.frame.setVisible(true);
  293.                 } catch (Exception e) {
  294.                     e.printStackTrace();
  295.                 }
  296.             }
  297.         });
  298.     }
  299.  
  300.     /**
  301.      * Create the application.
  302.      */
  303.     public MedClinic() {
  304.         initialize();
  305.         mntmPerfil.setEnabled(false);
  306.         mntmLogout.setEnabled(false);
  307.         textEmail.setText("Tudo em minúsculas");
  308.         textEmail.setForeground(Color.GRAY);
  309.         textDataNascimento.setText("AAAA-MM-DD");
  310.         textDataNascimento.setForeground(Color.GRAY);
  311.         textEmailForgot.setText("Tudo em minúsculas");
  312.         textEmailForgot.setForeground(Color.GRAY);
  313.        
  314.         panelLer = new JPanel();
  315.         frame.getContentPane().add(panelLer, "name_298078073230023");
  316.         GridBagLayout gbl_panelLer = new GridBagLayout();
  317.         gbl_panelLer.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
  318.         gbl_panelLer.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
  319.         gbl_panelLer.columnWeights = new double[]{0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
  320.         gbl_panelLer.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
  321.         panelLer.setLayout(gbl_panelLer);
  322.        
  323.         JLabel label = new JLabel("Mensagem");
  324.         GridBagConstraints gbc_label = new GridBagConstraints();
  325.         gbc_label.gridwidth = 6;
  326.         gbc_label.insets = new Insets(0, 0, 5, 5);
  327.         gbc_label.gridx = 1;
  328.         gbc_label.gridy = 0;
  329.         panelLer.add(label, gbc_label);
  330.        
  331.         JLabel labelOrigem = new JLabel("Origem:");
  332.         GridBagConstraints gbc_labelOrigem = new GridBagConstraints();
  333.         gbc_labelOrigem.anchor = GridBagConstraints.EAST;
  334.         gbc_labelOrigem.insets = new Insets(0, 0, 5, 5);
  335.         gbc_labelOrigem.gridx = 1;
  336.         gbc_labelOrigem.gridy = 1;
  337.         panelLer.add(labelOrigem, gbc_labelOrigem);
  338.        
  339.         textOrigemLer = new JTextField();
  340.         textOrigemLer.setBackground(Color.WHITE);
  341.         textOrigemLer.setEditable(false);
  342.         textOrigemLer.setColumns(10);
  343.         GridBagConstraints gbc_textOrigemLer = new GridBagConstraints();
  344.         gbc_textOrigemLer.fill = GridBagConstraints.HORIZONTAL;
  345.         gbc_textOrigemLer.insets = new Insets(0, 0, 5, 5);
  346.         gbc_textOrigemLer.gridx = 2;
  347.         gbc_textOrigemLer.gridy = 1;
  348.         panelLer.add(textOrigemLer, gbc_textOrigemLer);
  349.        
  350.         JLabel lblCategoria = new JLabel("Categoria");
  351.         GridBagConstraints gbc_lblCategoria = new GridBagConstraints();
  352.         gbc_lblCategoria.anchor = GridBagConstraints.EAST;
  353.         gbc_lblCategoria.insets = new Insets(0, 0, 5, 5);
  354.         gbc_lblCategoria.gridx = 1;
  355.         gbc_lblCategoria.gridy = 2;
  356.         panelLer.add(lblCategoria, gbc_lblCategoria);
  357.        
  358.         textCategorialer = new JTextField();
  359.         textCategorialer.setBackground(Color.WHITE);
  360.         textCategorialer.setEditable(false);
  361.         GridBagConstraints gbc_textCategorialer = new GridBagConstraints();
  362.         gbc_textCategorialer.insets = new Insets(0, 0, 5, 5);
  363.         gbc_textCategorialer.fill = GridBagConstraints.HORIZONTAL;
  364.         gbc_textCategorialer.gridx = 2;
  365.         gbc_textCategorialer.gridy = 2;
  366.         panelLer.add(textCategorialer, gbc_textCategorialer);
  367.         textCategorialer.setColumns(10);
  368.        
  369.         Component horizontalStrut_2 = Box.createHorizontalStrut(20);
  370.         GridBagConstraints gbc_horizontalStrut_2 = new GridBagConstraints();
  371.         gbc_horizontalStrut_2.insets = new Insets(0, 0, 5, 5);
  372.         gbc_horizontalStrut_2.gridx = 3;
  373.         gbc_horizontalStrut_2.gridy = 2;
  374.         panelLer.add(horizontalStrut_2, gbc_horizontalStrut_2);
  375.        
  376.         JLabel lblData = new JLabel("Data:");
  377.         GridBagConstraints gbc_lblData = new GridBagConstraints();
  378.         gbc_lblData.anchor = GridBagConstraints.EAST;
  379.         gbc_lblData.insets = new Insets(0, 0, 5, 5);
  380.         gbc_lblData.gridx = 4;
  381.         gbc_lblData.gridy = 2;
  382.         panelLer.add(lblData, gbc_lblData);
  383.        
  384.         textDataLer = new JTextField();
  385.         textDataLer.setBackground(Color.WHITE);
  386.         textDataLer.setEditable(false);
  387.         GridBagConstraints gbc_textDataLer = new GridBagConstraints();
  388.         gbc_textDataLer.gridwidth = 2;
  389.         gbc_textDataLer.insets = new Insets(0, 0, 5, 5);
  390.         gbc_textDataLer.fill = GridBagConstraints.HORIZONTAL;
  391.         gbc_textDataLer.gridx = 5;
  392.         gbc_textDataLer.gridy = 2;
  393.         panelLer.add(textDataLer, gbc_textDataLer);
  394.         textDataLer.setColumns(10);
  395.        
  396.         Component horizontalStrut = Box.createHorizontalStrut(20);
  397.         GridBagConstraints gbc_horizontalStrut = new GridBagConstraints();
  398.         gbc_horizontalStrut.insets = new Insets(0, 0, 5, 5);
  399.         gbc_horizontalStrut.gridx = 0;
  400.         gbc_horizontalStrut.gridy = 3;
  401.         panelLer.add(horizontalStrut, gbc_horizontalStrut);
  402.        
  403.         JLabel label_2 = new JLabel("Assunto:");
  404.         GridBagConstraints gbc_label_2 = new GridBagConstraints();
  405.         gbc_label_2.anchor = GridBagConstraints.EAST;
  406.         gbc_label_2.insets = new Insets(0, 0, 5, 5);
  407.         gbc_label_2.gridx = 1;
  408.         gbc_label_2.gridy = 3;
  409.         panelLer.add(label_2, gbc_label_2);
  410.        
  411.         textAssuntoLer = new JTextField();
  412.         textAssuntoLer.setBackground(Color.WHITE);
  413.         textAssuntoLer.setEditable(false);
  414.         textAssuntoLer.setColumns(10);
  415.         GridBagConstraints gbc_textAssuntoLer = new GridBagConstraints();
  416.         gbc_textAssuntoLer.fill = GridBagConstraints.HORIZONTAL;
  417.         gbc_textAssuntoLer.gridwidth = 5;
  418.         gbc_textAssuntoLer.insets = new Insets(0, 0, 5, 5);
  419.         gbc_textAssuntoLer.gridx = 2;
  420.         gbc_textAssuntoLer.gridy = 3;
  421.         panelLer.add(textAssuntoLer, gbc_textAssuntoLer);
  422.        
  423.         JLabel label_3 = new JLabel("Corpo:");
  424.         GridBagConstraints gbc_label_3 = new GridBagConstraints();
  425.         gbc_label_3.anchor = GridBagConstraints.EAST;
  426.         gbc_label_3.insets = new Insets(0, 0, 5, 5);
  427.         gbc_label_3.gridx = 1;
  428.         gbc_label_3.gridy = 4;
  429.         panelLer.add(label_3, gbc_label_3);
  430.        
  431.         Component horizontalStrut_1 = Box.createHorizontalStrut(20);
  432.         GridBagConstraints gbc_horizontalStrut_1 = new GridBagConstraints();
  433.         gbc_horizontalStrut_1.insets = new Insets(0, 0, 5, 0);
  434.         gbc_horizontalStrut_1.gridx = 7;
  435.         gbc_horizontalStrut_1.gridy = 4;
  436.         panelLer.add(horizontalStrut_1, gbc_horizontalStrut_1);
  437.        
  438.         JScrollPane scrollPaneLer = new JScrollPane();
  439.         GridBagConstraints gbc_scrollPaneLer = new GridBagConstraints();
  440.         gbc_scrollPaneLer.fill = GridBagConstraints.BOTH;
  441.         gbc_scrollPaneLer.gridwidth = 5;
  442.         gbc_scrollPaneLer.insets = new Insets(0, 0, 5, 5);
  443.         gbc_scrollPaneLer.gridx = 2;
  444.         gbc_scrollPaneLer.gridy = 5;
  445.         panelLer.add(scrollPaneLer, gbc_scrollPaneLer);
  446.        
  447.         textCorpoLer = new JTextPane();
  448.         textCorpoLer.setEditable(false);
  449.         scrollPaneLer.setViewportView(textCorpoLer);
  450.        
  451.         JButton btnResponder = new JButton("Responder");
  452.         btnResponder.addActionListener(new ActionListener() {
  453.             public void actionPerformed(ActionEvent arg0) {
  454.                 //voltar aqui
  455.                 try {
  456.                     textDestinatario.setText("");
  457.                     textAssunto.setText("");
  458.                     textCorpo.setText("");
  459.                     String assunto = "";
  460.                     int destinatario;
  461.                     String username = "";
  462.                     comboBoxIdentificador.setSelectedIndex(1);
  463.                     Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
  464.                     if(currentFilter == "Clientes") {
  465.                         comboBoxDestinatario.setSelectedIndex(1);
  466.                         Statement inst = lig.createStatement();
  467.                         ResultSet resultado = inst
  468.                                 .executeQuery("SELECT *  FROM mail_cliente_cliente where emailID = '" + currentEmail +"'");
  469.                        
  470.                         while(resultado.next()) {
  471.                             assunto = resultado.getString("assunto");
  472.                             destinatario = resultado.getInt("origem_idCliente");
  473.                             Statement inst1 = lig.createStatement();
  474.                             ResultSet resultado1 = inst1
  475.                                     .executeQuery("SELECT nome, apelido, username  FROM cliente where idCliente = '" + destinatario +"'");
  476.                            
  477.                             while(resultado1.next()) {
  478.                                 username = resultado1.getString("username");
  479.                             }
  480.                         }
  481.                     }
  482.                     else {//medico
  483.                         comboBoxDestinatario.setSelectedIndex(0);
  484.                     }
  485.                    
  486.                     textDestinatario.setText(username);
  487.                     textAssunto.setText(assunto);
  488.                 } catch (SQLException ex) {
  489.                     JOptionPane.showMessageDialog(null, "BD indísponivel! | " + ex);
  490.                 }
  491.                 frame.getContentPane().removeAll();
  492.                 frame.getContentPane().add(panelMensagem);
  493.                 frame.revalidate();
  494.                 frame.repaint();
  495.                
  496.             }
  497.         });
  498.         GridBagConstraints gbc_btnResponder = new GridBagConstraints();
  499.         gbc_btnResponder.anchor = GridBagConstraints.EAST;
  500.         gbc_btnResponder.gridwidth = 2;
  501.         gbc_btnResponder.insets = new Insets(0, 0, 0, 5);
  502.         gbc_btnResponder.gridx = 2;
  503.         gbc_btnResponder.gridy = 6;
  504.         panelLer.add(btnResponder, gbc_btnResponder);
  505.        
  506.         JButton btnVoltar = new JButton("Voltar");
  507.         GridBagConstraints gbc_btnVoltar = new GridBagConstraints();
  508.         gbc_btnVoltar.anchor = GridBagConstraints.WEST;
  509.         gbc_btnVoltar.gridwidth = 5;
  510.         gbc_btnVoltar.gridx = 4;
  511.         gbc_btnVoltar.gridy = 6;
  512.         panelLer.add(btnVoltar, gbc_btnVoltar);
  513.     }
  514.  
  515.     /**
  516.      * Initialize the contents of the frame.
  517.      */
  518.     private void initialize() {
  519.         frame = new JFrame();
  520.         frame.setBounds(100, 100, 800, 600);
  521.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  522.         frame.getContentPane().setLayout(new CardLayout(0, 0));
  523.        
  524.         panelLogin = new JPanel();
  525.         frame.getContentPane().add(panelLogin, "name_947814248684106");
  526.         GridBagLayout gbl_panelLogin = new GridBagLayout();
  527.         gbl_panelLogin.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  528.         gbl_panelLogin.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0};
  529.         gbl_panelLogin.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
  530.         gbl_panelLogin.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
  531.         panelLogin.setLayout(gbl_panelLogin);
  532.        
  533.         JLabel lblLogin = new JLabel("Login");
  534.         GridBagConstraints gbc_lblLogin = new GridBagConstraints();
  535.         gbc_lblLogin.gridwidth = 16;
  536.         gbc_lblLogin.insets = new Insets(0, 0, 5, 0);
  537.         gbc_lblLogin.gridx = 0;
  538.         gbc_lblLogin.gridy = 0;
  539.         panelLogin.add(lblLogin, gbc_lblLogin);
  540.        
  541.         Component verticalStrut = Box.createVerticalStrut(20);
  542.         GridBagConstraints gbc_verticalStrut = new GridBagConstraints();
  543.         gbc_verticalStrut.gridwidth = 3;
  544.         gbc_verticalStrut.insets = new Insets(0, 0, 5, 5);
  545.         gbc_verticalStrut.gridx = 7;
  546.         gbc_verticalStrut.gridy = 1;
  547.         panelLogin.add(verticalStrut, gbc_verticalStrut);
  548.        
  549.         Component horizontalStrut = Box.createHorizontalStrut(20);
  550.         GridBagConstraints gbc_horizontalStrut = new GridBagConstraints();
  551.         gbc_horizontalStrut.insets = new Insets(0, 0, 5, 5);
  552.         gbc_horizontalStrut.gridx = 1;
  553.         gbc_horizontalStrut.gridy = 2;
  554.         panelLogin.add(horizontalStrut, gbc_horizontalStrut);
  555.        
  556.         Component horizontalStrut_1 = Box.createHorizontalStrut(20);
  557.         GridBagConstraints gbc_horizontalStrut_1 = new GridBagConstraints();
  558.         gbc_horizontalStrut_1.insets = new Insets(0, 0, 5, 5);
  559.         gbc_horizontalStrut_1.gridx = 2;
  560.         gbc_horizontalStrut_1.gridy = 2;
  561.         panelLogin.add(horizontalStrut_1, gbc_horizontalStrut_1);
  562.        
  563.         Component horizontalStrut_2 = Box.createHorizontalStrut(20);
  564.         GridBagConstraints gbc_horizontalStrut_2 = new GridBagConstraints();
  565.         gbc_horizontalStrut_2.insets = new Insets(0, 0, 5, 5);
  566.         gbc_horizontalStrut_2.gridx = 3;
  567.         gbc_horizontalStrut_2.gridy = 2;
  568.         panelLogin.add(horizontalStrut_2, gbc_horizontalStrut_2);
  569.        
  570.         Component horizontalStrut_3 = Box.createHorizontalStrut(20);
  571.         GridBagConstraints gbc_horizontalStrut_3 = new GridBagConstraints();
  572.         gbc_horizontalStrut_3.insets = new Insets(0, 0, 5, 5);
  573.         gbc_horizontalStrut_3.gridx = 4;
  574.         gbc_horizontalStrut_3.gridy = 2;
  575.         panelLogin.add(horizontalStrut_3, gbc_horizontalStrut_3);
  576.        
  577.         Component horizontalStrut_4 = Box.createHorizontalStrut(20);
  578.         GridBagConstraints gbc_horizontalStrut_4 = new GridBagConstraints();
  579.         gbc_horizontalStrut_4.insets = new Insets(0, 0, 5, 5);
  580.         gbc_horizontalStrut_4.gridx = 5;
  581.         gbc_horizontalStrut_4.gridy = 2;
  582.         panelLogin.add(horizontalStrut_4, gbc_horizontalStrut_4);
  583.        
  584.         JLabel lblUsername_1 = new JLabel("Username:");
  585.         GridBagConstraints gbc_lblUsername_1 = new GridBagConstraints();
  586.         gbc_lblUsername_1.anchor = GridBagConstraints.EAST;
  587.         gbc_lblUsername_1.insets = new Insets(0, 0, 5, 5);
  588.         gbc_lblUsername_1.gridx = 6;
  589.         gbc_lblUsername_1.gridy = 2;
  590.         panelLogin.add(lblUsername_1, gbc_lblUsername_1);
  591.        
  592.         textUsernameLogin = new JTextField();
  593.         GridBagConstraints gbc_textUsernameLogin = new GridBagConstraints();
  594.         gbc_textUsernameLogin.gridwidth = 3;
  595.         gbc_textUsernameLogin.insets = new Insets(0, 0, 5, 5);
  596.         gbc_textUsernameLogin.fill = GridBagConstraints.HORIZONTAL;
  597.         gbc_textUsernameLogin.gridx = 7;
  598.         gbc_textUsernameLogin.gridy = 2;
  599.         panelLogin.add(textUsernameLogin, gbc_textUsernameLogin);
  600.         textUsernameLogin.setColumns(10);
  601.        
  602.         Component horizontalStrut_7 = Box.createHorizontalStrut(20);
  603.         GridBagConstraints gbc_horizontalStrut_7 = new GridBagConstraints();
  604.         gbc_horizontalStrut_7.insets = new Insets(0, 0, 5, 5);
  605.         gbc_horizontalStrut_7.gridx = 11;
  606.         gbc_horizontalStrut_7.gridy = 2;
  607.         panelLogin.add(horizontalStrut_7, gbc_horizontalStrut_7);
  608.        
  609.         Component horizontalStrut_9 = Box.createHorizontalStrut(20);
  610.         GridBagConstraints gbc_horizontalStrut_9 = new GridBagConstraints();
  611.         gbc_horizontalStrut_9.insets = new Insets(0, 0, 5, 5);
  612.         gbc_horizontalStrut_9.gridx = 12;
  613.         gbc_horizontalStrut_9.gridy = 2;
  614.         panelLogin.add(horizontalStrut_9, gbc_horizontalStrut_9);
  615.        
  616.         Component horizontalStrut_5 = Box.createHorizontalStrut(20);
  617.         GridBagConstraints gbc_horizontalStrut_5 = new GridBagConstraints();
  618.         gbc_horizontalStrut_5.insets = new Insets(0, 0, 5, 5);
  619.         gbc_horizontalStrut_5.gridx = 13;
  620.         gbc_horizontalStrut_5.gridy = 2;
  621.         panelLogin.add(horizontalStrut_5, gbc_horizontalStrut_5);
  622.        
  623.         Component horizontalStrut_6 = Box.createHorizontalStrut(20);
  624.         GridBagConstraints gbc_horizontalStrut_6 = new GridBagConstraints();
  625.         gbc_horizontalStrut_6.insets = new Insets(0, 0, 5, 5);
  626.         gbc_horizontalStrut_6.gridx = 14;
  627.         gbc_horizontalStrut_6.gridy = 2;
  628.         panelLogin.add(horizontalStrut_6, gbc_horizontalStrut_6);
  629.        
  630.         Component horizontalStrut_8 = Box.createHorizontalStrut(20);
  631.         GridBagConstraints gbc_horizontalStrut_8 = new GridBagConstraints();
  632.         gbc_horizontalStrut_8.insets = new Insets(0, 0, 5, 0);
  633.         gbc_horizontalStrut_8.gridx = 15;
  634.         gbc_horizontalStrut_8.gridy = 2;
  635.         panelLogin.add(horizontalStrut_8, gbc_horizontalStrut_8);
  636.        
  637.         JLabel lblPassword_1 = new JLabel("Password:");
  638.         GridBagConstraints gbc_lblPassword_1 = new GridBagConstraints();
  639.         gbc_lblPassword_1.anchor = GridBagConstraints.EAST;
  640.         gbc_lblPassword_1.insets = new Insets(0, 0, 5, 5);
  641.         gbc_lblPassword_1.gridx = 6;
  642.         gbc_lblPassword_1.gridy = 3;
  643.         panelLogin.add(lblPassword_1, gbc_lblPassword_1);
  644.        
  645.         JButton btnLogin_1 = new JButton("Login");
  646.         btnLogin_1.addActionListener(new ActionListener() {
  647.             public void actionPerformed(ActionEvent e) {
  648.                 String username = textUsernameLogin.getText();
  649.                 String password = passwordLogin.getText();
  650.                 try {
  651.                     Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
  652.                     Statement inst = lig.createStatement();
  653.                     ResultSet resultado = inst
  654.                             .executeQuery("select palavraChave, idCliente FROM cliente where username = '" + username + "'");
  655.                     while (resultado.next()) {
  656.                         String passworddb = resultado.getString("palavraChave");
  657.                         if(password.equals(passworddb)) {
  658.                             JOptionPane.showMessageDialog(null, "Login com sucesso");
  659.                             currentUserID = resultado.getInt("idCliente");
  660.                            
  661.                             /** Mudar de Painel para o perfil */
  662.                            
  663.                             frame.getContentPane().removeAll();
  664.                             frame.getContentPane().add(panelPerfil);
  665.                             frame.revalidate();
  666.                             frame.repaint();
  667.                             /** Definir os botões do menu (login e registo) como disabled */
  668.                             mntmLogin.setEnabled(false);
  669.                             mntmRegisto.setEnabled(false);
  670.                             mntmPerfil.setEnabled(true);
  671.                             mntmLogout.setEnabled(true);
  672.                             mntmEscrever.setEnabled(true);
  673.                             mntmInbox.setEnabled(true);
  674.                             /** Limpar os campos de utilizador e password */
  675.                             textUsernameLogin.setText("");
  676.                             passwordLogin.setText("");
  677.                             perfilSetup();
  678.                         }
  679.                         else {
  680.                             JOptionPane.showMessageDialog(null, "Login Falhado, password ou username errados.");
  681.                             passwordLogin.setText("");
  682.                         }
  683.                     }
  684.                     lig.close();
  685.                 } catch (SQLException ex) {
  686.                     JOptionPane.showMessageDialog(null, "BD indísponivel! \n" + ex.getMessage());
  687.                 }
  688.             }
  689.         });
  690.        
  691.         passwordLogin = new JTextField();
  692.         GridBagConstraints gbc_passwordLogin = new GridBagConstraints();
  693.         gbc_passwordLogin.gridwidth = 3;
  694.         gbc_passwordLogin.insets = new Insets(0, 0, 5, 5);
  695.         gbc_passwordLogin.fill = GridBagConstraints.HORIZONTAL;
  696.         gbc_passwordLogin.gridx = 7;
  697.         gbc_passwordLogin.gridy = 3;
  698.         panelLogin.add(passwordLogin, gbc_passwordLogin);
  699.         passwordLogin.setColumns(10);
  700.         GridBagConstraints gbc_btnLogin_1 = new GridBagConstraints();
  701.         gbc_btnLogin_1.insets = new Insets(0, 0, 0, 5);
  702.         gbc_btnLogin_1.gridx = 7;
  703.         gbc_btnLogin_1.gridy = 5;
  704.         panelLogin.add(btnLogin_1, gbc_btnLogin_1);
  705.        
  706.         JButton btnRegistar_1 = new JButton("Registar");
  707.         btnRegistar_1.addActionListener(new ActionListener() {
  708.             public void actionPerformed(ActionEvent arg0) {
  709.                 frame.getContentPane().removeAll();
  710.                 frame.getContentPane().add(panelRegisto);
  711.                 frame.revalidate();
  712.                 frame.repaint();
  713.             }
  714.         });
  715.         GridBagConstraints gbc_btnRegistar_1 = new GridBagConstraints();
  716.         gbc_btnRegistar_1.insets = new Insets(0, 0, 0, 5);
  717.         gbc_btnRegistar_1.gridx = 8;
  718.         gbc_btnRegistar_1.gridy = 5;
  719.         panelLogin.add(btnRegistar_1, gbc_btnRegistar_1);
  720.        
  721.         JButton btnPasswordForget = new JButton("Esqueci-me da palavra-passe");
  722.         btnPasswordForget.addActionListener(new ActionListener() {
  723.             public void actionPerformed(ActionEvent e) {
  724.                 frame.getContentPane().removeAll();
  725.                 frame.getContentPane().add(panelForgot);
  726.                 frame.revalidate();
  727.                 frame.repaint();
  728.                 textUsernameLogin.setText("");
  729.                 passwordLogin.setText("");
  730.             }
  731.         });
  732.         GridBagConstraints gbc_btnPasswordForget = new GridBagConstraints();
  733.         gbc_btnPasswordForget.insets = new Insets(0, 0, 0, 5);
  734.         gbc_btnPasswordForget.gridx = 9;
  735.         gbc_btnPasswordForget.gridy = 5;
  736.         panelLogin.add(btnPasswordForget, gbc_btnPasswordForget);
  737.        
  738.         panelRegisto = new JPanel();
  739.         frame.getContentPane().add(panelRegisto, "name_947819464113314");
  740.         GridBagLayout gbl_panelRegisto = new GridBagLayout();
  741.         gbl_panelRegisto.columnWidths = new int[]{0, 0, 15, 0, 0, 0, 0, 0, 0, 0};
  742.         gbl_panelRegisto.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  743.         gbl_panelRegisto.columnWeights = new double[]{0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
  744.         gbl_panelRegisto.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
  745.         panelRegisto.setLayout(gbl_panelRegisto);
  746.        
  747.         Component horizontalStrut_10 = Box.createHorizontalStrut(20);
  748.         GridBagConstraints gbc_horizontalStrut_10 = new GridBagConstraints();
  749.         gbc_horizontalStrut_10.insets = new Insets(0, 0, 5, 5);
  750.         gbc_horizontalStrut_10.gridx = 0;
  751.         gbc_horizontalStrut_10.gridy = 0;
  752.         panelRegisto.add(horizontalStrut_10, gbc_horizontalStrut_10);
  753.        
  754.         JLabel lblRegisto = new JLabel("Registo");
  755.         GridBagConstraints gbc_lblRegisto = new GridBagConstraints();
  756.         gbc_lblRegisto.gridwidth = 3;
  757.         gbc_lblRegisto.insets = new Insets(0, 0, 5, 5);
  758.         gbc_lblRegisto.gridx = 1;
  759.         gbc_lblRegisto.gridy = 0;
  760.         panelRegisto.add(lblRegisto, gbc_lblRegisto);
  761.        
  762.         Component horizontalStrut_11 = Box.createHorizontalStrut(20);
  763.         GridBagConstraints gbc_horizontalStrut_11 = new GridBagConstraints();
  764.         gbc_horizontalStrut_11.insets = new Insets(0, 0, 5, 0);
  765.         gbc_horizontalStrut_11.gridx = 8;
  766.         gbc_horizontalStrut_11.gridy = 0;
  767.         panelRegisto.add(horizontalStrut_11, gbc_horizontalStrut_11);
  768.        
  769.         JLabel lblNome = new JLabel("Nome:");
  770.         GridBagConstraints gbc_lblNome = new GridBagConstraints();
  771.         gbc_lblNome.anchor = GridBagConstraints.WEST;
  772.         gbc_lblNome.insets = new Insets(0, 0, 5, 5);
  773.         gbc_lblNome.gridx = 1;
  774.         gbc_lblNome.gridy = 1;
  775.         panelRegisto.add(lblNome, gbc_lblNome);
  776.        
  777.         textNome = new JTextField();
  778.         GridBagConstraints gbc_textNome = new GridBagConstraints();
  779.         gbc_textNome.gridwidth = 6;
  780.         gbc_textNome.insets = new Insets(0, 0, 5, 5);
  781.         gbc_textNome.fill = GridBagConstraints.HORIZONTAL;
  782.         gbc_textNome.gridx = 2;
  783.         gbc_textNome.gridy = 1;
  784.         panelRegisto.add(textNome, gbc_textNome);
  785.         textNome.setColumns(10);
  786.        
  787.         JLabel lblApelido = new JLabel("Apelido:");
  788.         GridBagConstraints gbc_lblApelido = new GridBagConstraints();
  789.         gbc_lblApelido.anchor = GridBagConstraints.WEST;
  790.         gbc_lblApelido.insets = new Insets(0, 0, 5, 5);
  791.         gbc_lblApelido.gridx = 1;
  792.         gbc_lblApelido.gridy = 2;
  793.         panelRegisto.add(lblApelido, gbc_lblApelido);
  794.        
  795.         textApelido = new JTextField();
  796.         GridBagConstraints gbc_textApelido = new GridBagConstraints();
  797.         gbc_textApelido.gridwidth = 6;
  798.         gbc_textApelido.insets = new Insets(0, 0, 5, 5);
  799.         gbc_textApelido.fill = GridBagConstraints.HORIZONTAL;
  800.         gbc_textApelido.gridx = 2;
  801.         gbc_textApelido.gridy = 2;
  802.         panelRegisto.add(textApelido, gbc_textApelido);
  803.         textApelido.setColumns(10);
  804.        
  805.         JLabel lblId = new JLabel("ID:");
  806.         GridBagConstraints gbc_lblId = new GridBagConstraints();
  807.         gbc_lblId.anchor = GridBagConstraints.WEST;
  808.         gbc_lblId.insets = new Insets(0, 0, 5, 5);
  809.         gbc_lblId.gridx = 1;
  810.         gbc_lblId.gridy = 3;
  811.         panelRegisto.add(lblId, gbc_lblId);
  812.        
  813.         textID = new JTextField();
  814.         textID.setEditable(false);
  815.         textID.setEnabled(false);
  816.         GridBagConstraints gbc_textID = new GridBagConstraints();
  817.         gbc_textID.gridwidth = 6;
  818.         gbc_textID.insets = new Insets(0, 0, 5, 5);
  819.         gbc_textID.fill = GridBagConstraints.HORIZONTAL;
  820.         gbc_textID.gridx = 2;
  821.         gbc_textID.gridy = 3;
  822.         panelRegisto.add(textID, gbc_textID);
  823.         textID.setColumns(10);
  824.         try {
  825.             Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
  826.             PreparedStatement inst = lig.prepareStatement("SELECT MAX(idCliente) FROM cliente");
  827.             ResultSet res = inst.executeQuery();
  828.             if (res.next()) {
  829.                 idCliente = res.getInt(1);
  830.                 textID.setText("" + (idCliente + 1));
  831.             }
  832.         } catch (SQLException e) {
  833.             JOptionPane.showMessageDialog(frame, "BD indisponível!" + e.getMessage());
  834.         }
  835.        
  836.         JLabel lblUsername = new JLabel("Username:");
  837.         GridBagConstraints gbc_lblUsername = new GridBagConstraints();
  838.         gbc_lblUsername.anchor = GridBagConstraints.WEST;
  839.         gbc_lblUsername.insets = new Insets(0, 0, 5, 5);
  840.         gbc_lblUsername.gridx = 1;
  841.         gbc_lblUsername.gridy = 4;
  842.         panelRegisto.add(lblUsername, gbc_lblUsername);
  843.        
  844.         textUsername = new JTextField();
  845.         GridBagConstraints gbc_textUsername = new GridBagConstraints();
  846.         gbc_textUsername.gridwidth = 6;
  847.         gbc_textUsername.insets = new Insets(0, 0, 5, 5);
  848.         gbc_textUsername.fill = GridBagConstraints.HORIZONTAL;
  849.         gbc_textUsername.gridx = 2;
  850.         gbc_textUsername.gridy = 4;
  851.         panelRegisto.add(textUsername, gbc_textUsername);
  852.         textUsername.setColumns(10);
  853.        
  854.         JLabel lblPassword = new JLabel("Password:");
  855.         GridBagConstraints gbc_lblPassword = new GridBagConstraints();
  856.         gbc_lblPassword.anchor = GridBagConstraints.WEST;
  857.         gbc_lblPassword.insets = new Insets(0, 0, 5, 5);
  858.         gbc_lblPassword.gridx = 1;
  859.         gbc_lblPassword.gridy = 5;
  860.         panelRegisto.add(lblPassword, gbc_lblPassword);
  861.        
  862.         passwordRegisto = new JTextField();
  863.         GridBagConstraints gbc_passwordRegisto = new GridBagConstraints();
  864.         gbc_passwordRegisto.gridwidth = 6;
  865.         gbc_passwordRegisto.insets = new Insets(0, 0, 5, 5);
  866.         gbc_passwordRegisto.fill = GridBagConstraints.HORIZONTAL;
  867.         gbc_passwordRegisto.gridx = 2;
  868.         gbc_passwordRegisto.gridy = 5;
  869.         panelRegisto.add(passwordRegisto, gbc_passwordRegisto);
  870.         passwordRegisto.setColumns(10);
  871.        
  872.         JLabel lblDataDeNascimento = new JLabel("Data de Nascimento:");
  873.         GridBagConstraints gbc_lblDataDeNascimento = new GridBagConstraints();
  874.         gbc_lblDataDeNascimento.anchor = GridBagConstraints.WEST;
  875.         gbc_lblDataDeNascimento.insets = new Insets(0, 0, 5, 5);
  876.         gbc_lblDataDeNascimento.gridx = 1;
  877.         gbc_lblDataDeNascimento.gridy = 6;
  878.         panelRegisto.add(lblDataDeNascimento, gbc_lblDataDeNascimento);
  879.        
  880.         textDataNascimento = new JTextField();
  881.         GridBagConstraints gbc_textDataNascimento = new GridBagConstraints();
  882.         gbc_textDataNascimento.gridwidth = 6;
  883.         gbc_textDataNascimento.insets = new Insets(0, 0, 5, 5);
  884.         gbc_textDataNascimento.fill = GridBagConstraints.HORIZONTAL;
  885.         gbc_textDataNascimento.gridx = 2;
  886.         gbc_textDataNascimento.gridy = 6;
  887.         panelRegisto.add(textDataNascimento, gbc_textDataNascimento);
  888.         textDataNascimento.addFocusListener(new FocusAdapter() {
  889.             public void focusGained(FocusEvent e){
  890.                 if(textDataNascimento.getText().equals("AAAA-MM-DD")){
  891.                     textDataNascimento.setText("");
  892.                     textDataNascimento.setForeground(Color.BLACK);
  893.                 }
  894.             }
  895.            
  896.             public void focusLost(FocusEvent x){
  897.                 if(textDataNascimento.getText().equals("")){
  898.                     textDataNascimento.setText("AAAA-MM-DD");
  899.                     textDataNascimento.setForeground(Color.GRAY);
  900.                 }
  901.             }
  902.         });
  903.        
  904.         JLabel lblTipoDeSangue = new JLabel("Tipo de Sangue:");
  905.         GridBagConstraints gbc_lblTipoDeSangue = new GridBagConstraints();
  906.         gbc_lblTipoDeSangue.anchor = GridBagConstraints.WEST;
  907.         gbc_lblTipoDeSangue.insets = new Insets(0, 0, 5, 5);
  908.         gbc_lblTipoDeSangue.gridx = 1;
  909.         gbc_lblTipoDeSangue.gridy = 7;
  910.         panelRegisto.add(lblTipoDeSangue, gbc_lblTipoDeSangue);
  911.        
  912.         JComboBox comboBoxTipoSangue = new JComboBox();
  913.         comboBoxTipoSangue.setModel(
  914.                 new DefaultComboBoxModel(new String[] { "...", "O+", "O-", "A+", "A-", "B+", "B-", "AB+", "AB-" }));
  915.         GridBagConstraints gbc_comboBoxTipoSangue = new GridBagConstraints();
  916.         gbc_comboBoxTipoSangue.insets = new Insets(0, 0, 5, 5);
  917.         gbc_comboBoxTipoSangue.fill = GridBagConstraints.HORIZONTAL;
  918.         gbc_comboBoxTipoSangue.gridx = 2;
  919.         gbc_comboBoxTipoSangue.gridy = 7;
  920.         panelRegisto.add(comboBoxTipoSangue, gbc_comboBoxTipoSangue);
  921.        
  922.         JLabel lblSexo = new JLabel("Sexo:");
  923.         GridBagConstraints gbc_lblSexo = new GridBagConstraints();
  924.         gbc_lblSexo.anchor = GridBagConstraints.WEST;
  925.         gbc_lblSexo.insets = new Insets(0, 0, 5, 5);
  926.         gbc_lblSexo.gridx = 1;
  927.         gbc_lblSexo.gridy = 8;
  928.         panelRegisto.add(lblSexo, gbc_lblSexo);
  929.        
  930.         JComboBox comboBoxSexo = new JComboBox();
  931.         comboBoxSexo.setModel(
  932.                 new DefaultComboBoxModel(new String[] { "...", "Masculino", "Feminino" }));
  933.         GridBagConstraints gbc_comboBoxSexo = new GridBagConstraints();
  934.         gbc_comboBoxSexo.insets = new Insets(0, 0, 5, 5);
  935.         gbc_comboBoxSexo.fill = GridBagConstraints.HORIZONTAL;
  936.         gbc_comboBoxSexo.gridx = 2;
  937.         gbc_comboBoxSexo.gridy = 8;
  938.         panelRegisto.add(comboBoxSexo, gbc_comboBoxSexo);
  939.        
  940.         JLabel lblEmail = new JLabel("Email:");
  941.         GridBagConstraints gbc_lblEmail = new GridBagConstraints();
  942.         gbc_lblEmail.anchor = GridBagConstraints.WEST;
  943.         gbc_lblEmail.insets = new Insets(0, 0, 5, 5);
  944.         gbc_lblEmail.gridx = 1;
  945.         gbc_lblEmail.gridy = 9;
  946.         panelRegisto.add(lblEmail, gbc_lblEmail);
  947.        
  948.         textEmail = new JTextField();
  949.         GridBagConstraints gbc_textEmail = new GridBagConstraints();
  950.         gbc_textEmail.gridwidth = 6;
  951.         gbc_textEmail.insets = new Insets(0, 0, 5, 5);
  952.         gbc_textEmail.fill = GridBagConstraints.HORIZONTAL;
  953.         gbc_textEmail.gridx = 2;
  954.         gbc_textEmail.gridy = 9;
  955.         panelRegisto.add(textEmail, gbc_textEmail);
  956.         textEmail.setColumns(10);
  957.         textEmail.addFocusListener(new FocusAdapter() {
  958.             public void focusGained(FocusEvent e){
  959.                 if(textEmail.getText().equals("Tudo em minúsculas")){
  960.                     textEmail.setText("");
  961.                     textEmail.setForeground(Color.BLACK);
  962.                 }
  963.             }
  964.            
  965.             public void focusLost(FocusEvent x){
  966.                 if(textEmail.getText().equals("")){
  967.                     textEmail.setText("Tudo em minúsculas");
  968.                     textEmail.setForeground(Color.GRAY);
  969.                 }
  970.             }
  971.         });
  972.        
  973.         JLabel lblContacto = new JLabel("Contacto:");
  974.         GridBagConstraints gbc_lblContacto = new GridBagConstraints();
  975.         gbc_lblContacto.anchor = GridBagConstraints.WEST;
  976.         gbc_lblContacto.insets = new Insets(0, 0, 5, 5);
  977.         gbc_lblContacto.gridx = 1;
  978.         gbc_lblContacto.gridy = 10;
  979.         panelRegisto.add(lblContacto, gbc_lblContacto);
  980.        
  981.         textContacto = new JTextField();
  982.         GridBagConstraints gbc_textContacto = new GridBagConstraints();
  983.         gbc_textContacto.gridwidth = 6;
  984.         gbc_textContacto.insets = new Insets(0, 0, 5, 5);
  985.         gbc_textContacto.fill = GridBagConstraints.HORIZONTAL;
  986.         gbc_textContacto.gridx = 2;
  987.         gbc_textContacto.gridy = 10;
  988.         panelRegisto.add(textContacto, gbc_textContacto);
  989.         textContacto.setColumns(10);
  990.        
  991.         JLabel lblMorada = new JLabel("Morada:");
  992.         GridBagConstraints gbc_lblMorada = new GridBagConstraints();
  993.         gbc_lblMorada.anchor = GridBagConstraints.WEST;
  994.         gbc_lblMorada.insets = new Insets(0, 0, 5, 5);
  995.         gbc_lblMorada.gridx = 1;
  996.         gbc_lblMorada.gridy = 11;
  997.         panelRegisto.add(lblMorada, gbc_lblMorada);
  998.        
  999.         textMorada = new JTextField();
  1000.         GridBagConstraints gbc_textMorada = new GridBagConstraints();
  1001.         gbc_textMorada.gridwidth = 6;
  1002.         gbc_textMorada.insets = new Insets(0, 0, 5, 5);
  1003.         gbc_textMorada.fill = GridBagConstraints.HORIZONTAL;
  1004.         gbc_textMorada.gridx = 2;
  1005.         gbc_textMorada.gridy = 11;
  1006.         panelRegisto.add(textMorada, gbc_textMorada);
  1007.         textMorada.setColumns(10);
  1008.        
  1009.         /*Botão para registar Clientes */
  1010.        
  1011.         JButton btnRegistar = new JButton("Registar");
  1012.         btnRegistar.addActionListener(new ActionListener() {
  1013.             public void actionPerformed(ActionEvent arg0) {
  1014.                 String username = textUsername.getText();
  1015.                 boolean usernameSame = true;
  1016.                 //verificar se ja existe o username
  1017.                
  1018.                 try {
  1019.                     Connection ligRegisto = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
  1020.                     Statement instRegisto = ligRegisto.createStatement();
  1021.                     ResultSet resultadoRegisto = instRegisto
  1022.                             .executeQuery("SELECT username  FROM cliente where username = '" + username +"'");
  1023.                    
  1024.                     if(resultadoRegisto.next() == false) {
  1025.                         usernameSame = false;
  1026.                     }
  1027.                     else {
  1028.                         usernameSame = true;
  1029.                     }
  1030.                 } catch (SQLException ex) {
  1031.                     JOptionPane.showMessageDialog(null, "BD indísponivel! | " + ex);
  1032.                 }
  1033.                
  1034.                 try {
  1035.                     Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
  1036.                     String id = textID.getText();
  1037.                     String nome = textNome.getText();
  1038.                     String apelido = textApelido.getText();
  1039.                     String password = passwordRegisto.getText();
  1040.                     DateTimeFormatter date = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  1041.                     LocalDate data = LocalDate.parse(textDataNascimento.getText(), date);
  1042.                     String tipoSangue = (String) comboBoxTipoSangue.getSelectedItem();
  1043.                     if(tipoSangue == "...") {
  1044.                         tipoSangue = null;
  1045.                     }
  1046.                     String sexo = (String) comboBoxSexo.getSelectedItem();
  1047.                     if(sexo == "...") {
  1048.                         sexo = null;
  1049.                     }
  1050.                     String email = textEmail.getText();
  1051.                     String contacto = textContacto.getText();
  1052.                     String morada = textMorada.getText();
  1053.                     if(usernameSame == false) {
  1054.                         PreparedStatement inst = lig.prepareStatement(
  1055.                                 "INSERT INTO cliente (idCliente, nome, apelido, username, palavraChave, dataNascimento, tipoSangue, sexo, email, contacto, morada) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
  1056.                         inst.setString(1, id);
  1057.                         inst.setString(2, nome);
  1058.                         inst.setString(3, apelido);
  1059.                         inst.setString(4, username);
  1060.                         inst.setString(5, password);
  1061.                         inst.setObject(6, data);
  1062.                         inst.setString(7, tipoSangue);
  1063.                         inst.setString(8, sexo);
  1064.                         inst.setString(9, email);
  1065.                         inst.setString(10, contacto);
  1066.                         inst.setString(11, morada);
  1067.                         int linhasAlteradas = inst.executeUpdate();
  1068.                         if (linhasAlteradas == 1) {
  1069.                             JOptionPane.showMessageDialog(null, "Registo Inserido");
  1070.                         } else {
  1071.                             JOptionPane.showMessageDialog(null, "Registo não Inserido");
  1072.                         }
  1073.                         lig.close();
  1074.                         textID.setText("");
  1075.                         textNome.setText("");
  1076.                         textApelido.setText("");
  1077.                         textUsername.setText("");
  1078.                         passwordRegisto.setText("");
  1079.                         comboBoxTipoSangue.setSelectedIndex(0);
  1080.                         comboBoxSexo.setSelectedIndex(0);
  1081.                         textContacto.setText("");
  1082.                         textMorada.setText("");
  1083.                         textEmail.setText("Tudo em minúsculas");
  1084.                         textEmail.setForeground(Color.GRAY);
  1085.                         textDataNascimento.setText("AAAA-MM-DD");
  1086.                         textDataNascimento.setForeground(Color.GRAY);
  1087.                     }
  1088.                     else {
  1089.                         JOptionPane.showMessageDialog(null,"O username (" + username + ") já está a ser utilizado, escolha outro.");
  1090.                         textUsername.setText("");
  1091.                     }
  1092.                 }catch (SQLException e) {
  1093.                     JOptionPane.showMessageDialog(frame, "Base de dados indisponivel: " + e.getMessage());
  1094.                 }
  1095.                 try {
  1096.                     Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
  1097.                     PreparedStatement inst = lig.prepareStatement("SELECT MAX(idCliente) FROM cliente");
  1098.                     ResultSet res = inst.executeQuery();
  1099.                     if (res.next()) {
  1100.                         idCliente = res.getInt(1);
  1101.                         textID.setText("" + (idCliente + 1));
  1102.                     }
  1103.                 } catch (SQLException ex) {
  1104.                     JOptionPane.showMessageDialog(frame, "BD indisponível!" + ex.getMessage());
  1105.                 }
  1106.             }
  1107.         });
  1108.         GridBagConstraints gbc_btnRegistar = new GridBagConstraints();
  1109.         gbc_btnRegistar.gridwidth = 4;
  1110.         gbc_btnRegistar.insets = new Insets(0, 0, 0, 5);
  1111.         gbc_btnRegistar.gridx = 2;
  1112.         gbc_btnRegistar.gridy = 13;
  1113.         panelRegisto.add(btnRegistar, gbc_btnRegistar);
  1114.        
  1115.         panelPerfil = new JPanel();
  1116.         frame.getContentPane().add(panelPerfil, "name_205706181382062");
  1117.         GridBagLayout gbl_panelPerfil = new GridBagLayout();
  1118.         gbl_panelPerfil.columnWidths = new int[]{0, 214, 44, 44, 0, 0, 0, 0, 0, 0, 0, 0};
  1119.         gbl_panelPerfil.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  1120.         gbl_panelPerfil.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, Double.MIN_VALUE};
  1121.         gbl_panelPerfil.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE};
  1122.         panelPerfil.setLayout(gbl_panelPerfil);
  1123.        
  1124.         JLabel labelPerfil = new JLabel("Perfil");
  1125.         GridBagConstraints gbc_labelPerfil = new GridBagConstraints();
  1126.         gbc_labelPerfil.gridwidth = 11;
  1127.         gbc_labelPerfil.insets = new Insets(0, 0, 5, 0);
  1128.         gbc_labelPerfil.gridx = 0;
  1129.         gbc_labelPerfil.gridy = 0;
  1130.         panelPerfil.add(labelPerfil, gbc_labelPerfil);
  1131.        
  1132.         JLabel labelNomePerfil = new JLabel("Nome:");
  1133.         GridBagConstraints gbc_labelNomePerfil = new GridBagConstraints();
  1134.         gbc_labelNomePerfil.anchor = GridBagConstraints.WEST;
  1135.         gbc_labelNomePerfil.insets = new Insets(0, 0, 5, 5);
  1136.         gbc_labelNomePerfil.gridx = 0;
  1137.         gbc_labelNomePerfil.gridy = 1;
  1138.         panelPerfil.add(labelNomePerfil, gbc_labelNomePerfil);
  1139.        
  1140.         textNomePerfil = new JTextField();
  1141.         textNomePerfil.setEditable(false);
  1142.         textNomePerfil.setColumns(10);
  1143.         GridBagConstraints gbc_textNomePerfil = new GridBagConstraints();
  1144.         gbc_textNomePerfil.fill = GridBagConstraints.HORIZONTAL;
  1145.         gbc_textNomePerfil.gridwidth = 3;
  1146.         gbc_textNomePerfil.insets = new Insets(0, 0, 5, 5);
  1147.         gbc_textNomePerfil.gridx = 1;
  1148.         gbc_textNomePerfil.gridy = 1;
  1149.         panelPerfil.add(textNomePerfil, gbc_textNomePerfil);
  1150.        
  1151.         JLabel labelApelidoPerfil = new JLabel("Apelido:");
  1152.         GridBagConstraints gbc_labelApelidoPerfil = new GridBagConstraints();
  1153.         gbc_labelApelidoPerfil.anchor = GridBagConstraints.WEST;
  1154.         gbc_labelApelidoPerfil.insets = new Insets(0, 0, 5, 5);
  1155.         gbc_labelApelidoPerfil.gridx = 0;
  1156.         gbc_labelApelidoPerfil.gridy = 2;
  1157.         panelPerfil.add(labelApelidoPerfil, gbc_labelApelidoPerfil);
  1158.        
  1159.         textApelidoPerfil = new JTextField();
  1160.         textApelidoPerfil.setEditable(false);
  1161.         textApelidoPerfil.setColumns(10);
  1162.         GridBagConstraints gbc_textApelidoPerfil = new GridBagConstraints();
  1163.         gbc_textApelidoPerfil.fill = GridBagConstraints.HORIZONTAL;
  1164.         gbc_textApelidoPerfil.gridwidth = 3;
  1165.         gbc_textApelidoPerfil.insets = new Insets(0, 0, 5, 5);
  1166.         gbc_textApelidoPerfil.gridx = 1;
  1167.         gbc_textApelidoPerfil.gridy = 2;
  1168.         panelPerfil.add(textApelidoPerfil, gbc_textApelidoPerfil);
  1169.        
  1170.         JLabel lblImagemDePerfil = new JLabel("Imagem de Perfil");
  1171.         GridBagConstraints gbc_lblImagemDePerfil = new GridBagConstraints();
  1172.         gbc_lblImagemDePerfil.gridwidth = 4;
  1173.         gbc_lblImagemDePerfil.gridheight = 4;
  1174.         gbc_lblImagemDePerfil.insets = new Insets(0, 0, 5, 5);
  1175.         gbc_lblImagemDePerfil.gridx = 6;
  1176.         gbc_lblImagemDePerfil.gridy = 1;
  1177.         panelPerfil.add(lblImagemDePerfil, gbc_lblImagemDePerfil);
  1178.        
  1179.         JLabel labelIDPerfil = new JLabel("ID:");
  1180.         GridBagConstraints gbc_labelIDPerfil = new GridBagConstraints();
  1181.         gbc_labelIDPerfil.anchor = GridBagConstraints.WEST;
  1182.         gbc_labelIDPerfil.insets = new Insets(0, 0, 5, 5);
  1183.         gbc_labelIDPerfil.gridx = 0;
  1184.         gbc_labelIDPerfil.gridy = 3;
  1185.         panelPerfil.add(labelIDPerfil, gbc_labelIDPerfil);
  1186.        
  1187.         textIDPerfil = new JTextField();
  1188.         textIDPerfil.setEnabled(false);
  1189.         textIDPerfil.setEditable(false);
  1190.         textIDPerfil.setColumns(10);
  1191.         GridBagConstraints gbc_textIDPerfil = new GridBagConstraints();
  1192.         gbc_textIDPerfil.fill = GridBagConstraints.HORIZONTAL;
  1193.         gbc_textIDPerfil.insets = new Insets(0, 0, 5, 5);
  1194.         gbc_textIDPerfil.gridx = 1;
  1195.         gbc_textIDPerfil.gridy = 3;
  1196.         panelPerfil.add(textIDPerfil, gbc_textIDPerfil);
  1197.        
  1198.         JLabel labelUsernamePerfil = new JLabel("Username:");
  1199.         GridBagConstraints gbc_labelUsernamePerfil = new GridBagConstraints();
  1200.         gbc_labelUsernamePerfil.anchor = GridBagConstraints.WEST;
  1201.         gbc_labelUsernamePerfil.insets = new Insets(0, 0, 5, 5);
  1202.         gbc_labelUsernamePerfil.gridx = 0;
  1203.         gbc_labelUsernamePerfil.gridy = 4;
  1204.         panelPerfil.add(labelUsernamePerfil, gbc_labelUsernamePerfil);
  1205.        
  1206.         textUsernamePerfil = new JTextField();
  1207.         textUsernamePerfil.setEditable(false);
  1208.         textUsernamePerfil.setColumns(10);
  1209.         GridBagConstraints gbc_textUsernamePerfil = new GridBagConstraints();
  1210.         gbc_textUsernamePerfil.fill = GridBagConstraints.HORIZONTAL;
  1211.         gbc_textUsernamePerfil.gridwidth = 3;
  1212.         gbc_textUsernamePerfil.insets = new Insets(0, 0, 5, 5);
  1213.         gbc_textUsernamePerfil.gridx = 1;
  1214.         gbc_textUsernamePerfil.gridy = 4;
  1215.         panelPerfil.add(textUsernamePerfil, gbc_textUsernamePerfil);
  1216.        
  1217.         JLabel labelPasswordPerfil = new JLabel("Password:");
  1218.         GridBagConstraints gbc_labelPasswordPerfil = new GridBagConstraints();
  1219.         gbc_labelPasswordPerfil.anchor = GridBagConstraints.WEST;
  1220.         gbc_labelPasswordPerfil.insets = new Insets(0, 0, 5, 5);
  1221.         gbc_labelPasswordPerfil.gridx = 0;
  1222.         gbc_labelPasswordPerfil.gridy = 5;
  1223.         panelPerfil.add(labelPasswordPerfil, gbc_labelPasswordPerfil);
  1224.        
  1225.         JButton btnEditarPassword = new JButton("Mudar  a palavra-passe");
  1226.         btnEditarPassword.addActionListener(new ActionListener() {
  1227.             public void actionPerformed(ActionEvent arg0) {
  1228.                 //Mudar para o painel de mudar password
  1229.                 frame.getContentPane().removeAll();
  1230.                 frame.getContentPane().add(panelPassword);
  1231.                 frame.revalidate();
  1232.                 frame.repaint();
  1233.             }
  1234.         });
  1235.         GridBagConstraints gbc_btnEditarPassword = new GridBagConstraints();
  1236.         gbc_btnEditarPassword.anchor = GridBagConstraints.WEST;
  1237.         gbc_btnEditarPassword.gridwidth = 2;
  1238.         gbc_btnEditarPassword.insets = new Insets(0, 0, 5, 5);
  1239.         gbc_btnEditarPassword.gridx = 1;
  1240.         gbc_btnEditarPassword.gridy = 5;
  1241.         panelPerfil.add(btnEditarPassword, gbc_btnEditarPassword);
  1242.        
  1243.         JLabel lblHistrico = new JLabel("Hist\u00F3rico");
  1244.         GridBagConstraints gbc_lblHistrico = new GridBagConstraints();
  1245.         gbc_lblHistrico.gridwidth = 5;
  1246.         gbc_lblHistrico.insets = new Insets(0, 0, 5, 5);
  1247.         gbc_lblHistrico.gridx = 5;
  1248.         gbc_lblHistrico.gridy = 5;
  1249.         panelPerfil.add(lblHistrico, gbc_lblHistrico);
  1250.        
  1251.         JLabel labelDataNascimentoPerfil = new JLabel("Data de Nascimento:");
  1252.         GridBagConstraints gbc_labelDataNascimentoPerfil = new GridBagConstraints();
  1253.         gbc_labelDataNascimentoPerfil.anchor = GridBagConstraints.WEST;
  1254.         gbc_labelDataNascimentoPerfil.insets = new Insets(0, 0, 5, 5);
  1255.         gbc_labelDataNascimentoPerfil.gridx = 0;
  1256.         gbc_labelDataNascimentoPerfil.gridy = 6;
  1257.         panelPerfil.add(labelDataNascimentoPerfil, gbc_labelDataNascimentoPerfil);
  1258.        
  1259.         textDataNascimentoPerfil = new JTextField();
  1260.         textDataNascimentoPerfil.setEditable(false);
  1261.         GridBagConstraints gbc_textDataNascimentoPerfil = new GridBagConstraints();
  1262.         gbc_textDataNascimentoPerfil.fill = GridBagConstraints.HORIZONTAL;
  1263.         gbc_textDataNascimentoPerfil.gridwidth = 3;
  1264.         gbc_textDataNascimentoPerfil.insets = new Insets(0, 0, 5, 5);
  1265.         gbc_textDataNascimentoPerfil.gridx = 1;
  1266.         gbc_textDataNascimentoPerfil.gridy = 6;
  1267.         panelPerfil.add(textDataNascimentoPerfil, gbc_textDataNascimentoPerfil);
  1268.        
  1269.         JList listaHistoricoPerfil = new JList();
  1270.         GridBagConstraints gbc_listaHistoricoPerfil = new GridBagConstraints();
  1271.         gbc_listaHistoricoPerfil.gridheight = 7;
  1272.         gbc_listaHistoricoPerfil.gridwidth = 5;
  1273.         gbc_listaHistoricoPerfil.insets = new Insets(0, 0, 5, 5);
  1274.         gbc_listaHistoricoPerfil.fill = GridBagConstraints.BOTH;
  1275.         gbc_listaHistoricoPerfil.gridx = 5;
  1276.         gbc_listaHistoricoPerfil.gridy = 6;
  1277.         panelPerfil.add(listaHistoricoPerfil, gbc_listaHistoricoPerfil);
  1278.        
  1279.         JLabel labelTipoSanguePerfil = new JLabel("Tipo de Sangue:");
  1280.         GridBagConstraints gbc_labelTipoSanguePerfil = new GridBagConstraints();
  1281.         gbc_labelTipoSanguePerfil.anchor = GridBagConstraints.WEST;
  1282.         gbc_labelTipoSanguePerfil.insets = new Insets(0, 0, 5, 5);
  1283.         gbc_labelTipoSanguePerfil.gridx = 0;
  1284.         gbc_labelTipoSanguePerfil.gridy = 7;
  1285.         panelPerfil.add(labelTipoSanguePerfil, gbc_labelTipoSanguePerfil);
  1286.        
  1287.         textTipoSanguePerfil = new JTextField();
  1288.         textTipoSanguePerfil.setEditable(false);
  1289.         GridBagConstraints gbc_textTipoSanguePerfil = new GridBagConstraints();
  1290.         gbc_textTipoSanguePerfil.gridwidth = 3;
  1291.         gbc_textTipoSanguePerfil.insets = new Insets(0, 0, 5, 5);
  1292.         gbc_textTipoSanguePerfil.fill = GridBagConstraints.HORIZONTAL;
  1293.         gbc_textTipoSanguePerfil.gridx = 1;
  1294.         gbc_textTipoSanguePerfil.gridy = 7;
  1295.         panelPerfil.add(textTipoSanguePerfil, gbc_textTipoSanguePerfil);
  1296.         textTipoSanguePerfil.setColumns(10);
  1297.        
  1298.         JLabel labelSexoPerfil = new JLabel("Sexo:");
  1299.         GridBagConstraints gbc_labelSexoPerfil = new GridBagConstraints();
  1300.         gbc_labelSexoPerfil.anchor = GridBagConstraints.WEST;
  1301.         gbc_labelSexoPerfil.insets = new Insets(0, 0, 5, 5);
  1302.         gbc_labelSexoPerfil.gridx = 0;
  1303.         gbc_labelSexoPerfil.gridy = 8;
  1304.         panelPerfil.add(labelSexoPerfil, gbc_labelSexoPerfil);
  1305.        
  1306.         textSexoPerfil = new JTextField();
  1307.         textSexoPerfil.setEditable(false);
  1308.         GridBagConstraints gbc_textSexoPerfil = new GridBagConstraints();
  1309.         gbc_textSexoPerfil.gridwidth = 3;
  1310.         gbc_textSexoPerfil.insets = new Insets(0, 0, 5, 5);
  1311.         gbc_textSexoPerfil.fill = GridBagConstraints.HORIZONTAL;
  1312.         gbc_textSexoPerfil.gridx = 1;
  1313.         gbc_textSexoPerfil.gridy = 8;
  1314.         panelPerfil.add(textSexoPerfil, gbc_textSexoPerfil);
  1315.         textSexoPerfil.setColumns(10);
  1316.        
  1317.         JLabel labelEmailPerfil = new JLabel("Email:");
  1318.         GridBagConstraints gbc_labelEmailPerfil = new GridBagConstraints();
  1319.         gbc_labelEmailPerfil.anchor = GridBagConstraints.WEST;
  1320.         gbc_labelEmailPerfil.insets = new Insets(0, 0, 5, 5);
  1321.         gbc_labelEmailPerfil.gridx = 0;
  1322.         gbc_labelEmailPerfil.gridy = 9;
  1323.         panelPerfil.add(labelEmailPerfil, gbc_labelEmailPerfil);
  1324.        
  1325.         textEmailPerfil = new JTextField();
  1326.         textEmailPerfil.setEditable(false);
  1327.         textEmailPerfil.setColumns(10);
  1328.         GridBagConstraints gbc_textEmailPerfil = new GridBagConstraints();
  1329.         gbc_textEmailPerfil.fill = GridBagConstraints.HORIZONTAL;
  1330.         gbc_textEmailPerfil.gridwidth = 3;
  1331.         gbc_textEmailPerfil.insets = new Insets(0, 0, 5, 5);
  1332.         gbc_textEmailPerfil.gridx = 1;
  1333.         gbc_textEmailPerfil.gridy = 9;
  1334.         panelPerfil.add(textEmailPerfil, gbc_textEmailPerfil);
  1335.        
  1336.         JLabel labelContactoPerfil = new JLabel("Contacto:");
  1337.         GridBagConstraints gbc_labelContactoPerfil = new GridBagConstraints();
  1338.         gbc_labelContactoPerfil.anchor = GridBagConstraints.WEST;
  1339.         gbc_labelContactoPerfil.insets = new Insets(0, 0, 5, 5);
  1340.         gbc_labelContactoPerfil.gridx = 0;
  1341.         gbc_labelContactoPerfil.gridy = 10;
  1342.         panelPerfil.add(labelContactoPerfil, gbc_labelContactoPerfil);
  1343.        
  1344.         textContactoPerfil = new JTextField();
  1345.         textContactoPerfil.setEditable(false);
  1346.         textContactoPerfil.setColumns(10);
  1347.         GridBagConstraints gbc_textContactoPerfil = new GridBagConstraints();
  1348.         gbc_textContactoPerfil.fill = GridBagConstraints.HORIZONTAL;
  1349.         gbc_textContactoPerfil.gridwidth = 3;
  1350.         gbc_textContactoPerfil.insets = new Insets(0, 0, 5, 5);
  1351.         gbc_textContactoPerfil.gridx = 1;
  1352.         gbc_textContactoPerfil.gridy = 10;
  1353.         panelPerfil.add(textContactoPerfil, gbc_textContactoPerfil);
  1354.        
  1355.         JLabel labelMoradaPerfil = new JLabel("Morada:");
  1356.         GridBagConstraints gbc_labelMoradaPerfil = new GridBagConstraints();
  1357.         gbc_labelMoradaPerfil.anchor = GridBagConstraints.WEST;
  1358.         gbc_labelMoradaPerfil.insets = new Insets(0, 0, 5, 5);
  1359.         gbc_labelMoradaPerfil.gridx = 0;
  1360.         gbc_labelMoradaPerfil.gridy = 11;
  1361.         panelPerfil.add(labelMoradaPerfil, gbc_labelMoradaPerfil);
  1362.        
  1363.         textMoradaPerfil = new JTextField();
  1364.         textMoradaPerfil.setEditable(false);
  1365.         textMoradaPerfil.setColumns(10);
  1366.         GridBagConstraints gbc_textMoradaPerfil = new GridBagConstraints();
  1367.         gbc_textMoradaPerfil.fill = GridBagConstraints.HORIZONTAL;
  1368.         gbc_textMoradaPerfil.gridwidth = 3;
  1369.         gbc_textMoradaPerfil.insets = new Insets(0, 0, 5, 5);
  1370.         gbc_textMoradaPerfil.gridx = 1;
  1371.         gbc_textMoradaPerfil.gridy = 11;
  1372.         panelPerfil.add(textMoradaPerfil, gbc_textMoradaPerfil);
  1373.        
  1374.         btnEditar = new JButton("Editar");
  1375.         btnEditar.addActionListener(new ActionListener() {
  1376.             public void actionPerformed(ActionEvent e) {
  1377.                 /** Botao Editar Perfil */
  1378.                 btnEditar.setEnabled(false);
  1379.                 btnGuardar.setEnabled(true);
  1380.                 //textUsernamePerfil.setEditable(true);
  1381.                 textNomePerfil.setEditable(true);
  1382.                 textApelidoPerfil.setEditable(true);
  1383.                 textEmailPerfil.setEditable(true);
  1384.                 textContactoPerfil.setEditable(true);
  1385.                 textMoradaPerfil.setEditable(true);
  1386.             }
  1387.         });
  1388.         GridBagConstraints gbc_btnEditar = new GridBagConstraints();
  1389.         gbc_btnEditar.insets = new Insets(0, 0, 0, 5);
  1390.         gbc_btnEditar.gridx = 1;
  1391.         gbc_btnEditar.gridy = 13;
  1392.         panelPerfil.add(btnEditar, gbc_btnEditar);
  1393.        
  1394.         btnGuardar = new JButton("Guardar");
  1395.         btnGuardar.addActionListener(new ActionListener() {
  1396.             public void actionPerformed(ActionEvent e) {
  1397.                 btnEditar.setEnabled(true);
  1398.                 btnGuardar.setEnabled(false);
  1399.                            
  1400.                 try {
  1401.                     Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
  1402.                     String nome =  textNomePerfil.getText();
  1403.                     String apelido = textApelidoPerfil.getText();
  1404.                     String email = textEmailPerfil.getText();
  1405.                     String contacto = textContactoPerfil.getText();
  1406.                     String morada = textMoradaPerfil.getText();
  1407.                    
  1408.                         PreparedStatement inst = lig.prepareStatement(
  1409.                                 "UPDATE cliente SET nome = ?, apelido = ?, email = ?, contacto = ?, morada = ? WHERE idCliente = '" + currentUserID + "'");
  1410.                         inst.setString(1, nome);
  1411.                         inst.setString(2, apelido);
  1412.                         inst.setString(3, email);
  1413.                         inst.setString(4, contacto);
  1414.                         inst.setString(5, morada);
  1415.                         int linhasAlteradas = inst.executeUpdate();
  1416.                         if (linhasAlteradas == 1) {
  1417.                             JOptionPane.showMessageDialog(null, "Perfil Atualizado");
  1418.                         } else {
  1419.                             JOptionPane.showMessageDialog(null, "Registo não atualizado");
  1420.                         }
  1421.                         lig.close();
  1422.                 }catch (SQLException ex) {
  1423.                     JOptionPane.showMessageDialog(frame, "Base de dados indisponivel: " + ex.getMessage());
  1424.                 }
  1425.                 //textUsernamePerfil.setEditable(false);
  1426.                 textNomePerfil.setEditable(false);
  1427.                 textApelidoPerfil.setEditable(false);
  1428.                 textEmailPerfil.setEditable(false);
  1429.                 textContactoPerfil.setEditable(false);
  1430.                 textMoradaPerfil.setEditable(false);
  1431.                 perfilSetup();
  1432.             }
  1433.         });
  1434.         btnGuardar.setEnabled(false);
  1435.         GridBagConstraints gbc_btnGuardar = new GridBagConstraints();
  1436.         gbc_btnGuardar.gridwidth = 6;
  1437.         gbc_btnGuardar.insets = new Insets(0, 0, 0, 5);
  1438.         gbc_btnGuardar.gridx = 2;
  1439.         gbc_btnGuardar.gridy = 13;
  1440.         panelPerfil.add(btnGuardar, gbc_btnGuardar);
  1441.        
  1442.         panelPassword = new JPanel();
  1443.         frame.getContentPane().add(panelPassword, "name_277697535854293");
  1444.         GridBagLayout gbl_panelPassword = new GridBagLayout();
  1445.         gbl_panelPassword.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  1446.         gbl_panelPassword.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
  1447.         gbl_panelPassword.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
  1448.         gbl_panelPassword.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
  1449.         panelPassword.setLayout(gbl_panelPassword);
  1450.        
  1451.         JLabel label = new JLabel("Login");
  1452.         GridBagConstraints gbc_label = new GridBagConstraints();
  1453.         gbc_label.gridwidth = 15;
  1454.         gbc_label.insets = new Insets(0, 0, 5, 0);
  1455.         gbc_label.gridx = 0;
  1456.         gbc_label.gridy = 0;
  1457.         panelPassword.add(label, gbc_label);
  1458.        
  1459.         Component verticalStrut_1 = Box.createVerticalStrut(20);
  1460.         GridBagConstraints gbc_verticalStrut_1 = new GridBagConstraints();
  1461.         gbc_verticalStrut_1.gridwidth = 2;
  1462.         gbc_verticalStrut_1.insets = new Insets(0, 0, 5, 5);
  1463.         gbc_verticalStrut_1.gridx = 7;
  1464.         gbc_verticalStrut_1.gridy = 1;
  1465.         panelPassword.add(verticalStrut_1, gbc_verticalStrut_1);
  1466.        
  1467.         Component horizontalStrut_12 = Box.createHorizontalStrut(20);
  1468.         GridBagConstraints gbc_horizontalStrut_12 = new GridBagConstraints();
  1469.         gbc_horizontalStrut_12.insets = new Insets(0, 0, 5, 5);
  1470.         gbc_horizontalStrut_12.gridx = 1;
  1471.         gbc_horizontalStrut_12.gridy = 2;
  1472.         panelPassword.add(horizontalStrut_12, gbc_horizontalStrut_12);
  1473.        
  1474.         Component horizontalStrut_13 = Box.createHorizontalStrut(20);
  1475.         GridBagConstraints gbc_horizontalStrut_13 = new GridBagConstraints();
  1476.         gbc_horizontalStrut_13.insets = new Insets(0, 0, 5, 5);
  1477.         gbc_horizontalStrut_13.gridx = 2;
  1478.         gbc_horizontalStrut_13.gridy = 2;
  1479.         panelPassword.add(horizontalStrut_13, gbc_horizontalStrut_13);
  1480.        
  1481.         Component horizontalStrut_14 = Box.createHorizontalStrut(20);
  1482.         GridBagConstraints gbc_horizontalStrut_14 = new GridBagConstraints();
  1483.         gbc_horizontalStrut_14.insets = new Insets(0, 0, 5, 5);
  1484.         gbc_horizontalStrut_14.gridx = 3;
  1485.         gbc_horizontalStrut_14.gridy = 2;
  1486.         panelPassword.add(horizontalStrut_14, gbc_horizontalStrut_14);
  1487.        
  1488.         Component horizontalStrut_15 = Box.createHorizontalStrut(20);
  1489.         GridBagConstraints gbc_horizontalStrut_15 = new GridBagConstraints();
  1490.         gbc_horizontalStrut_15.insets = new Insets(0, 0, 5, 5);
  1491.         gbc_horizontalStrut_15.gridx = 4;
  1492.         gbc_horizontalStrut_15.gridy = 2;
  1493.         panelPassword.add(horizontalStrut_15, gbc_horizontalStrut_15);
  1494.        
  1495.         Component horizontalStrut_16 = Box.createHorizontalStrut(20);
  1496.         GridBagConstraints gbc_horizontalStrut_16 = new GridBagConstraints();
  1497.         gbc_horizontalStrut_16.insets = new Insets(0, 0, 5, 5);
  1498.         gbc_horizontalStrut_16.gridx = 5;
  1499.         gbc_horizontalStrut_16.gridy = 2;
  1500.         panelPassword.add(horizontalStrut_16, gbc_horizontalStrut_16);
  1501.        
  1502.         JLabel labelOldPassword = new JLabel("Password antiga:");
  1503.         GridBagConstraints gbc_labelOldPassword = new GridBagConstraints();
  1504.         gbc_labelOldPassword.anchor = GridBagConstraints.EAST;
  1505.         gbc_labelOldPassword.insets = new Insets(0, 0, 5, 5);
  1506.         gbc_labelOldPassword.gridx = 6;
  1507.         gbc_labelOldPassword.gridy = 2;
  1508.         panelPassword.add(labelOldPassword, gbc_labelOldPassword);
  1509.        
  1510.         passwordVelha = new JTextField();
  1511.         passwordVelha.setColumns(10);
  1512.         GridBagConstraints gbc_passwordVelha = new GridBagConstraints();
  1513.         gbc_passwordVelha.fill = GridBagConstraints.HORIZONTAL;
  1514.         gbc_passwordVelha.gridwidth = 2;
  1515.         gbc_passwordVelha.insets = new Insets(0, 0, 5, 5);
  1516.         gbc_passwordVelha.gridx = 7;
  1517.         gbc_passwordVelha.gridy = 2;
  1518.         panelPassword.add(passwordVelha, gbc_passwordVelha);
  1519.        
  1520.         Component horizontalStrut_17 = Box.createHorizontalStrut(20);
  1521.         GridBagConstraints gbc_horizontalStrut_17 = new GridBagConstraints();
  1522.         gbc_horizontalStrut_17.insets = new Insets(0, 0, 5, 5);
  1523.         gbc_horizontalStrut_17.gridx = 10;
  1524.         gbc_horizontalStrut_17.gridy = 2;
  1525.         panelPassword.add(horizontalStrut_17, gbc_horizontalStrut_17);
  1526.        
  1527.         Component horizontalStrut_18 = Box.createHorizontalStrut(20);
  1528.         GridBagConstraints gbc_horizontalStrut_18 = new GridBagConstraints();
  1529.         gbc_horizontalStrut_18.insets = new Insets(0, 0, 5, 5);
  1530.         gbc_horizontalStrut_18.gridx = 11;
  1531.         gbc_horizontalStrut_18.gridy = 2;
  1532.         panelPassword.add(horizontalStrut_18, gbc_horizontalStrut_18);
  1533.        
  1534.         Component horizontalStrut_19 = Box.createHorizontalStrut(20);
  1535.         GridBagConstraints gbc_horizontalStrut_19 = new GridBagConstraints();
  1536.         gbc_horizontalStrut_19.insets = new Insets(0, 0, 5, 5);
  1537.         gbc_horizontalStrut_19.gridx = 12;
  1538.         gbc_horizontalStrut_19.gridy = 2;
  1539.         panelPassword.add(horizontalStrut_19, gbc_horizontalStrut_19);
  1540.        
  1541.         Component horizontalStrut_20 = Box.createHorizontalStrut(20);
  1542.         GridBagConstraints gbc_horizontalStrut_20 = new GridBagConstraints();
  1543.         gbc_horizontalStrut_20.insets = new Insets(0, 0, 5, 5);
  1544.         gbc_horizontalStrut_20.gridx = 13;
  1545.         gbc_horizontalStrut_20.gridy = 2;
  1546.         panelPassword.add(horizontalStrut_20, gbc_horizontalStrut_20);
  1547.        
  1548.         Component horizontalStrut_21 = Box.createHorizontalStrut(20);
  1549.         GridBagConstraints gbc_horizontalStrut_21 = new GridBagConstraints();
  1550.         gbc_horizontalStrut_21.insets = new Insets(0, 0, 5, 0);
  1551.         gbc_horizontalStrut_21.gridx = 14;
  1552.         gbc_horizontalStrut_21.gridy = 2;
  1553.         panelPassword.add(horizontalStrut_21, gbc_horizontalStrut_21);
  1554.        
  1555.         Component verticalStrut_2 = Box.createVerticalStrut(20);
  1556.         GridBagConstraints gbc_verticalStrut_2 = new GridBagConstraints();
  1557.         gbc_verticalStrut_2.insets = new Insets(0, 0, 5, 5);
  1558.         gbc_verticalStrut_2.gridx = 7;
  1559.         gbc_verticalStrut_2.gridy = 3;
  1560.         panelPassword.add(verticalStrut_2, gbc_verticalStrut_2);
  1561.        
  1562.         JLabel labelNewPassword = new JLabel("Password nova:");
  1563.         GridBagConstraints gbc_labelNewPassword = new GridBagConstraints();
  1564.         gbc_labelNewPassword.anchor = GridBagConstraints.EAST;
  1565.         gbc_labelNewPassword.insets = new Insets(0, 0, 5, 5);
  1566.         gbc_labelNewPassword.gridx = 6;
  1567.         gbc_labelNewPassword.gridy = 4;
  1568.         panelPassword.add(labelNewPassword, gbc_labelNewPassword);
  1569.        
  1570.         passwordNova = new JTextField();
  1571.         passwordNova.setColumns(10);
  1572.         GridBagConstraints gbc_passwordNova = new GridBagConstraints();
  1573.         gbc_passwordNova.fill = GridBagConstraints.HORIZONTAL;
  1574.         gbc_passwordNova.gridwidth = 2;
  1575.         gbc_passwordNova.insets = new Insets(0, 0, 5, 5);
  1576.         gbc_passwordNova.gridx = 7;
  1577.         gbc_passwordNova.gridy = 4;
  1578.         panelPassword.add(passwordNova, gbc_passwordNova);
  1579.        
  1580.         JLabel lblConfirmarPassword = new JLabel("Confirmar password:");
  1581.         GridBagConstraints gbc_lblConfirmarPassword = new GridBagConstraints();
  1582.         gbc_lblConfirmarPassword.anchor = GridBagConstraints.EAST;
  1583.         gbc_lblConfirmarPassword.insets = new Insets(0, 0, 5, 5);
  1584.         gbc_lblConfirmarPassword.gridx = 6;
  1585.         gbc_lblConfirmarPassword.gridy = 5;
  1586.         panelPassword.add(lblConfirmarPassword, gbc_lblConfirmarPassword);
  1587.        
  1588.         passwordConfirmar = new JTextField();
  1589.         passwordConfirmar.setColumns(10);
  1590.         GridBagConstraints gbc_passwordConfirmar = new GridBagConstraints();
  1591.         gbc_passwordConfirmar.gridwidth = 2;
  1592.         gbc_passwordConfirmar.insets = new Insets(0, 0, 5, 5);
  1593.         gbc_passwordConfirmar.fill = GridBagConstraints.HORIZONTAL;
  1594.         gbc_passwordConfirmar.gridx = 7;
  1595.         gbc_passwordConfirmar.gridy = 5;
  1596.         panelPassword.add(passwordConfirmar, gbc_passwordConfirmar);
  1597.        
  1598.         Component verticalStrut_3 = Box.createVerticalStrut(20);
  1599.         GridBagConstraints gbc_verticalStrut_3 = new GridBagConstraints();
  1600.         gbc_verticalStrut_3.insets = new Insets(0, 0, 5, 5);
  1601.         gbc_verticalStrut_3.gridx = 8;
  1602.         gbc_verticalStrut_3.gridy = 6;
  1603.         panelPassword.add(verticalStrut_3, gbc_verticalStrut_3);
  1604.        
  1605.         JButton btnMudarPassword = new JButton("Confirmar");
  1606.         btnMudarPassword.addActionListener(new ActionListener() {
  1607.             public void actionPerformed(ActionEvent e) {
  1608.                 //Mudar password
  1609.                 String passwordVelha1 = passwordVelha.getText();
  1610.                 String passwordNova1 = passwordNova.getText();
  1611.                 String passwordConfirmar1 = passwordConfirmar.getText();
  1612.                 //comparar  as 2 passwords
  1613.                 if(passwordNova1.equals(passwordConfirmar1)) {
  1614.                    
  1615.                     //comparar a password velha com a da base de dados
  1616.                     try {
  1617.                         Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
  1618.                         Statement inst = lig.createStatement();
  1619.                         ResultSet resultado = inst
  1620.                                 .executeQuery("select palavraChave, idCliente FROM cliente where idCliente = '" + currentUserID + "'");
  1621.                         while (resultado.next()) {
  1622.                             String passworddb = resultado.getString("palavraChave");
  1623.                            
  1624.                             if(passwordVelha1.equals(passworddb)) {
  1625.                                 PreparedStatement instPassword = lig.prepareStatement(
  1626.                                         "UPDATE cliente SET palavraChave = ? WHERE idCliente = '" + currentUserID + "'");
  1627.                                 instPassword.setString(1, passwordNova1);
  1628.                                 int linhasAlteradas = instPassword.executeUpdate();
  1629.                                 if (linhasAlteradas == 1) {
  1630.                                     JOptionPane.showMessageDialog(null, "Palavra-Passe atualizada");
  1631.                                    
  1632.                                     //volta para o perfil
  1633.                                     frame.getContentPane().removeAll();
  1634.                                     frame.getContentPane().add(panelPerfil);
  1635.                                     frame.revalidate();
  1636.                                     frame.repaint();
  1637.                                 } else {
  1638.                                     JOptionPane.showMessageDialog(null, "Palavra-Passe não atualizada");
  1639.                                 }
  1640.                                
  1641.                             }
  1642.                             else {
  1643.                                 JOptionPane.showMessageDialog(null, "A palavra-Passe não corresponde à antiga.");
  1644.                                 passwordLogin.setText("");
  1645.                             }
  1646.                         }
  1647.                         lig.close();
  1648.                     } catch (SQLException ex) {
  1649.                         JOptionPane.showMessageDialog(null, "BD indísponivel! \n" + ex.getMessage());
  1650.                     }
  1651.                 }
  1652.                 else {
  1653.                     JOptionPane.showMessageDialog(null, "As palavras-Passe não correspondem.");
  1654.                 }
  1655.                 passwordVelha.setText("");
  1656.                 passwordNova.setText("");
  1657.                 passwordConfirmar.setText("");
  1658.                
  1659.             }
  1660.         });
  1661.         GridBagConstraints gbc_btnMudarPassword = new GridBagConstraints();
  1662.         gbc_btnMudarPassword.gridwidth = 15;
  1663.         gbc_btnMudarPassword.insets = new Insets(0, 0, 0, 5);
  1664.         gbc_btnMudarPassword.gridx = 0;
  1665.         gbc_btnMudarPassword.gridy = 7;
  1666.         panelPassword.add(btnMudarPassword, gbc_btnMudarPassword);
  1667.        
  1668.         panelMensagem = new JPanel();
  1669.         frame.getContentPane().add(panelMensagem, "name_947820898540649");
  1670.         GridBagLayout gbl_panelMensagem = new GridBagLayout();
  1671.         gbl_panelMensagem.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
  1672.         gbl_panelMensagem.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
  1673.         gbl_panelMensagem.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
  1674.         gbl_panelMensagem.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
  1675.         panelMensagem.setLayout(gbl_panelMensagem);
  1676.        
  1677.         JLabel lblMensagem = new JLabel("Mensagem");
  1678.         GridBagConstraints gbc_lblMensagem = new GridBagConstraints();
  1679.         gbc_lblMensagem.gridwidth = 5;
  1680.         gbc_lblMensagem.insets = new Insets(0, 0, 5, 5);
  1681.         gbc_lblMensagem.gridx = 1;
  1682.         gbc_lblMensagem.gridy = 0;
  1683.         panelMensagem.add(lblMensagem, gbc_lblMensagem);
  1684.        
  1685.         comboBoxDestinatario = new JComboBox();
  1686.         comboBoxDestinatario.setModel(new DefaultComboBoxModel(new String[] {"M\u00E9dico", "Cliente"}));
  1687.         GridBagConstraints gbc_comboBoxDestinatario = new GridBagConstraints();
  1688.         gbc_comboBoxDestinatario.insets = new Insets(0, 0, 5, 5);
  1689.         gbc_comboBoxDestinatario.fill = GridBagConstraints.HORIZONTAL;
  1690.         gbc_comboBoxDestinatario.gridx = 2;
  1691.         gbc_comboBoxDestinatario.gridy = 1;
  1692.         panelMensagem.add(comboBoxDestinatario, gbc_comboBoxDestinatario);
  1693.        
  1694.         comboBoxIdentificador = new JComboBox();
  1695.         comboBoxIdentificador.setModel(new DefaultComboBoxModel(new String[] {"ID", "Username"}));
  1696.         GridBagConstraints gbc_comboBoxIdentificador = new GridBagConstraints();
  1697.         gbc_comboBoxIdentificador.insets = new Insets(0, 0, 5, 5);
  1698.         gbc_comboBoxIdentificador.fill = GridBagConstraints.HORIZONTAL;
  1699.         gbc_comboBoxIdentificador.gridx = 3;
  1700.         gbc_comboBoxIdentificador.gridy = 1;
  1701.         panelMensagem.add(comboBoxIdentificador, gbc_comboBoxIdentificador);
  1702.        
  1703.         JComboBox comboBoxCategoria = new JComboBox();
  1704.         comboBoxCategoria.setModel(new DefaultComboBoxModel(new String[] {"Mensagem", "Exames", "Consultas", "Relat\u00F3rios"}));
  1705.         GridBagConstraints gbc_comboBoxCategoria = new GridBagConstraints();
  1706.         gbc_comboBoxCategoria.insets = new Insets(0, 0, 5, 5);
  1707.         gbc_comboBoxCategoria.fill = GridBagConstraints.HORIZONTAL;
  1708.         gbc_comboBoxCategoria.gridx = 4;
  1709.         gbc_comboBoxCategoria.gridy = 1;
  1710.         panelMensagem.add(comboBoxCategoria, gbc_comboBoxCategoria);
  1711.        
  1712.         JLabel lblDestinatrio = new JLabel("Destinat\u00E1rio:");
  1713.         GridBagConstraints gbc_lblDestinatrio = new GridBagConstraints();
  1714.         gbc_lblDestinatrio.anchor = GridBagConstraints.WEST;
  1715.         gbc_lblDestinatrio.insets = new Insets(0, 0, 5, 5);
  1716.         gbc_lblDestinatrio.gridx = 1;
  1717.         gbc_lblDestinatrio.gridy = 2;
  1718.         panelMensagem.add(lblDestinatrio, gbc_lblDestinatrio);
  1719.        
  1720.         textDestinatario = new JTextField();
  1721.         GridBagConstraints gbc_textDestinatario = new GridBagConstraints();
  1722.         gbc_textDestinatario.gridwidth = 2;
  1723.         gbc_textDestinatario.insets = new Insets(0, 0, 5, 5);
  1724.         gbc_textDestinatario.fill = GridBagConstraints.HORIZONTAL;
  1725.         gbc_textDestinatario.gridx = 2;
  1726.         gbc_textDestinatario.gridy = 2;
  1727.         panelMensagem.add(textDestinatario, gbc_textDestinatario);
  1728.         textDestinatario.setColumns(10);
  1729.        
  1730.         Component horizontalStrut_32 = Box.createHorizontalStrut(20);
  1731.         GridBagConstraints gbc_horizontalStrut_32 = new GridBagConstraints();
  1732.         gbc_horizontalStrut_32.insets = new Insets(0, 0, 5, 5);
  1733.         gbc_horizontalStrut_32.gridx = 0;
  1734.         gbc_horizontalStrut_32.gridy = 3;
  1735.         panelMensagem.add(horizontalStrut_32, gbc_horizontalStrut_32);
  1736.        
  1737.         JLabel lblAssunto = new JLabel("Assunto:");
  1738.         GridBagConstraints gbc_lblAssunto = new GridBagConstraints();
  1739.         gbc_lblAssunto.anchor = GridBagConstraints.EAST;
  1740.         gbc_lblAssunto.insets = new Insets(0, 0, 5, 5);
  1741.         gbc_lblAssunto.gridx = 1;
  1742.         gbc_lblAssunto.gridy = 3;
  1743.         panelMensagem.add(lblAssunto, gbc_lblAssunto);
  1744.        
  1745.         textAssunto = new JTextField();
  1746.         GridBagConstraints gbc_textAssunto = new GridBagConstraints();
  1747.         gbc_textAssunto.gridwidth = 4;
  1748.         gbc_textAssunto.insets = new Insets(0, 0, 5, 5);
  1749.         gbc_textAssunto.fill = GridBagConstraints.HORIZONTAL;
  1750.         gbc_textAssunto.gridx = 2;
  1751.         gbc_textAssunto.gridy = 3;
  1752.         panelMensagem.add(textAssunto, gbc_textAssunto);
  1753.         textAssunto.setColumns(10);
  1754.        
  1755.         JLabel lblCorpo = new JLabel("Corpo:");
  1756.         GridBagConstraints gbc_lblCorpo = new GridBagConstraints();
  1757.         gbc_lblCorpo.anchor = GridBagConstraints.EAST;
  1758.         gbc_lblCorpo.insets = new Insets(0, 0, 5, 5);
  1759.         gbc_lblCorpo.gridx = 1;
  1760.         gbc_lblCorpo.gridy = 4;
  1761.         panelMensagem.add(lblCorpo, gbc_lblCorpo);
  1762.        
  1763.         Component horizontalStrut_33 = Box.createHorizontalStrut(20);
  1764.         GridBagConstraints gbc_horizontalStrut_33 = new GridBagConstraints();
  1765.         gbc_horizontalStrut_33.insets = new Insets(0, 0, 5, 0);
  1766.         gbc_horizontalStrut_33.gridx = 6;
  1767.         gbc_horizontalStrut_33.gridy = 4;
  1768.         panelMensagem.add(horizontalStrut_33, gbc_horizontalStrut_33);
  1769.        
  1770.         JScrollPane scrollPaneMensagem = new JScrollPane();
  1771.         GridBagConstraints gbc_scrollPaneMensagem = new GridBagConstraints();
  1772.         gbc_scrollPaneMensagem.gridwidth = 4;
  1773.         gbc_scrollPaneMensagem.insets = new Insets(0, 0, 5, 5);
  1774.         gbc_scrollPaneMensagem.fill = GridBagConstraints.BOTH;
  1775.         gbc_scrollPaneMensagem.gridx = 2;
  1776.         gbc_scrollPaneMensagem.gridy = 5;
  1777.         panelMensagem.add(scrollPaneMensagem, gbc_scrollPaneMensagem);
  1778.        
  1779.         textCorpo = new JTextPane();
  1780.         scrollPaneMensagem.setViewportView(textCorpo);
  1781.        
  1782.         JButton btnEnviar = new JButton("Enviar");
  1783.         btnEnviar.addActionListener(new ActionListener() {
  1784.             public void actionPerformed(ActionEvent e) {
  1785.                 //Definir variaveis
  1786.                 String tipoDestinatario = (String) comboBoxDestinatario.getSelectedItem();
  1787.                 String identificador = (String) comboBoxIdentificador.getSelectedItem();
  1788.                 String categoria = (String) comboBoxCategoria.getSelectedItem();
  1789.                 String destinatario = textDestinatario.getText();
  1790.                 String assunto = textAssunto.getText();
  1791.                 String corpo = textCorpo.getText();
  1792.                 java.sql.Timestamp data = new java.sql.Timestamp(new java.util.Date().getTime());
  1793.                 int id_mail_cliente_medico  = 0;
  1794.                 int id_mail_cliente_cliente = 0;
  1795.                
  1796.                 //obter os ids dos mails
  1797.                 try {
  1798.                     Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
  1799.                     PreparedStatement inst = lig.prepareStatement("SELECT MAX(emailID) FROM mail_cliente_medico");
  1800.                     ResultSet res = inst.executeQuery();
  1801.                     if (res.next()) {
  1802.                         id_mail_cliente_medico = res.getInt("MAX(emailID)") +1;
  1803.                     }
  1804.                 } catch (SQLException ex) {
  1805.                     JOptionPane.showMessageDialog(frame, "BD indisponível!" + ex.getMessage());
  1806.                 }
  1807.                
  1808.                 try {
  1809.                     Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
  1810.                     PreparedStatement inst = lig.prepareStatement("SELECT MAX(emailID) FROM mail_cliente_cliente");
  1811.                     ResultSet res = inst.executeQuery();
  1812.                     if (res.next()) {
  1813.                         id_mail_cliente_cliente = res.getInt("MAX(emailID)") + 1;
  1814.                         JOptionPane.showMessageDialog(null,id_mail_cliente_cliente + "      " + res.getInt("MAX(emailID)") );
  1815.                     }
  1816.                 } catch (SQLException ex) {
  1817.                     JOptionPane.showMessageDialog(frame, "BD indisponível!" + ex.getMessage());
  1818.                 }
  1819.                
  1820.                 //ligação à base de dados
  1821.                 try {
  1822.                     Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
  1823.                    
  1824.                     //se o destinatario for medico
  1825.                     if(tipoDestinatario == "Médico") {
  1826.                         if(identificador == "ID") {
  1827.                             PreparedStatement inst = lig.prepareStatement(
  1828.                                     "INSERT INTO mail_cliente_medico (Medico_ID, Cliente_idCliente, assunto, conteudo, categoria, data, emailID) VALUES(?, ?, ?, ?, ?, ?, ?);");
  1829.                             inst.setString(1, destinatario);
  1830.                             inst.setInt(2, currentUserID);
  1831.                             inst.setString(3, assunto);
  1832.                             inst.setString(4, corpo);
  1833.                             inst.setString(5, categoria);
  1834.                             inst.setTimestamp(6, data);
  1835.                             inst.setInt(7, id_mail_cliente_medico);
  1836.                             int linhasAlteradas = inst.executeUpdate();
  1837.                             if (linhasAlteradas == 1) {
  1838.                                 JOptionPane.showMessageDialog(null, "Mensagem Enviada");
  1839.                             } else {
  1840.                                 JOptionPane.showMessageDialog(null, "Mensagem não enviada");
  1841.                             }
  1842.                             lig.close();
  1843.                             textDestinatario.setText("");
  1844.                             textAssunto.setText("");
  1845.                             textCorpo.setText("");
  1846.                         }
  1847.                         else {
  1848.                             Statement inst1 = lig.createStatement();
  1849.                             String medicoID = "";
  1850.                             ResultSet resultado = inst1.executeQuery("select ID FROM medico where username = '" + destinatario + "'");
  1851.                             while (resultado.next()) {
  1852.                                 medicoID = resultado.getString("ID");
  1853.                             }
  1854.                            
  1855.                             PreparedStatement inst2 = lig.prepareStatement(
  1856.                                     "INSERT INTO mail_cliente_medico (Medico_ID, Cliente_idCliente, assunto, conteudo, categoria, data, emailID) VALUES(?, ?, ?, ?, ?, ?, ?);");
  1857.                             inst2.setString(1, medicoID);
  1858.                             inst2.setInt(2, currentUserID);
  1859.                             inst2.setString(3, assunto);
  1860.                             inst2.setString(4, corpo);
  1861.                             inst2.setString(5, categoria);
  1862.                             inst2.setTimestamp(6, data);
  1863.                             inst2.setInt(7, id_mail_cliente_medico);
  1864.                             int linhasAlteradas = inst2.executeUpdate();
  1865.                             if (linhasAlteradas == 1) {
  1866.                                 JOptionPane.showMessageDialog(null, "Mensagem Enviada");
  1867.                             } else {
  1868.                                 JOptionPane.showMessageDialog(null, "Mensagem não enviada");
  1869.                             }
  1870.                             lig.close();
  1871.                             textDestinatario.setText("");
  1872.                             textAssunto.setText("");
  1873.                             textCorpo.setText("");
  1874.                            
  1875.                         }
  1876.                     }
  1877.                     //se o destinatario for outro cliente
  1878.                     else {
  1879.                        
  1880.                         if(identificador == "ID") {
  1881.                             PreparedStatement inst = lig.prepareStatement(
  1882.                                     "INSERT INTO mail_cliente_cliente (destino_idCliente, origem_idCliente, assunto, conteudo, categoria, data, emailID) VALUES(?, ?, ?, ?, ?, ?, ?);");
  1883.                             inst.setString(1, destinatario);
  1884.                             inst.setInt(2, currentUserID);
  1885.                             inst.setString(3, assunto);
  1886.                             inst.setString(4, corpo);
  1887.                             inst.setString(5, categoria);
  1888.                             inst.setTimestamp(6, data);
  1889.                             inst.setInt(7, id_mail_cliente_cliente);
  1890.                             int linhasAlteradas = inst.executeUpdate();
  1891.                             if (linhasAlteradas == 1) {
  1892.                                 JOptionPane.showMessageDialog(null, "Mensagem Enviada");
  1893.                             } else {
  1894.                                 JOptionPane.showMessageDialog(null, "Mensagem não enviada");
  1895.                             }
  1896.                             lig.close();
  1897.                             textDestinatario.setText("");
  1898.                             textAssunto.setText("");
  1899.                             textCorpo.setText("");
  1900.                         }
  1901.                         else {
  1902.                             Statement inst1 = lig.createStatement();
  1903.                             String clienteID = "";
  1904.                             ResultSet resultado = inst1.executeQuery("select idCLiente FROM cliente where username = '" + destinatario + "'");
  1905.                             while (resultado.next()) {
  1906.                                 clienteID = resultado.getString("idCliente");
  1907.                             }
  1908.                            
  1909.                             PreparedStatement inst2 = lig.prepareStatement(
  1910.                                     "INSERT INTO mail_cliente_cliente (destino_idCliente, origem_idCliente, assunto, conteudo, categoria, data, emailID) VALUES(?, ?, ?, ?, ?, ?, ?);");
  1911.                             inst2.setString(1, clienteID);
  1912.                             inst2.setInt(2, currentUserID);
  1913.                             inst2.setString(3, assunto);
  1914.                             inst2.setString(4, corpo);
  1915.                             inst2.setString(5, categoria);
  1916.                             inst2.setTimestamp(6, data);
  1917.                             inst2.setInt(7, id_mail_cliente_cliente);
  1918.                             int linhasAlteradas = inst2.executeUpdate();
  1919.                             if (linhasAlteradas == 1) {
  1920.                                 JOptionPane.showMessageDialog(null, "Mensagem Enviada");
  1921.                             } else {
  1922.                                 JOptionPane.showMessageDialog(null, "Mensagem não enviada");
  1923.                             }
  1924.                             lig.close();
  1925.                             textDestinatario.setText("");
  1926.                             textAssunto.setText("");
  1927.                             textCorpo.setText("");
  1928.                         }
  1929.                        
  1930.                        
  1931.                        
  1932.                     }
  1933.                 }catch (SQLException ex) {
  1934.                     JOptionPane.showMessageDialog(frame, "Base de dados indisponivel: " + ex.getMessage());
  1935.                 }
  1936.                
  1937.             }
  1938.         });
  1939.         GridBagConstraints gbc_btnEnviar = new GridBagConstraints();
  1940.         gbc_btnEnviar.gridwidth = 5;
  1941.         gbc_btnEnviar.insets = new Insets(0, 0, 0, 5);
  1942.         gbc_btnEnviar.gridx = 1;
  1943.         gbc_btnEnviar.gridy = 6;
  1944.         panelMensagem.add(btnEnviar, gbc_btnEnviar);
  1945.        
  1946.         JPanel panelInbox = new JPanel();
  1947.         frame.getContentPane().add(panelInbox, "name_947822139102008");
  1948.         GridBagLayout gbl_panelInbox = new GridBagLayout();
  1949.         gbl_panelInbox.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  1950.         gbl_panelInbox.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0};
  1951.         gbl_panelInbox.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
  1952.         gbl_panelInbox.rowWeights = new double[]{0.0, 0.0, 0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
  1953.         panelInbox.setLayout(gbl_panelInbox);
  1954.        
  1955.         JLabel lblFiltro = new JLabel("Filtro:");
  1956.         GridBagConstraints gbc_lblFiltro = new GridBagConstraints();
  1957.         gbc_lblFiltro.insets = new Insets(0, 0, 5, 5);
  1958.         gbc_lblFiltro.gridx = 1;
  1959.         gbc_lblFiltro.gridy = 1;
  1960.         panelInbox.add(lblFiltro, gbc_lblFiltro);
  1961.        
  1962.         Component horizontalStrut_34 = Box.createHorizontalStrut(20);
  1963.         GridBagConstraints gbc_horizontalStrut_34 = new GridBagConstraints();
  1964.         gbc_horizontalStrut_34.insets = new Insets(0, 0, 5, 5);
  1965.         gbc_horizontalStrut_34.gridx = 2;
  1966.         gbc_horizontalStrut_34.gridy = 1;
  1967.         panelInbox.add(horizontalStrut_34, gbc_horizontalStrut_34);
  1968.        
  1969.         JLabel labelFiltroOrigem = new JLabel("Origem:");
  1970.         GridBagConstraints gbc_labelFiltroOrigem = new GridBagConstraints();
  1971.         gbc_labelFiltroOrigem.insets = new Insets(0, 0, 5, 5);
  1972.         gbc_labelFiltroOrigem.anchor = GridBagConstraints.EAST;
  1973.         gbc_labelFiltroOrigem.gridx = 3;
  1974.         gbc_labelFiltroOrigem.gridy = 1;
  1975.         panelInbox.add(labelFiltroOrigem, gbc_labelFiltroOrigem);
  1976.        
  1977.         comboBoxFiltroOrigem = new JComboBox();
  1978.         comboBoxFiltroOrigem.setModel(new DefaultComboBoxModel(new String[] {"Clientes", "M\u00E9dicos"}));
  1979.         GridBagConstraints gbc_comboBoxFiltroOrigem = new GridBagConstraints();
  1980.         gbc_comboBoxFiltroOrigem.insets = new Insets(0, 0, 5, 5);
  1981.         gbc_comboBoxFiltroOrigem.fill = GridBagConstraints.HORIZONTAL;
  1982.         gbc_comboBoxFiltroOrigem.gridx = 4;
  1983.         gbc_comboBoxFiltroOrigem.gridy = 1;
  1984.         panelInbox.add(comboBoxFiltroOrigem, gbc_comboBoxFiltroOrigem);
  1985.        
  1986.         Component horizontalStrut_35 = Box.createHorizontalStrut(20);
  1987.         GridBagConstraints gbc_horizontalStrut_35 = new GridBagConstraints();
  1988.         gbc_horizontalStrut_35.insets = new Insets(0, 0, 5, 5);
  1989.         gbc_horizontalStrut_35.gridx = 5;
  1990.         gbc_horizontalStrut_35.gridy = 1;
  1991.         panelInbox.add(horizontalStrut_35, gbc_horizontalStrut_35);
  1992.        
  1993.         JLabel lblCategoriaFiltro = new JLabel("Categoria:");
  1994.         GridBagConstraints gbc_lblCategoriaFiltro = new GridBagConstraints();
  1995.         gbc_lblCategoriaFiltro.anchor = GridBagConstraints.EAST;
  1996.         gbc_lblCategoriaFiltro.insets = new Insets(0, 0, 5, 5);
  1997.         gbc_lblCategoriaFiltro.gridx = 6;
  1998.         gbc_lblCategoriaFiltro.gridy = 1;
  1999.         panelInbox.add(lblCategoriaFiltro, gbc_lblCategoriaFiltro);
  2000.        
  2001.         comboBoxFiltroCategoria = new JComboBox();
  2002.         comboBoxFiltroCategoria.setModel(new DefaultComboBoxModel(new String[] {"Todas", "Mensagem", "Exames", "Consultas", "Relat\u00F3rios"}));
  2003.         GridBagConstraints gbc_comboBoxFiltroCategoria = new GridBagConstraints();
  2004.         gbc_comboBoxFiltroCategoria.insets = new Insets(0, 0, 5, 5);
  2005.         gbc_comboBoxFiltroCategoria.fill = GridBagConstraints.HORIZONTAL;
  2006.         gbc_comboBoxFiltroCategoria.gridx = 7;
  2007.         gbc_comboBoxFiltroCategoria.gridy = 1;
  2008.         panelInbox.add(comboBoxFiltroCategoria, gbc_comboBoxFiltroCategoria);
  2009.        
  2010.         Component horizontalStrut_36 = Box.createHorizontalStrut(20);
  2011.         GridBagConstraints gbc_horizontalStrut_36 = new GridBagConstraints();
  2012.         gbc_horizontalStrut_36.insets = new Insets(0, 0, 5, 5);
  2013.         gbc_horizontalStrut_36.gridx = 0;
  2014.         gbc_horizontalStrut_36.gridy = 3;
  2015.         panelInbox.add(horizontalStrut_36, gbc_horizontalStrut_36);
  2016.        
  2017.         JScrollPane scrollPane = new JScrollPane();
  2018.         GridBagConstraints gbc_scrollPane = new GridBagConstraints();
  2019.         gbc_scrollPane.gridwidth = 13;
  2020.         gbc_scrollPane.insets = new Insets(0, 0, 5, 5);
  2021.         gbc_scrollPane.fill = GridBagConstraints.BOTH;
  2022.         gbc_scrollPane.gridx = 1;
  2023.         gbc_scrollPane.gridy = 3;
  2024.         panelInbox.add(scrollPane, gbc_scrollPane);
  2025.        
  2026.         tableMensagem = new JTable();
  2027.         tableMensagem.setModel(modeloInbox = new DefaultTableModel(
  2028.             new Object[][] {
  2029.             },
  2030.             new String[] {
  2031.                 "ID", "Nome", "Categoria", "Assunto", "Data"
  2032.             }
  2033.         ) {
  2034.             Class[] columnTypes = new Class[] {
  2035.                 String.class, String.class, String.class, String.class, String.class
  2036.             };
  2037.             public Class getColumnClass(int columnIndex) {
  2038.                 return columnTypes[columnIndex];
  2039.             }
  2040.         });
  2041.         tableMensagem.getColumnModel().getColumn(0).setPreferredWidth(40);
  2042.         tableMensagem.getColumnModel().getColumn(1).setPreferredWidth(125);
  2043.         tableMensagem.getColumnModel().getColumn(3).setPreferredWidth(275);
  2044.         tableMensagem.getColumnModel().getColumn(4).setPreferredWidth(125);
  2045.         scrollPane.setViewportView(tableMensagem);
  2046.        
  2047.        
  2048.        
  2049.         Component horizontalStrut_37 = Box.createHorizontalStrut(20);
  2050.         GridBagConstraints gbc_horizontalStrut_37 = new GridBagConstraints();
  2051.         gbc_horizontalStrut_37.insets = new Insets(0, 0, 5, 0);
  2052.         gbc_horizontalStrut_37.gridx = 14;
  2053.         gbc_horizontalStrut_37.gridy = 3;
  2054.         panelInbox.add(horizontalStrut_37, gbc_horizontalStrut_37);
  2055.        
  2056.         JButton btnLer = new JButton("Ler");
  2057.         btnLer.addActionListener(new ActionListener() {
  2058.             public void actionPerformed(ActionEvent e) {
  2059.                 //Selecionar o ID do email
  2060.                 int column = 0;
  2061.                 int row = tableMensagem.getSelectedRow();
  2062.                 String emailID = tableMensagem.getModel().getValueAt(row, column).toString();
  2063.                 currentEmail = emailID;
  2064.                 //Definir a mensagem no outro painel
  2065.                 try {
  2066.                     textOrigemLer.setText("");
  2067.                     textCategorialer.setText("");
  2068.                     textAssuntoLer.setText("");
  2069.                     textDataLer.setText("");
  2070.                     textCorpoLer.setText("");
  2071.                     String nome = "";
  2072.                     String apelido = "";
  2073.                     String categoria = "";
  2074.                     String assunto = "";
  2075.                     String conteudo = "";
  2076.                     String data = "";
  2077.                     String idCLienteLer ="";
  2078.                     String username = "";
  2079.                     Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
  2080.                     Statement inst = lig.createStatement();
  2081.                     ResultSet resultado = inst
  2082.                             .executeQuery("SELECT *  FROM mail_cliente_cliente where emailID = '" + emailID +"'");
  2083.                    
  2084.                     while(resultado.next()) {
  2085.                         idCLienteLer = resultado.getString("origem_idCliente");
  2086.                         categoria = resultado.getString("categoria");
  2087.                         assunto = resultado.getString("assunto");
  2088.                         conteudo = resultado.getString("conteudo");
  2089.                         data = resultado.getString("data");
  2090.                         Statement inst1 = lig.createStatement();
  2091.                         ResultSet resultado1 = inst1
  2092.                                 .executeQuery("SELECT nome, apelido, username  FROM cliente where idCliente = '" + idCLienteLer +"'");
  2093.                        
  2094.                         while(resultado1.next()) {
  2095.                             nome = resultado1.getString("nome");
  2096.                             apelido = resultado1.getString("apelido");
  2097.                             username = resultado1.getString("username");
  2098.                         }
  2099.                     }
  2100.                     textOrigemLer.setText(nome + " " + apelido + "  (" + username + ")");
  2101.                     textCategorialer.setText(categoria);
  2102.                     textAssuntoLer.setText(assunto);
  2103.                     textDataLer.setText(data);
  2104.                     textCorpoLer.setText(conteudo);
  2105.                 } catch (SQLException ex) {
  2106.                     JOptionPane.showMessageDialog(null, "BD indísponivel! | " + ex);
  2107.                 }
  2108.                 frame.getContentPane().removeAll();
  2109.                 frame.getContentPane().add(panelLer);
  2110.                 frame.revalidate();
  2111.                 frame.repaint();
  2112.                
  2113.             }
  2114.         });
  2115.         GridBagConstraints gbc_btnLer = new GridBagConstraints();
  2116.         gbc_btnLer.insets = new Insets(0, 0, 5, 5);
  2117.         gbc_btnLer.gridx = 10;
  2118.         gbc_btnLer.gridy = 4;
  2119.         panelInbox.add(btnLer, gbc_btnLer);
  2120.        
  2121.         JButton btnAtualizar = new JButton("Atualizar");
  2122.         btnAtualizar.addActionListener(new ActionListener() {
  2123.             public void actionPerformed(ActionEvent e) {
  2124.                 String origemFiltro = (String) comboBoxFiltroOrigem.getSelectedItem();
  2125.                 currentFilter = origemFiltro;
  2126.                 if(origemFiltro == "Clientes") {
  2127.                     MensagensClienteCategoria();
  2128.                 }
  2129.             }
  2130.         });
  2131.         GridBagConstraints gbc_btnAtualizar = new GridBagConstraints();
  2132.         gbc_btnAtualizar.insets = new Insets(0, 0, 5, 5);
  2133.         gbc_btnAtualizar.gridx = 11;
  2134.         gbc_btnAtualizar.gridy = 4;
  2135.         panelInbox.add(btnAtualizar, gbc_btnAtualizar);
  2136.        
  2137.         JButton btnEscrever = new JButton("Escrever");
  2138.         GridBagConstraints gbc_btnEscrever = new GridBagConstraints();
  2139.         gbc_btnEscrever.anchor = GridBagConstraints.WEST;
  2140.         gbc_btnEscrever.insets = new Insets(0, 0, 5, 5);
  2141.         gbc_btnEscrever.gridx = 12;
  2142.         gbc_btnEscrever.gridy = 4;
  2143.         panelInbox.add(btnEscrever, gbc_btnEscrever);
  2144.        
  2145.         JButton btnApagarLer = new JButton("Apagar");
  2146.         btnApagarLer.addActionListener(new ActionListener() {
  2147.             public void actionPerformed(ActionEvent arg0) {
  2148.                 //apanhar o ID do email
  2149.                 int column = 0;
  2150.                 int row = tableMensagem.getSelectedRow();
  2151.                 String emailID = tableMensagem.getModel().getValueAt(row, column).toString();
  2152.                 try {
  2153.                     Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root","");
  2154.                     if(currentFilter == "Clientes") {
  2155.                         PreparedStatement inst = lig.prepareStatement("DELETE FROM mail_cliente_cliente WHERE emailID = ?");
  2156.                         inst.setString(1, emailID);
  2157.                         inst.executeUpdate();
  2158.                         MensagensClienteCategoria();
  2159.                     }
  2160.                     else {
  2161.                         PreparedStatement inst = lig.prepareStatement("DELETE FROM mail_cliente_medico WHERE emailID = ?");
  2162.                         inst.setString(1, emailID);
  2163.                         inst.executeUpdate();
  2164.                     }  
  2165.                 } catch (SQLException ex) {
  2166.                     JOptionPane.showMessageDialog(frame, "Erro ao eliminar: " + ex.getMessage());
  2167.                 }
  2168.                
  2169.             }
  2170.         });
  2171.         GridBagConstraints gbc_btnApagarLer = new GridBagConstraints();
  2172.         gbc_btnApagarLer.anchor = GridBagConstraints.WEST;
  2173.         gbc_btnApagarLer.insets = new Insets(0, 0, 5, 5);
  2174.         gbc_btnApagarLer.gridx = 13;
  2175.         gbc_btnApagarLer.gridy = 4;
  2176.         panelInbox.add(btnApagarLer, gbc_btnApagarLer);
  2177.        
  2178.         Component verticalStrut_7 = Box.createVerticalStrut(20);
  2179.         GridBagConstraints gbc_verticalStrut_7 = new GridBagConstraints();
  2180.         gbc_verticalStrut_7.insets = new Insets(0, 0, 0, 5);
  2181.         gbc_verticalStrut_7.gridx = 1;
  2182.         gbc_verticalStrut_7.gridy = 5;
  2183.         panelInbox.add(verticalStrut_7, gbc_verticalStrut_7);
  2184.        
  2185.         panelForgot = new JPanel();
  2186.         frame.getContentPane().add(panelForgot, "name_279474687724319");
  2187.         GridBagLayout gbl_panelForgot = new GridBagLayout();
  2188.         gbl_panelForgot.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  2189.         gbl_panelForgot.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
  2190.         gbl_panelForgot.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
  2191.         gbl_panelForgot.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
  2192.         panelForgot.setLayout(gbl_panelForgot);
  2193.        
  2194.         JLabel label_1 = new JLabel("Login");
  2195.         GridBagConstraints gbc_label_1 = new GridBagConstraints();
  2196.         gbc_label_1.gridwidth = 15;
  2197.         gbc_label_1.insets = new Insets(0, 0, 5, 0);
  2198.         gbc_label_1.gridx = 0;
  2199.         gbc_label_1.gridy = 0;
  2200.         panelForgot.add(label_1, gbc_label_1);
  2201.        
  2202.         Component verticalStrut_4 = Box.createVerticalStrut(20);
  2203.         GridBagConstraints gbc_verticalStrut_4 = new GridBagConstraints();
  2204.         gbc_verticalStrut_4.gridwidth = 2;
  2205.         gbc_verticalStrut_4.insets = new Insets(0, 0, 5, 5);
  2206.         gbc_verticalStrut_4.gridx = 7;
  2207.         gbc_verticalStrut_4.gridy = 1;
  2208.         panelForgot.add(verticalStrut_4, gbc_verticalStrut_4);
  2209.        
  2210.         Component horizontalStrut_22 = Box.createHorizontalStrut(20);
  2211.         GridBagConstraints gbc_horizontalStrut_22 = new GridBagConstraints();
  2212.         gbc_horizontalStrut_22.insets = new Insets(0, 0, 5, 5);
  2213.         gbc_horizontalStrut_22.gridx = 1;
  2214.         gbc_horizontalStrut_22.gridy = 2;
  2215.         panelForgot.add(horizontalStrut_22, gbc_horizontalStrut_22);
  2216.        
  2217.         Component horizontalStrut_23 = Box.createHorizontalStrut(20);
  2218.         GridBagConstraints gbc_horizontalStrut_23 = new GridBagConstraints();
  2219.         gbc_horizontalStrut_23.insets = new Insets(0, 0, 5, 5);
  2220.         gbc_horizontalStrut_23.gridx = 2;
  2221.         gbc_horizontalStrut_23.gridy = 2;
  2222.         panelForgot.add(horizontalStrut_23, gbc_horizontalStrut_23);
  2223.        
  2224.         Component horizontalStrut_24 = Box.createHorizontalStrut(20);
  2225.         GridBagConstraints gbc_horizontalStrut_24 = new GridBagConstraints();
  2226.         gbc_horizontalStrut_24.insets = new Insets(0, 0, 5, 5);
  2227.         gbc_horizontalStrut_24.gridx = 3;
  2228.         gbc_horizontalStrut_24.gridy = 2;
  2229.         panelForgot.add(horizontalStrut_24, gbc_horizontalStrut_24);
  2230.        
  2231.         Component horizontalStrut_25 = Box.createHorizontalStrut(20);
  2232.         GridBagConstraints gbc_horizontalStrut_25 = new GridBagConstraints();
  2233.         gbc_horizontalStrut_25.insets = new Insets(0, 0, 5, 5);
  2234.         gbc_horizontalStrut_25.gridx = 4;
  2235.         gbc_horizontalStrut_25.gridy = 2;
  2236.         panelForgot.add(horizontalStrut_25, gbc_horizontalStrut_25);
  2237.        
  2238.         Component horizontalStrut_26 = Box.createHorizontalStrut(20);
  2239.         GridBagConstraints gbc_horizontalStrut_26 = new GridBagConstraints();
  2240.         gbc_horizontalStrut_26.insets = new Insets(0, 0, 5, 5);
  2241.         gbc_horizontalStrut_26.gridx = 5;
  2242.         gbc_horizontalStrut_26.gridy = 2;
  2243.         panelForgot.add(horizontalStrut_26, gbc_horizontalStrut_26);
  2244.        
  2245.         JLabel lblUsernameForgot = new JLabel("Username");
  2246.         GridBagConstraints gbc_lblUsernameForgot = new GridBagConstraints();
  2247.         gbc_lblUsernameForgot.anchor = GridBagConstraints.EAST;
  2248.         gbc_lblUsernameForgot.insets = new Insets(0, 0, 5, 5);
  2249.         gbc_lblUsernameForgot.gridx = 6;
  2250.         gbc_lblUsernameForgot.gridy = 2;
  2251.         panelForgot.add(lblUsernameForgot, gbc_lblUsernameForgot);
  2252.        
  2253.         textUsernameForgot = new JTextField();
  2254.         textUsernameForgot.setColumns(10);
  2255.         GridBagConstraints gbc_textUsernameForgot = new GridBagConstraints();
  2256.         gbc_textUsernameForgot.fill = GridBagConstraints.HORIZONTAL;
  2257.         gbc_textUsernameForgot.gridwidth = 2;
  2258.         gbc_textUsernameForgot.insets = new Insets(0, 0, 5, 5);
  2259.         gbc_textUsernameForgot.gridx = 7;
  2260.         gbc_textUsernameForgot.gridy = 2;
  2261.         panelForgot.add(textUsernameForgot, gbc_textUsernameForgot);
  2262.        
  2263.         Component horizontalStrut_27 = Box.createHorizontalStrut(20);
  2264.         GridBagConstraints gbc_horizontalStrut_27 = new GridBagConstraints();
  2265.         gbc_horizontalStrut_27.insets = new Insets(0, 0, 5, 5);
  2266.         gbc_horizontalStrut_27.gridx = 10;
  2267.         gbc_horizontalStrut_27.gridy = 2;
  2268.         panelForgot.add(horizontalStrut_27, gbc_horizontalStrut_27);
  2269.        
  2270.         Component horizontalStrut_28 = Box.createHorizontalStrut(20);
  2271.         GridBagConstraints gbc_horizontalStrut_28 = new GridBagConstraints();
  2272.         gbc_horizontalStrut_28.insets = new Insets(0, 0, 5, 5);
  2273.         gbc_horizontalStrut_28.gridx = 11;
  2274.         gbc_horizontalStrut_28.gridy = 2;
  2275.         panelForgot.add(horizontalStrut_28, gbc_horizontalStrut_28);
  2276.        
  2277.         Component horizontalStrut_29 = Box.createHorizontalStrut(20);
  2278.         GridBagConstraints gbc_horizontalStrut_29 = new GridBagConstraints();
  2279.         gbc_horizontalStrut_29.insets = new Insets(0, 0, 5, 5);
  2280.         gbc_horizontalStrut_29.gridx = 12;
  2281.         gbc_horizontalStrut_29.gridy = 2;
  2282.         panelForgot.add(horizontalStrut_29, gbc_horizontalStrut_29);
  2283.        
  2284.         Component horizontalStrut_30 = Box.createHorizontalStrut(20);
  2285.         GridBagConstraints gbc_horizontalStrut_30 = new GridBagConstraints();
  2286.         gbc_horizontalStrut_30.insets = new Insets(0, 0, 5, 5);
  2287.         gbc_horizontalStrut_30.gridx = 13;
  2288.         gbc_horizontalStrut_30.gridy = 2;
  2289.         panelForgot.add(horizontalStrut_30, gbc_horizontalStrut_30);
  2290.        
  2291.         Component horizontalStrut_31 = Box.createHorizontalStrut(20);
  2292.         GridBagConstraints gbc_horizontalStrut_31 = new GridBagConstraints();
  2293.         gbc_horizontalStrut_31.insets = new Insets(0, 0, 5, 0);
  2294.         gbc_horizontalStrut_31.gridx = 14;
  2295.         gbc_horizontalStrut_31.gridy = 2;
  2296.         panelForgot.add(horizontalStrut_31, gbc_horizontalStrut_31);
  2297.        
  2298.         JLabel lblEmail_1 = new JLabel("Email:");
  2299.         GridBagConstraints gbc_lblEmail_1 = new GridBagConstraints();
  2300.         gbc_lblEmail_1.anchor = GridBagConstraints.EAST;
  2301.         gbc_lblEmail_1.insets = new Insets(0, 0, 5, 5);
  2302.         gbc_lblEmail_1.gridx = 6;
  2303.         gbc_lblEmail_1.gridy = 3;
  2304.         panelForgot.add(lblEmail_1, gbc_lblEmail_1);
  2305.        
  2306.         textEmailForgot = new JTextField();
  2307.         GridBagConstraints gbc_textEmailForgot = new GridBagConstraints();
  2308.         gbc_textEmailForgot.gridwidth = 2;
  2309.         gbc_textEmailForgot.insets = new Insets(0, 0, 5, 5);
  2310.         gbc_textEmailForgot.fill = GridBagConstraints.HORIZONTAL;
  2311.         gbc_textEmailForgot.gridx = 7;
  2312.         gbc_textEmailForgot.gridy = 3;
  2313.         panelForgot.add(textEmailForgot, gbc_textEmailForgot);
  2314.         textEmailForgot.setColumns(10);
  2315.         textEmailForgot.addFocusListener(new FocusAdapter() {
  2316.             public void focusGained(FocusEvent e){
  2317.                 if(textEmailForgot.getText().equals("Tudo em minúsculas")){
  2318.                     textEmailForgot.setText("");
  2319.                     textEmailForgot.setForeground(Color.BLACK);
  2320.                 }
  2321.             }
  2322.            
  2323.             public void focusLost(FocusEvent x){
  2324.                 if(textEmailForgot.getText().equals("")){
  2325.                     textEmailForgot.setText("Tudo em minúsculas");
  2326.                     textEmailForgot.setForeground(Color.GRAY);
  2327.                 }
  2328.             }
  2329.         });
  2330.        
  2331.         JLabel label_3 = new JLabel("Password nova:");
  2332.         GridBagConstraints gbc_label_3 = new GridBagConstraints();
  2333.         gbc_label_3.anchor = GridBagConstraints.EAST;
  2334.         gbc_label_3.insets = new Insets(0, 0, 5, 5);
  2335.         gbc_label_3.gridx = 6;
  2336.         gbc_label_3.gridy = 4;
  2337.         panelForgot.add(label_3, gbc_label_3);
  2338.        
  2339.         passwordNovaForgot = new JTextField();
  2340.         passwordNovaForgot.setColumns(10);
  2341.         GridBagConstraints gbc_passwordNovaForgot = new GridBagConstraints();
  2342.         gbc_passwordNovaForgot.fill = GridBagConstraints.HORIZONTAL;
  2343.         gbc_passwordNovaForgot.gridwidth = 2;
  2344.         gbc_passwordNovaForgot.insets = new Insets(0, 0, 5, 5);
  2345.         gbc_passwordNovaForgot.gridx = 7;
  2346.         gbc_passwordNovaForgot.gridy = 4;
  2347.         panelForgot.add(passwordNovaForgot, gbc_passwordNovaForgot);
  2348.        
  2349.         JLabel label_4 = new JLabel("Confirmar password:");
  2350.         GridBagConstraints gbc_label_4 = new GridBagConstraints();
  2351.         gbc_label_4.anchor = GridBagConstraints.EAST;
  2352.         gbc_label_4.insets = new Insets(0, 0, 5, 5);
  2353.         gbc_label_4.gridx = 6;
  2354.         gbc_label_4.gridy = 5;
  2355.         panelForgot.add(label_4, gbc_label_4);
  2356.        
  2357.         passwordConfirmarForgot = new JTextField();
  2358.         passwordConfirmarForgot.setColumns(10);
  2359.         GridBagConstraints gbc_passwordConfirmarForgot = new GridBagConstraints();
  2360.         gbc_passwordConfirmarForgot.fill = GridBagConstraints.HORIZONTAL;
  2361.         gbc_passwordConfirmarForgot.gridwidth = 2;
  2362.         gbc_passwordConfirmarForgot.insets = new Insets(0, 0, 5, 5);
  2363.         gbc_passwordConfirmarForgot.gridx = 7;
  2364.         gbc_passwordConfirmarForgot.gridy = 5;
  2365.         panelForgot.add(passwordConfirmarForgot, gbc_passwordConfirmarForgot);
  2366.        
  2367.         Component verticalStrut_6 = Box.createVerticalStrut(20);
  2368.         GridBagConstraints gbc_verticalStrut_6 = new GridBagConstraints();
  2369.         gbc_verticalStrut_6.insets = new Insets(0, 0, 5, 5);
  2370.         gbc_verticalStrut_6.gridx = 8;
  2371.         gbc_verticalStrut_6.gridy = 6;
  2372.         panelForgot.add(verticalStrut_6, gbc_verticalStrut_6);
  2373.        
  2374.         JButton button = new JButton("Confirmar");
  2375.         button.addActionListener(new ActionListener() {
  2376.             public void actionPerformed(ActionEvent e) {
  2377.                 //esqueceu-se da palavra-Chave?
  2378.                 //Mudar password
  2379.                 String username = textUsernameForgot.getText();
  2380.                 String email = textEmailForgot.getText();
  2381.                 String passwordNovaForgot1 = passwordNovaForgot.getText();
  2382.                 String passwordConfirmarForgot1 = passwordConfirmarForgot.getText();
  2383.                 //comparar  as 2 passwords
  2384.                 if(passwordNovaForgot1.equals(passwordConfirmarForgot1)) {
  2385.                    
  2386.                     //Verificar se o username existe
  2387.                     try {
  2388.                         Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
  2389.                         Statement instRegisto = lig.createStatement();
  2390.                         ResultSet resultadoRegisto = instRegisto
  2391.                                 .executeQuery("SELECT username, email  FROM cliente where username = '" + username +"'");
  2392.                         if(resultadoRegisto.next() == true) {
  2393.                             String emailDB = resultadoRegisto.getString("email");
  2394.                             if(email.equals(emailDB)) {
  2395.                                 PreparedStatement instPassword = lig.prepareStatement(
  2396.                                         "UPDATE cliente SET palavraChave = ? WHERE username = '" + username + "'");
  2397.                                 instPassword.setString(1, passwordNovaForgot1);
  2398.                                 int linhasAlteradas = instPassword.executeUpdate();
  2399.                                 if (linhasAlteradas == 1) {
  2400.                                     JOptionPane.showMessageDialog(null, "Palavra-Passe atualizada");
  2401.                                    
  2402.                                     //volta para o login
  2403.                                     frame.getContentPane().removeAll();
  2404.                                     frame.getContentPane().add(panelLogin);
  2405.                                     frame.revalidate();
  2406.                                     frame.repaint();
  2407.                                 } else {
  2408.                                     JOptionPane.showMessageDialog(null, "Palavra-Passe não atualizada");
  2409.                                 }
  2410.                             }
  2411.                             else {
  2412.                                 JOptionPane.showMessageDialog(null, "Email errado");
  2413.                                 textEmailForgot.setText("");
  2414.                             }
  2415.                         }
  2416.                         else {
  2417.                             JOptionPane.showMessageDialog(null, "O username não existe.");
  2418.                         }
  2419.                     } catch (SQLException ex) {
  2420.                         JOptionPane.showMessageDialog(null, "BD indísponivel! | " + ex);
  2421.                     }
  2422.                 }
  2423.                 else {
  2424.                     JOptionPane.showMessageDialog(null, "As palavras-Passe não correspondem.");
  2425.                     passwordNovaForgot.setText("");
  2426.                     passwordConfirmarForgot.setText("");
  2427.                 }
  2428.                 passwordNovaForgot.setText("");
  2429.                 passwordConfirmarForgot.setText("");
  2430.  
  2431.             }
  2432.         });
  2433.         GridBagConstraints gbc_button = new GridBagConstraints();
  2434.         gbc_button.gridwidth = 15;
  2435.         gbc_button.gridx = 0;
  2436.         gbc_button.gridy = 7;
  2437.         panelForgot.add(button, gbc_button);
  2438.        
  2439.         JMenuBar menuBar = new JMenuBar();
  2440.         frame.setJMenuBar(menuBar);
  2441.        
  2442.         JMenu mnIncio = new JMenu("In\u00EDcio");
  2443.         menuBar.add(mnIncio);
  2444.        
  2445.         mntmLogin = new JMenuItem("Login");
  2446.         mntmLogin.addActionListener(new ActionListener() {
  2447.             public void actionPerformed(ActionEvent arg0) {
  2448.                     frame.getContentPane().removeAll();
  2449.                     frame.getContentPane().add(panelLogin);
  2450.                     frame.revalidate();
  2451.                     frame.repaint();
  2452.                 }
  2453.         });
  2454.         mnIncio.add(mntmLogin);
  2455.        
  2456.         mntmRegisto = new JMenuItem("Registo");
  2457.         mntmRegisto.addActionListener(new ActionListener() {
  2458.             public void actionPerformed(ActionEvent e) {
  2459.                 frame.getContentPane().removeAll();
  2460.                 frame.getContentPane().add(panelRegisto);
  2461.                 frame.revalidate();
  2462.                 frame.repaint();
  2463.             }
  2464.         });
  2465.         mnIncio.add(mntmRegisto);
  2466.        
  2467.         JMenu mnUtilizador = new JMenu("utilizador");
  2468.         menuBar.add(mnUtilizador);
  2469.        
  2470.         mntmPerfil = new JMenuItem("Perfil");
  2471.         mntmPerfil.addActionListener(new ActionListener() {
  2472.             public void actionPerformed(ActionEvent e) {
  2473.                 frame.getContentPane().removeAll();
  2474.                 frame.getContentPane().add(panelPerfil);
  2475.                 frame.revalidate();
  2476.                 frame.repaint();
  2477.             }
  2478.         });
  2479.         mnUtilizador.add(mntmPerfil);
  2480.        
  2481.         JMenu mnMensagem = new JMenu("Mensagem");
  2482.         menuBar.add(mnMensagem);
  2483.        
  2484.         mntmInbox = new JMenuItem("Inbox");
  2485.         mntmInbox.addActionListener(new ActionListener() {
  2486.             public void actionPerformed(ActionEvent e) {
  2487.                 frame.getContentPane().removeAll();
  2488.                 frame.getContentPane().add(panelInbox);
  2489.                 frame.revalidate();
  2490.                 frame.repaint();
  2491.                 comboBoxFiltroCategoria.setSelectedIndex(0);
  2492.                 String origemFiltro = (String) comboBoxFiltroOrigem.getSelectedItem();
  2493.                 currentFilter = origemFiltro;
  2494.                 if(origemFiltro == "Clientes") {
  2495.                     MensagensCliente();
  2496.                 }
  2497.                 else {
  2498.                    
  2499.                 }
  2500.             }
  2501.         });
  2502.         mntmInbox.setEnabled(false);
  2503.         mnMensagem.add(mntmInbox);
  2504.        
  2505.         mntmEscrever = new JMenuItem("Escrever");
  2506.         mntmEscrever.addActionListener(new ActionListener() {
  2507.             public void actionPerformed(ActionEvent e) {
  2508.                 textDestinatario.setText("");
  2509.                 textAssunto.setText("");
  2510.                 textCorpo.setText("");
  2511.                 comboBoxIdentificador.setSelectedIndex(0);
  2512.                 comboBoxIdentificador.setSelectedIndex(0);
  2513.                 comboBoxIdentificador.setSelectedIndex(0);
  2514.                 frame.getContentPane().removeAll();
  2515.                 frame.getContentPane().add(panelMensagem);
  2516.                 frame.revalidate();
  2517.                 frame.repaint();
  2518.             }
  2519.         });
  2520.         mntmEscrever.setEnabled(false);
  2521.         mnMensagem.add(mntmEscrever);
  2522.        
  2523.         JMenu mnOutros = new JMenu("Outros");
  2524.         menuBar.add(mnOutros);
  2525.        
  2526.         mntmCancelar = new JMenuItem("Cancelar todas as a\u00E7\u00F5es");
  2527.         mntmCancelar.addActionListener(new ActionListener() {
  2528.             public void actionPerformed(ActionEvent e) {
  2529.                 comboBoxTipoSangue.setSelectedIndex(0);
  2530.                 comboBoxSexo.setSelectedIndex(0);
  2531.                 textNome.setText("");
  2532.                 textApelido.setText("");
  2533.                 textUsername.setText("");
  2534.                 textDataNascimento.setText("AAAA-MM-DD");
  2535.                 textDataNascimento.setForeground(Color.GRAY);
  2536.                 textContacto.setText("");
  2537.                 textEmail.setText("Tudo em minúsculas");
  2538.                 textEmail.setForeground(Color.GRAY);
  2539.                 textMorada.setText("");
  2540.                 textUsernameLogin.setText("");
  2541.                 passwordVelha.setText("");
  2542.                 passwordNova.setText("");
  2543.                 passwordConfirmar.setText("");
  2544.                 textUsernameForgot.setText("");
  2545.                 textEmailForgot.setText("Tudo em minúsculas");
  2546.                 textEmailForgot.setForeground(Color.GRAY);
  2547.                 passwordNovaForgot.setText("");
  2548.                 passwordConfirmarForgot.setText("");
  2549.                 textDestinatario.setText("");
  2550.                 textAssunto.setText("");
  2551.                 passwordLogin.setText("");;
  2552.                 passwordRegisto.setText("");;
  2553.                 textEmailForgot.setText("");;
  2554.                 textOrigemLer.setText("");;
  2555.                 textAssuntoLer.setText("");;
  2556.                 textCategorialer.setText("");;
  2557.                 textDataLer.setText("");;
  2558.                 /** Perfil - Para avaliação para ver se se tira os campos ou não - Provavelmente não */
  2559.                 /*
  2560.                 textNomePerfil.setText("");
  2561.                 textApelidoPerfil.setText("");
  2562.                 textIDPerfil.setText("");
  2563.                 textUsernamePerfil.setText("");
  2564.                 textDataNascimentoPerfil.setText("");
  2565.                 textEmailPerfil.setText("");
  2566.                 textContactoPerfil.setText("");
  2567.                 textMoradaPerfil.setText("");
  2568.                 textTipoSanguePerfil.setText("");
  2569.                 textSexoPerfil.setText("");
  2570.                 */
  2571.                 passwordLogin.setText("");
  2572.                 passwordRegisto.setText("");
  2573.                
  2574.                 /** JcomboBoxes */
  2575.                 comboBoxFiltroOrigem.setSelectedIndex(0);
  2576.                 comboBoxFiltroCategoria.setSelectedIndex(0);
  2577.                 comboBoxDestinatario.setSelectedIndex(0);
  2578.                 comboBoxIdentificador.setSelectedIndex(0);
  2579.                
  2580.                 /** textpanes */
  2581.                 textCorpo.setText("");
  2582.                 textCorpoLer.setText("");
  2583.             }
  2584.         });
  2585.         mnOutros.add(mntmCancelar);
  2586.        
  2587.         mntmLogout = new JMenuItem("Terminar Sess\u00E3o");
  2588.         mntmLogout.addActionListener(new ActionListener() {
  2589.             public void actionPerformed(ActionEvent e) {
  2590.                 currentUserID = 0;
  2591.                 frame.getContentPane().removeAll();
  2592.                 frame.getContentPane().add(panelLogin);
  2593.                 frame.revalidate();
  2594.                 frame.repaint();
  2595.                 mntmLogin.setEnabled(true);
  2596.                 mntmRegisto.setEnabled(true);
  2597.                 mntmPerfil.setEnabled(false);
  2598.                 mntmLogout.setEnabled(false);
  2599.                 mntmEscrever.setEnabled(false);
  2600.                 mntmInbox.setEnabled(false);
  2601.                 passwordVelha.setText("");
  2602.                 passwordNova.setText("");
  2603.                 passwordConfirmar.setText("");
  2604.                
  2605.             }
  2606.         });
  2607.         mnOutros.add(mntmLogout);
  2608.     }
  2609. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement