Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pap;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.GroupLayout;
- import javax.swing.GroupLayout.Alignment;
- import javax.swing.JTextPane;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.FocusAdapter;
- import java.awt.event.FocusEvent;
- import java.sql.Array;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.text.SimpleDateFormat;
- import java.time.LocalDate;
- import java.time.format.DateTimeFormatter;
- import java.util.Date;
- import java.awt.event.ActionEvent;
- import javax.swing.LayoutStyle.ComponentPlacement;
- import javax.swing.JPanel;
- import java.awt.GridLayout;
- import java.awt.CardLayout;
- import java.awt.Color;
- import javax.swing.BoxLayout;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.DefaultListModel;
- import java.awt.GridBagLayout;
- import java.awt.GridBagConstraints;
- import java.awt.Insets;
- import javax.swing.JTextField;
- import javax.swing.JRadioButton;
- import javax.swing.JPasswordField;
- import javax.swing.JComboBox;
- import javax.swing.JMenuBar;
- import javax.swing.JMenu;
- import javax.swing.JMenuItem;
- import javax.swing.JList;
- import java.awt.Component;
- import javax.swing.Box;
- import javax.swing.JScrollPane;
- import javax.swing.JTable;
- import javax.swing.table.DefaultTableModel;
- public class MedClinic {
- /** Panels */
- private JFrame frame;
- private JPanel panelRegisto;
- private JPanel panelLogin;
- private JPanel panelPerfil;
- private JPanel panelPassword;
- private JPanel panelForgot;
- private JPanel panelMensagem;
- private JPanel panelLer;
- /** TextFields */
- private JTextField textNome;
- private JTextField textApelido;
- private JTextField textUsername;
- private JTextField textDataNascimento;
- private JTextField textContacto;
- private JTextField textEmail;
- private JTextField textMorada;
- private JTextField textID;
- private JTextField textUsernameLogin;
- private JTextField passwordVelha;
- private JTextField passwordNova;
- private JTextField passwordConfirmar;
- private JTextField textUsernameForgot;
- private JTextField passwordNovaForgot;
- private JTextField passwordConfirmarForgot;
- private JTextField textDestinatario;
- private JTextField textAssunto;
- private JTextField textNomePerfil;
- private JTextField textApelidoPerfil;
- private JTextField textIDPerfil;
- private JTextField textUsernamePerfil;
- private JTextField textDataNascimentoPerfil;
- private JTextField textEmailPerfil;
- private JTextField textContactoPerfil;
- private JTextField textMoradaPerfil;
- private JTextField textTipoSanguePerfil;
- private JTextField textSexoPerfil;
- private JTextField passwordLogin;
- private JTextField passwordRegisto;
- private JTextField textEmailForgot;
- private JTextField textOrigemLer;
- private JTextField textAssuntoLer;
- private JTextField textCategorialer;
- private JTextField textDataLer;
- /** TextPanes */
- private JTextPane textCorpoLer;
- private JTextPane textCorpo;
- /** ComboBoxes */
- private JComboBox comboBoxFiltroOrigem;
- private JComboBox comboBoxFiltroCategoria;
- private JComboBox comboBoxDestinatario;
- private JComboBox comboBoxIdentificador;
- /** Butões do panelPerfil */
- private JButton btnEditar;
- private JButton btnGuardar;
- /** Menu Items */
- private JMenuItem mntmLogin;
- private JMenuItem mntmRegisto;
- private JMenuItem mntmLogout;
- private JMenuItem mntmCancelar;
- private JMenuItem mntmPerfil;
- private JMenuItem mntmEscrever;
- private JMenuItem mntmInbox;
- /** Variaveis */
- private int idCliente;
- private String currentFilter;
- private String currentEmail;
- private int currentUserID = 0;
- /** List Models */
- private DefaultTableModel modeloInbox = new DefaultTableModel();
- private JTable tableMensagem;
- /** Tabelas */
- public void MensagensCliente(){
- modeloInbox.setRowCount(0);
- String query = "SELECT emailID, origem_idCliente, categoria, assunto, data FROM mail_cliente_cliente WHERE destino_idCliente = '" + currentUserID + "'";
- try {
- modeloInbox.setRowCount(0);
- Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
- PreparedStatement inst = lig.prepareStatement(query);
- ResultSet resultado = inst.executeQuery();
- while (resultado.next()) {
- int id = resultado.getInt("emailID");
- String nome = "";
- String apelido = "";
- String origem = resultado.getString("origem_idCliente");
- String categoria = resultado.getString("categoria");
- String assunto = resultado.getString("assunto");
- String data = resultado.getString("data");
- try {
- PreparedStatement inst1 = lig.prepareStatement("SELECT nome, apelido FROM cliente WHERE idCliente = '" + origem + "'");
- ResultSet resultado1 = inst1.executeQuery();
- while (resultado1.next()) {
- nome = resultado1.getString("nome");
- apelido = resultado1.getString("apelido");
- }
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "BD indísponivel!1" + ex.getMessage());
- }
- String nomeApelido = nome + " " + apelido;
- modeloInbox.addRow(new Object[] {id, nomeApelido, categoria, assunto, data});
- }
- lig.close();
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "BD indísponivel!" + ex.getMessage());
- }
- }
- public void MensagensClienteCategoria(){
- modeloInbox.setRowCount(0);
- String categoria = (String) comboBoxFiltroCategoria.getSelectedItem();
- if(!(categoria == "Todas")) {
- String query = "SELECT emailID, origem_idCliente, categoria, assunto, data FROM mail_cliente_cliente WHERE destino_idCliente = '" + currentUserID + "' AND categoria = '" + categoria + "'";
- try {
- modeloInbox.setRowCount(0);
- Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
- PreparedStatement inst = lig.prepareStatement(query);
- ResultSet resultado = inst.executeQuery();
- while (resultado.next()) {
- int id = resultado.getInt("emailID");
- String nome = "";
- String apelido = "";
- String origem = resultado.getString("origem_idCliente");
- categoria = resultado.getString("categoria");
- String assunto = resultado.getString("assunto");
- String data = resultado.getString("data");
- try {
- PreparedStatement inst1 = lig.prepareStatement("SELECT nome, apelido FROM cliente WHERE idCliente = '" + origem + "'");
- ResultSet resultado1 = inst1.executeQuery();
- while (resultado1.next()) {
- nome = resultado1.getString("nome");
- apelido = resultado1.getString("apelido");
- }
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "BD indísponivel!1" + ex.getMessage());
- }
- String nomeApelido = nome + " " + apelido;
- modeloInbox.addRow(new Object[] {id, nomeApelido, categoria, assunto, data});
- }
- lig.close();
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "BD indísponivel!" + ex.getMessage());
- }
- }
- else {
- String query = "SELECT emailID, origem_idCliente, categoria, assunto, data FROM mail_cliente_cliente WHERE destino_idCliente = '" + currentUserID + "'";
- try {
- modeloInbox.setRowCount(0);
- Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
- PreparedStatement inst = lig.prepareStatement(query);
- ResultSet resultado = inst.executeQuery();
- while (resultado.next()) {
- int id = resultado.getInt("emailID");
- String nome = "";
- String apelido = "";
- String origem = resultado.getString("origem_idCliente");
- categoria = resultado.getString("categoria");
- String assunto = resultado.getString("assunto");
- String data = resultado.getString("data");
- try {
- PreparedStatement inst1 = lig.prepareStatement("SELECT nome, apelido FROM cliente WHERE idCliente = '" + origem + "'");
- ResultSet resultado1 = inst1.executeQuery();
- while (resultado1.next()) {
- nome = resultado1.getString("nome");
- apelido = resultado1.getString("apelido");
- }
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "BD indísponivel!1" + ex.getMessage());
- }
- String nomeApelido = nome + " " + apelido;
- modeloInbox.addRow(new Object[] {id, nomeApelido, categoria, assunto, data});
- }
- lig.close();
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "BD indísponivel!" + ex.getMessage());
- }
- }
- }
- /** Setup do Perfil */
- public void perfilSetup() {
- try {
- Connection ligPerfil = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
- Statement instPerfil = ligPerfil.createStatement();
- ResultSet resultadoPerfil = instPerfil
- .executeQuery("SELECT * FROM cliente where idCliente = '" + currentUserID + "'");
- while (resultadoPerfil.next()) {
- //preencher os campos do perfil com os dados da base de dados respetivos ao username
- textIDPerfil.setText(resultadoPerfil.getString("idCliente"));
- textNomePerfil.setText(resultadoPerfil.getString("nome"));
- textApelidoPerfil.setText(resultadoPerfil.getString("apelido"));
- textUsernamePerfil.setText(resultadoPerfil.getString("username"));
- textDataNascimentoPerfil.setText(resultadoPerfil.getString("dataNascimento"));
- textTipoSanguePerfil.setText(resultadoPerfil.getString("tipoSangue"));
- textSexoPerfil.setText(resultadoPerfil.getString("sexo"));
- textContactoPerfil.setText(resultadoPerfil.getString("contacto"));
- textEmailPerfil.setText(resultadoPerfil.getString("email"));
- textMoradaPerfil.setText(resultadoPerfil.getString("morada"));
- }
- ligPerfil.close();
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "BD indísponivel! | " +ex.getMessage());
- }
- }
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- MedClinic window = new MedClinic();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public MedClinic() {
- initialize();
- mntmPerfil.setEnabled(false);
- mntmLogout.setEnabled(false);
- textEmail.setText("Tudo em minúsculas");
- textEmail.setForeground(Color.GRAY);
- textDataNascimento.setText("AAAA-MM-DD");
- textDataNascimento.setForeground(Color.GRAY);
- textEmailForgot.setText("Tudo em minúsculas");
- textEmailForgot.setForeground(Color.GRAY);
- panelLer = new JPanel();
- frame.getContentPane().add(panelLer, "name_298078073230023");
- GridBagLayout gbl_panelLer = new GridBagLayout();
- gbl_panelLer.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
- gbl_panelLer.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
- gbl_panelLer.columnWeights = new double[]{0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
- gbl_panelLer.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
- panelLer.setLayout(gbl_panelLer);
- JLabel label = new JLabel("Mensagem");
- GridBagConstraints gbc_label = new GridBagConstraints();
- gbc_label.gridwidth = 6;
- gbc_label.insets = new Insets(0, 0, 5, 5);
- gbc_label.gridx = 1;
- gbc_label.gridy = 0;
- panelLer.add(label, gbc_label);
- JLabel labelOrigem = new JLabel("Origem:");
- GridBagConstraints gbc_labelOrigem = new GridBagConstraints();
- gbc_labelOrigem.anchor = GridBagConstraints.EAST;
- gbc_labelOrigem.insets = new Insets(0, 0, 5, 5);
- gbc_labelOrigem.gridx = 1;
- gbc_labelOrigem.gridy = 1;
- panelLer.add(labelOrigem, gbc_labelOrigem);
- textOrigemLer = new JTextField();
- textOrigemLer.setBackground(Color.WHITE);
- textOrigemLer.setEditable(false);
- textOrigemLer.setColumns(10);
- GridBagConstraints gbc_textOrigemLer = new GridBagConstraints();
- gbc_textOrigemLer.fill = GridBagConstraints.HORIZONTAL;
- gbc_textOrigemLer.insets = new Insets(0, 0, 5, 5);
- gbc_textOrigemLer.gridx = 2;
- gbc_textOrigemLer.gridy = 1;
- panelLer.add(textOrigemLer, gbc_textOrigemLer);
- JLabel lblCategoria = new JLabel("Categoria");
- GridBagConstraints gbc_lblCategoria = new GridBagConstraints();
- gbc_lblCategoria.anchor = GridBagConstraints.EAST;
- gbc_lblCategoria.insets = new Insets(0, 0, 5, 5);
- gbc_lblCategoria.gridx = 1;
- gbc_lblCategoria.gridy = 2;
- panelLer.add(lblCategoria, gbc_lblCategoria);
- textCategorialer = new JTextField();
- textCategorialer.setBackground(Color.WHITE);
- textCategorialer.setEditable(false);
- GridBagConstraints gbc_textCategorialer = new GridBagConstraints();
- gbc_textCategorialer.insets = new Insets(0, 0, 5, 5);
- gbc_textCategorialer.fill = GridBagConstraints.HORIZONTAL;
- gbc_textCategorialer.gridx = 2;
- gbc_textCategorialer.gridy = 2;
- panelLer.add(textCategorialer, gbc_textCategorialer);
- textCategorialer.setColumns(10);
- Component horizontalStrut_2 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_2 = new GridBagConstraints();
- gbc_horizontalStrut_2.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_2.gridx = 3;
- gbc_horizontalStrut_2.gridy = 2;
- panelLer.add(horizontalStrut_2, gbc_horizontalStrut_2);
- JLabel lblData = new JLabel("Data:");
- GridBagConstraints gbc_lblData = new GridBagConstraints();
- gbc_lblData.anchor = GridBagConstraints.EAST;
- gbc_lblData.insets = new Insets(0, 0, 5, 5);
- gbc_lblData.gridx = 4;
- gbc_lblData.gridy = 2;
- panelLer.add(lblData, gbc_lblData);
- textDataLer = new JTextField();
- textDataLer.setBackground(Color.WHITE);
- textDataLer.setEditable(false);
- GridBagConstraints gbc_textDataLer = new GridBagConstraints();
- gbc_textDataLer.gridwidth = 2;
- gbc_textDataLer.insets = new Insets(0, 0, 5, 5);
- gbc_textDataLer.fill = GridBagConstraints.HORIZONTAL;
- gbc_textDataLer.gridx = 5;
- gbc_textDataLer.gridy = 2;
- panelLer.add(textDataLer, gbc_textDataLer);
- textDataLer.setColumns(10);
- Component horizontalStrut = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut = new GridBagConstraints();
- gbc_horizontalStrut.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut.gridx = 0;
- gbc_horizontalStrut.gridy = 3;
- panelLer.add(horizontalStrut, gbc_horizontalStrut);
- JLabel label_2 = new JLabel("Assunto:");
- GridBagConstraints gbc_label_2 = new GridBagConstraints();
- gbc_label_2.anchor = GridBagConstraints.EAST;
- gbc_label_2.insets = new Insets(0, 0, 5, 5);
- gbc_label_2.gridx = 1;
- gbc_label_2.gridy = 3;
- panelLer.add(label_2, gbc_label_2);
- textAssuntoLer = new JTextField();
- textAssuntoLer.setBackground(Color.WHITE);
- textAssuntoLer.setEditable(false);
- textAssuntoLer.setColumns(10);
- GridBagConstraints gbc_textAssuntoLer = new GridBagConstraints();
- gbc_textAssuntoLer.fill = GridBagConstraints.HORIZONTAL;
- gbc_textAssuntoLer.gridwidth = 5;
- gbc_textAssuntoLer.insets = new Insets(0, 0, 5, 5);
- gbc_textAssuntoLer.gridx = 2;
- gbc_textAssuntoLer.gridy = 3;
- panelLer.add(textAssuntoLer, gbc_textAssuntoLer);
- JLabel label_3 = new JLabel("Corpo:");
- GridBagConstraints gbc_label_3 = new GridBagConstraints();
- gbc_label_3.anchor = GridBagConstraints.EAST;
- gbc_label_3.insets = new Insets(0, 0, 5, 5);
- gbc_label_3.gridx = 1;
- gbc_label_3.gridy = 4;
- panelLer.add(label_3, gbc_label_3);
- Component horizontalStrut_1 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_1 = new GridBagConstraints();
- gbc_horizontalStrut_1.insets = new Insets(0, 0, 5, 0);
- gbc_horizontalStrut_1.gridx = 7;
- gbc_horizontalStrut_1.gridy = 4;
- panelLer.add(horizontalStrut_1, gbc_horizontalStrut_1);
- JScrollPane scrollPaneLer = new JScrollPane();
- GridBagConstraints gbc_scrollPaneLer = new GridBagConstraints();
- gbc_scrollPaneLer.fill = GridBagConstraints.BOTH;
- gbc_scrollPaneLer.gridwidth = 5;
- gbc_scrollPaneLer.insets = new Insets(0, 0, 5, 5);
- gbc_scrollPaneLer.gridx = 2;
- gbc_scrollPaneLer.gridy = 5;
- panelLer.add(scrollPaneLer, gbc_scrollPaneLer);
- textCorpoLer = new JTextPane();
- textCorpoLer.setEditable(false);
- scrollPaneLer.setViewportView(textCorpoLer);
- JButton btnResponder = new JButton("Responder");
- btnResponder.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- //voltar aqui
- try {
- textDestinatario.setText("");
- textAssunto.setText("");
- textCorpo.setText("");
- String assunto = "";
- int destinatario;
- String username = "";
- comboBoxIdentificador.setSelectedIndex(1);
- Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
- if(currentFilter == "Clientes") {
- comboBoxDestinatario.setSelectedIndex(1);
- Statement inst = lig.createStatement();
- ResultSet resultado = inst
- .executeQuery("SELECT * FROM mail_cliente_cliente where emailID = '" + currentEmail +"'");
- while(resultado.next()) {
- assunto = resultado.getString("assunto");
- destinatario = resultado.getInt("origem_idCliente");
- Statement inst1 = lig.createStatement();
- ResultSet resultado1 = inst1
- .executeQuery("SELECT nome, apelido, username FROM cliente where idCliente = '" + destinatario +"'");
- while(resultado1.next()) {
- username = resultado1.getString("username");
- }
- }
- }
- else {//medico
- comboBoxDestinatario.setSelectedIndex(0);
- }
- textDestinatario.setText(username);
- textAssunto.setText(assunto);
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "BD indísponivel! | " + ex);
- }
- frame.getContentPane().removeAll();
- frame.getContentPane().add(panelMensagem);
- frame.revalidate();
- frame.repaint();
- }
- });
- GridBagConstraints gbc_btnResponder = new GridBagConstraints();
- gbc_btnResponder.anchor = GridBagConstraints.EAST;
- gbc_btnResponder.gridwidth = 2;
- gbc_btnResponder.insets = new Insets(0, 0, 0, 5);
- gbc_btnResponder.gridx = 2;
- gbc_btnResponder.gridy = 6;
- panelLer.add(btnResponder, gbc_btnResponder);
- JButton btnVoltar = new JButton("Voltar");
- GridBagConstraints gbc_btnVoltar = new GridBagConstraints();
- gbc_btnVoltar.anchor = GridBagConstraints.WEST;
- gbc_btnVoltar.gridwidth = 5;
- gbc_btnVoltar.gridx = 4;
- gbc_btnVoltar.gridy = 6;
- panelLer.add(btnVoltar, gbc_btnVoltar);
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frame = new JFrame();
- frame.setBounds(100, 100, 800, 600);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.getContentPane().setLayout(new CardLayout(0, 0));
- panelLogin = new JPanel();
- frame.getContentPane().add(panelLogin, "name_947814248684106");
- GridBagLayout gbl_panelLogin = new GridBagLayout();
- gbl_panelLogin.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- gbl_panelLogin.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0};
- 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};
- gbl_panelLogin.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
- panelLogin.setLayout(gbl_panelLogin);
- JLabel lblLogin = new JLabel("Login");
- GridBagConstraints gbc_lblLogin = new GridBagConstraints();
- gbc_lblLogin.gridwidth = 16;
- gbc_lblLogin.insets = new Insets(0, 0, 5, 0);
- gbc_lblLogin.gridx = 0;
- gbc_lblLogin.gridy = 0;
- panelLogin.add(lblLogin, gbc_lblLogin);
- Component verticalStrut = Box.createVerticalStrut(20);
- GridBagConstraints gbc_verticalStrut = new GridBagConstraints();
- gbc_verticalStrut.gridwidth = 3;
- gbc_verticalStrut.insets = new Insets(0, 0, 5, 5);
- gbc_verticalStrut.gridx = 7;
- gbc_verticalStrut.gridy = 1;
- panelLogin.add(verticalStrut, gbc_verticalStrut);
- Component horizontalStrut = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut = new GridBagConstraints();
- gbc_horizontalStrut.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut.gridx = 1;
- gbc_horizontalStrut.gridy = 2;
- panelLogin.add(horizontalStrut, gbc_horizontalStrut);
- Component horizontalStrut_1 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_1 = new GridBagConstraints();
- gbc_horizontalStrut_1.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_1.gridx = 2;
- gbc_horizontalStrut_1.gridy = 2;
- panelLogin.add(horizontalStrut_1, gbc_horizontalStrut_1);
- Component horizontalStrut_2 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_2 = new GridBagConstraints();
- gbc_horizontalStrut_2.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_2.gridx = 3;
- gbc_horizontalStrut_2.gridy = 2;
- panelLogin.add(horizontalStrut_2, gbc_horizontalStrut_2);
- Component horizontalStrut_3 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_3 = new GridBagConstraints();
- gbc_horizontalStrut_3.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_3.gridx = 4;
- gbc_horizontalStrut_3.gridy = 2;
- panelLogin.add(horizontalStrut_3, gbc_horizontalStrut_3);
- Component horizontalStrut_4 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_4 = new GridBagConstraints();
- gbc_horizontalStrut_4.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_4.gridx = 5;
- gbc_horizontalStrut_4.gridy = 2;
- panelLogin.add(horizontalStrut_4, gbc_horizontalStrut_4);
- JLabel lblUsername_1 = new JLabel("Username:");
- GridBagConstraints gbc_lblUsername_1 = new GridBagConstraints();
- gbc_lblUsername_1.anchor = GridBagConstraints.EAST;
- gbc_lblUsername_1.insets = new Insets(0, 0, 5, 5);
- gbc_lblUsername_1.gridx = 6;
- gbc_lblUsername_1.gridy = 2;
- panelLogin.add(lblUsername_1, gbc_lblUsername_1);
- textUsernameLogin = new JTextField();
- GridBagConstraints gbc_textUsernameLogin = new GridBagConstraints();
- gbc_textUsernameLogin.gridwidth = 3;
- gbc_textUsernameLogin.insets = new Insets(0, 0, 5, 5);
- gbc_textUsernameLogin.fill = GridBagConstraints.HORIZONTAL;
- gbc_textUsernameLogin.gridx = 7;
- gbc_textUsernameLogin.gridy = 2;
- panelLogin.add(textUsernameLogin, gbc_textUsernameLogin);
- textUsernameLogin.setColumns(10);
- Component horizontalStrut_7 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_7 = new GridBagConstraints();
- gbc_horizontalStrut_7.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_7.gridx = 11;
- gbc_horizontalStrut_7.gridy = 2;
- panelLogin.add(horizontalStrut_7, gbc_horizontalStrut_7);
- Component horizontalStrut_9 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_9 = new GridBagConstraints();
- gbc_horizontalStrut_9.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_9.gridx = 12;
- gbc_horizontalStrut_9.gridy = 2;
- panelLogin.add(horizontalStrut_9, gbc_horizontalStrut_9);
- Component horizontalStrut_5 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_5 = new GridBagConstraints();
- gbc_horizontalStrut_5.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_5.gridx = 13;
- gbc_horizontalStrut_5.gridy = 2;
- panelLogin.add(horizontalStrut_5, gbc_horizontalStrut_5);
- Component horizontalStrut_6 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_6 = new GridBagConstraints();
- gbc_horizontalStrut_6.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_6.gridx = 14;
- gbc_horizontalStrut_6.gridy = 2;
- panelLogin.add(horizontalStrut_6, gbc_horizontalStrut_6);
- Component horizontalStrut_8 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_8 = new GridBagConstraints();
- gbc_horizontalStrut_8.insets = new Insets(0, 0, 5, 0);
- gbc_horizontalStrut_8.gridx = 15;
- gbc_horizontalStrut_8.gridy = 2;
- panelLogin.add(horizontalStrut_8, gbc_horizontalStrut_8);
- JLabel lblPassword_1 = new JLabel("Password:");
- GridBagConstraints gbc_lblPassword_1 = new GridBagConstraints();
- gbc_lblPassword_1.anchor = GridBagConstraints.EAST;
- gbc_lblPassword_1.insets = new Insets(0, 0, 5, 5);
- gbc_lblPassword_1.gridx = 6;
- gbc_lblPassword_1.gridy = 3;
- panelLogin.add(lblPassword_1, gbc_lblPassword_1);
- JButton btnLogin_1 = new JButton("Login");
- btnLogin_1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String username = textUsernameLogin.getText();
- String password = passwordLogin.getText();
- try {
- Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
- Statement inst = lig.createStatement();
- ResultSet resultado = inst
- .executeQuery("select palavraChave, idCliente FROM cliente where username = '" + username + "'");
- while (resultado.next()) {
- String passworddb = resultado.getString("palavraChave");
- if(password.equals(passworddb)) {
- JOptionPane.showMessageDialog(null, "Login com sucesso");
- currentUserID = resultado.getInt("idCliente");
- /** Mudar de Painel para o perfil */
- frame.getContentPane().removeAll();
- frame.getContentPane().add(panelPerfil);
- frame.revalidate();
- frame.repaint();
- /** Definir os botões do menu (login e registo) como disabled */
- mntmLogin.setEnabled(false);
- mntmRegisto.setEnabled(false);
- mntmPerfil.setEnabled(true);
- mntmLogout.setEnabled(true);
- mntmEscrever.setEnabled(true);
- mntmInbox.setEnabled(true);
- /** Limpar os campos de utilizador e password */
- textUsernameLogin.setText("");
- passwordLogin.setText("");
- perfilSetup();
- }
- else {
- JOptionPane.showMessageDialog(null, "Login Falhado, password ou username errados.");
- passwordLogin.setText("");
- }
- }
- lig.close();
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "BD indísponivel! \n" + ex.getMessage());
- }
- }
- });
- passwordLogin = new JTextField();
- GridBagConstraints gbc_passwordLogin = new GridBagConstraints();
- gbc_passwordLogin.gridwidth = 3;
- gbc_passwordLogin.insets = new Insets(0, 0, 5, 5);
- gbc_passwordLogin.fill = GridBagConstraints.HORIZONTAL;
- gbc_passwordLogin.gridx = 7;
- gbc_passwordLogin.gridy = 3;
- panelLogin.add(passwordLogin, gbc_passwordLogin);
- passwordLogin.setColumns(10);
- GridBagConstraints gbc_btnLogin_1 = new GridBagConstraints();
- gbc_btnLogin_1.insets = new Insets(0, 0, 0, 5);
- gbc_btnLogin_1.gridx = 7;
- gbc_btnLogin_1.gridy = 5;
- panelLogin.add(btnLogin_1, gbc_btnLogin_1);
- JButton btnRegistar_1 = new JButton("Registar");
- btnRegistar_1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- frame.getContentPane().removeAll();
- frame.getContentPane().add(panelRegisto);
- frame.revalidate();
- frame.repaint();
- }
- });
- GridBagConstraints gbc_btnRegistar_1 = new GridBagConstraints();
- gbc_btnRegistar_1.insets = new Insets(0, 0, 0, 5);
- gbc_btnRegistar_1.gridx = 8;
- gbc_btnRegistar_1.gridy = 5;
- panelLogin.add(btnRegistar_1, gbc_btnRegistar_1);
- JButton btnPasswordForget = new JButton("Esqueci-me da palavra-passe");
- btnPasswordForget.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- frame.getContentPane().removeAll();
- frame.getContentPane().add(panelForgot);
- frame.revalidate();
- frame.repaint();
- textUsernameLogin.setText("");
- passwordLogin.setText("");
- }
- });
- GridBagConstraints gbc_btnPasswordForget = new GridBagConstraints();
- gbc_btnPasswordForget.insets = new Insets(0, 0, 0, 5);
- gbc_btnPasswordForget.gridx = 9;
- gbc_btnPasswordForget.gridy = 5;
- panelLogin.add(btnPasswordForget, gbc_btnPasswordForget);
- panelRegisto = new JPanel();
- frame.getContentPane().add(panelRegisto, "name_947819464113314");
- GridBagLayout gbl_panelRegisto = new GridBagLayout();
- gbl_panelRegisto.columnWidths = new int[]{0, 0, 15, 0, 0, 0, 0, 0, 0, 0};
- gbl_panelRegisto.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- 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};
- 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};
- panelRegisto.setLayout(gbl_panelRegisto);
- Component horizontalStrut_10 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_10 = new GridBagConstraints();
- gbc_horizontalStrut_10.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_10.gridx = 0;
- gbc_horizontalStrut_10.gridy = 0;
- panelRegisto.add(horizontalStrut_10, gbc_horizontalStrut_10);
- JLabel lblRegisto = new JLabel("Registo");
- GridBagConstraints gbc_lblRegisto = new GridBagConstraints();
- gbc_lblRegisto.gridwidth = 3;
- gbc_lblRegisto.insets = new Insets(0, 0, 5, 5);
- gbc_lblRegisto.gridx = 1;
- gbc_lblRegisto.gridy = 0;
- panelRegisto.add(lblRegisto, gbc_lblRegisto);
- Component horizontalStrut_11 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_11 = new GridBagConstraints();
- gbc_horizontalStrut_11.insets = new Insets(0, 0, 5, 0);
- gbc_horizontalStrut_11.gridx = 8;
- gbc_horizontalStrut_11.gridy = 0;
- panelRegisto.add(horizontalStrut_11, gbc_horizontalStrut_11);
- JLabel lblNome = new JLabel("Nome:");
- GridBagConstraints gbc_lblNome = new GridBagConstraints();
- gbc_lblNome.anchor = GridBagConstraints.WEST;
- gbc_lblNome.insets = new Insets(0, 0, 5, 5);
- gbc_lblNome.gridx = 1;
- gbc_lblNome.gridy = 1;
- panelRegisto.add(lblNome, gbc_lblNome);
- textNome = new JTextField();
- GridBagConstraints gbc_textNome = new GridBagConstraints();
- gbc_textNome.gridwidth = 6;
- gbc_textNome.insets = new Insets(0, 0, 5, 5);
- gbc_textNome.fill = GridBagConstraints.HORIZONTAL;
- gbc_textNome.gridx = 2;
- gbc_textNome.gridy = 1;
- panelRegisto.add(textNome, gbc_textNome);
- textNome.setColumns(10);
- JLabel lblApelido = new JLabel("Apelido:");
- GridBagConstraints gbc_lblApelido = new GridBagConstraints();
- gbc_lblApelido.anchor = GridBagConstraints.WEST;
- gbc_lblApelido.insets = new Insets(0, 0, 5, 5);
- gbc_lblApelido.gridx = 1;
- gbc_lblApelido.gridy = 2;
- panelRegisto.add(lblApelido, gbc_lblApelido);
- textApelido = new JTextField();
- GridBagConstraints gbc_textApelido = new GridBagConstraints();
- gbc_textApelido.gridwidth = 6;
- gbc_textApelido.insets = new Insets(0, 0, 5, 5);
- gbc_textApelido.fill = GridBagConstraints.HORIZONTAL;
- gbc_textApelido.gridx = 2;
- gbc_textApelido.gridy = 2;
- panelRegisto.add(textApelido, gbc_textApelido);
- textApelido.setColumns(10);
- JLabel lblId = new JLabel("ID:");
- GridBagConstraints gbc_lblId = new GridBagConstraints();
- gbc_lblId.anchor = GridBagConstraints.WEST;
- gbc_lblId.insets = new Insets(0, 0, 5, 5);
- gbc_lblId.gridx = 1;
- gbc_lblId.gridy = 3;
- panelRegisto.add(lblId, gbc_lblId);
- textID = new JTextField();
- textID.setEditable(false);
- textID.setEnabled(false);
- GridBagConstraints gbc_textID = new GridBagConstraints();
- gbc_textID.gridwidth = 6;
- gbc_textID.insets = new Insets(0, 0, 5, 5);
- gbc_textID.fill = GridBagConstraints.HORIZONTAL;
- gbc_textID.gridx = 2;
- gbc_textID.gridy = 3;
- panelRegisto.add(textID, gbc_textID);
- textID.setColumns(10);
- try {
- Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
- PreparedStatement inst = lig.prepareStatement("SELECT MAX(idCliente) FROM cliente");
- ResultSet res = inst.executeQuery();
- if (res.next()) {
- idCliente = res.getInt(1);
- textID.setText("" + (idCliente + 1));
- }
- } catch (SQLException e) {
- JOptionPane.showMessageDialog(frame, "BD indisponível!" + e.getMessage());
- }
- JLabel lblUsername = new JLabel("Username:");
- GridBagConstraints gbc_lblUsername = new GridBagConstraints();
- gbc_lblUsername.anchor = GridBagConstraints.WEST;
- gbc_lblUsername.insets = new Insets(0, 0, 5, 5);
- gbc_lblUsername.gridx = 1;
- gbc_lblUsername.gridy = 4;
- panelRegisto.add(lblUsername, gbc_lblUsername);
- textUsername = new JTextField();
- GridBagConstraints gbc_textUsername = new GridBagConstraints();
- gbc_textUsername.gridwidth = 6;
- gbc_textUsername.insets = new Insets(0, 0, 5, 5);
- gbc_textUsername.fill = GridBagConstraints.HORIZONTAL;
- gbc_textUsername.gridx = 2;
- gbc_textUsername.gridy = 4;
- panelRegisto.add(textUsername, gbc_textUsername);
- textUsername.setColumns(10);
- JLabel lblPassword = new JLabel("Password:");
- GridBagConstraints gbc_lblPassword = new GridBagConstraints();
- gbc_lblPassword.anchor = GridBagConstraints.WEST;
- gbc_lblPassword.insets = new Insets(0, 0, 5, 5);
- gbc_lblPassword.gridx = 1;
- gbc_lblPassword.gridy = 5;
- panelRegisto.add(lblPassword, gbc_lblPassword);
- passwordRegisto = new JTextField();
- GridBagConstraints gbc_passwordRegisto = new GridBagConstraints();
- gbc_passwordRegisto.gridwidth = 6;
- gbc_passwordRegisto.insets = new Insets(0, 0, 5, 5);
- gbc_passwordRegisto.fill = GridBagConstraints.HORIZONTAL;
- gbc_passwordRegisto.gridx = 2;
- gbc_passwordRegisto.gridy = 5;
- panelRegisto.add(passwordRegisto, gbc_passwordRegisto);
- passwordRegisto.setColumns(10);
- JLabel lblDataDeNascimento = new JLabel("Data de Nascimento:");
- GridBagConstraints gbc_lblDataDeNascimento = new GridBagConstraints();
- gbc_lblDataDeNascimento.anchor = GridBagConstraints.WEST;
- gbc_lblDataDeNascimento.insets = new Insets(0, 0, 5, 5);
- gbc_lblDataDeNascimento.gridx = 1;
- gbc_lblDataDeNascimento.gridy = 6;
- panelRegisto.add(lblDataDeNascimento, gbc_lblDataDeNascimento);
- textDataNascimento = new JTextField();
- GridBagConstraints gbc_textDataNascimento = new GridBagConstraints();
- gbc_textDataNascimento.gridwidth = 6;
- gbc_textDataNascimento.insets = new Insets(0, 0, 5, 5);
- gbc_textDataNascimento.fill = GridBagConstraints.HORIZONTAL;
- gbc_textDataNascimento.gridx = 2;
- gbc_textDataNascimento.gridy = 6;
- panelRegisto.add(textDataNascimento, gbc_textDataNascimento);
- textDataNascimento.addFocusListener(new FocusAdapter() {
- public void focusGained(FocusEvent e){
- if(textDataNascimento.getText().equals("AAAA-MM-DD")){
- textDataNascimento.setText("");
- textDataNascimento.setForeground(Color.BLACK);
- }
- }
- public void focusLost(FocusEvent x){
- if(textDataNascimento.getText().equals("")){
- textDataNascimento.setText("AAAA-MM-DD");
- textDataNascimento.setForeground(Color.GRAY);
- }
- }
- });
- JLabel lblTipoDeSangue = new JLabel("Tipo de Sangue:");
- GridBagConstraints gbc_lblTipoDeSangue = new GridBagConstraints();
- gbc_lblTipoDeSangue.anchor = GridBagConstraints.WEST;
- gbc_lblTipoDeSangue.insets = new Insets(0, 0, 5, 5);
- gbc_lblTipoDeSangue.gridx = 1;
- gbc_lblTipoDeSangue.gridy = 7;
- panelRegisto.add(lblTipoDeSangue, gbc_lblTipoDeSangue);
- JComboBox comboBoxTipoSangue = new JComboBox();
- comboBoxTipoSangue.setModel(
- new DefaultComboBoxModel(new String[] { "...", "O+", "O-", "A+", "A-", "B+", "B-", "AB+", "AB-" }));
- GridBagConstraints gbc_comboBoxTipoSangue = new GridBagConstraints();
- gbc_comboBoxTipoSangue.insets = new Insets(0, 0, 5, 5);
- gbc_comboBoxTipoSangue.fill = GridBagConstraints.HORIZONTAL;
- gbc_comboBoxTipoSangue.gridx = 2;
- gbc_comboBoxTipoSangue.gridy = 7;
- panelRegisto.add(comboBoxTipoSangue, gbc_comboBoxTipoSangue);
- JLabel lblSexo = new JLabel("Sexo:");
- GridBagConstraints gbc_lblSexo = new GridBagConstraints();
- gbc_lblSexo.anchor = GridBagConstraints.WEST;
- gbc_lblSexo.insets = new Insets(0, 0, 5, 5);
- gbc_lblSexo.gridx = 1;
- gbc_lblSexo.gridy = 8;
- panelRegisto.add(lblSexo, gbc_lblSexo);
- JComboBox comboBoxSexo = new JComboBox();
- comboBoxSexo.setModel(
- new DefaultComboBoxModel(new String[] { "...", "Masculino", "Feminino" }));
- GridBagConstraints gbc_comboBoxSexo = new GridBagConstraints();
- gbc_comboBoxSexo.insets = new Insets(0, 0, 5, 5);
- gbc_comboBoxSexo.fill = GridBagConstraints.HORIZONTAL;
- gbc_comboBoxSexo.gridx = 2;
- gbc_comboBoxSexo.gridy = 8;
- panelRegisto.add(comboBoxSexo, gbc_comboBoxSexo);
- JLabel lblEmail = new JLabel("Email:");
- GridBagConstraints gbc_lblEmail = new GridBagConstraints();
- gbc_lblEmail.anchor = GridBagConstraints.WEST;
- gbc_lblEmail.insets = new Insets(0, 0, 5, 5);
- gbc_lblEmail.gridx = 1;
- gbc_lblEmail.gridy = 9;
- panelRegisto.add(lblEmail, gbc_lblEmail);
- textEmail = new JTextField();
- GridBagConstraints gbc_textEmail = new GridBagConstraints();
- gbc_textEmail.gridwidth = 6;
- gbc_textEmail.insets = new Insets(0, 0, 5, 5);
- gbc_textEmail.fill = GridBagConstraints.HORIZONTAL;
- gbc_textEmail.gridx = 2;
- gbc_textEmail.gridy = 9;
- panelRegisto.add(textEmail, gbc_textEmail);
- textEmail.setColumns(10);
- textEmail.addFocusListener(new FocusAdapter() {
- public void focusGained(FocusEvent e){
- if(textEmail.getText().equals("Tudo em minúsculas")){
- textEmail.setText("");
- textEmail.setForeground(Color.BLACK);
- }
- }
- public void focusLost(FocusEvent x){
- if(textEmail.getText().equals("")){
- textEmail.setText("Tudo em minúsculas");
- textEmail.setForeground(Color.GRAY);
- }
- }
- });
- JLabel lblContacto = new JLabel("Contacto:");
- GridBagConstraints gbc_lblContacto = new GridBagConstraints();
- gbc_lblContacto.anchor = GridBagConstraints.WEST;
- gbc_lblContacto.insets = new Insets(0, 0, 5, 5);
- gbc_lblContacto.gridx = 1;
- gbc_lblContacto.gridy = 10;
- panelRegisto.add(lblContacto, gbc_lblContacto);
- textContacto = new JTextField();
- GridBagConstraints gbc_textContacto = new GridBagConstraints();
- gbc_textContacto.gridwidth = 6;
- gbc_textContacto.insets = new Insets(0, 0, 5, 5);
- gbc_textContacto.fill = GridBagConstraints.HORIZONTAL;
- gbc_textContacto.gridx = 2;
- gbc_textContacto.gridy = 10;
- panelRegisto.add(textContacto, gbc_textContacto);
- textContacto.setColumns(10);
- JLabel lblMorada = new JLabel("Morada:");
- GridBagConstraints gbc_lblMorada = new GridBagConstraints();
- gbc_lblMorada.anchor = GridBagConstraints.WEST;
- gbc_lblMorada.insets = new Insets(0, 0, 5, 5);
- gbc_lblMorada.gridx = 1;
- gbc_lblMorada.gridy = 11;
- panelRegisto.add(lblMorada, gbc_lblMorada);
- textMorada = new JTextField();
- GridBagConstraints gbc_textMorada = new GridBagConstraints();
- gbc_textMorada.gridwidth = 6;
- gbc_textMorada.insets = new Insets(0, 0, 5, 5);
- gbc_textMorada.fill = GridBagConstraints.HORIZONTAL;
- gbc_textMorada.gridx = 2;
- gbc_textMorada.gridy = 11;
- panelRegisto.add(textMorada, gbc_textMorada);
- textMorada.setColumns(10);
- /*Botão para registar Clientes */
- JButton btnRegistar = new JButton("Registar");
- btnRegistar.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- String username = textUsername.getText();
- boolean usernameSame = true;
- //verificar se ja existe o username
- try {
- Connection ligRegisto = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
- Statement instRegisto = ligRegisto.createStatement();
- ResultSet resultadoRegisto = instRegisto
- .executeQuery("SELECT username FROM cliente where username = '" + username +"'");
- if(resultadoRegisto.next() == false) {
- usernameSame = false;
- }
- else {
- usernameSame = true;
- }
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "BD indísponivel! | " + ex);
- }
- try {
- Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
- String id = textID.getText();
- String nome = textNome.getText();
- String apelido = textApelido.getText();
- String password = passwordRegisto.getText();
- DateTimeFormatter date = DateTimeFormatter.ofPattern("yyyy-MM-dd");
- LocalDate data = LocalDate.parse(textDataNascimento.getText(), date);
- String tipoSangue = (String) comboBoxTipoSangue.getSelectedItem();
- if(tipoSangue == "...") {
- tipoSangue = null;
- }
- String sexo = (String) comboBoxSexo.getSelectedItem();
- if(sexo == "...") {
- sexo = null;
- }
- String email = textEmail.getText();
- String contacto = textContacto.getText();
- String morada = textMorada.getText();
- if(usernameSame == false) {
- PreparedStatement inst = lig.prepareStatement(
- "INSERT INTO cliente (idCliente, nome, apelido, username, palavraChave, dataNascimento, tipoSangue, sexo, email, contacto, morada) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
- inst.setString(1, id);
- inst.setString(2, nome);
- inst.setString(3, apelido);
- inst.setString(4, username);
- inst.setString(5, password);
- inst.setObject(6, data);
- inst.setString(7, tipoSangue);
- inst.setString(8, sexo);
- inst.setString(9, email);
- inst.setString(10, contacto);
- inst.setString(11, morada);
- int linhasAlteradas = inst.executeUpdate();
- if (linhasAlteradas == 1) {
- JOptionPane.showMessageDialog(null, "Registo Inserido");
- } else {
- JOptionPane.showMessageDialog(null, "Registo não Inserido");
- }
- lig.close();
- textID.setText("");
- textNome.setText("");
- textApelido.setText("");
- textUsername.setText("");
- passwordRegisto.setText("");
- comboBoxTipoSangue.setSelectedIndex(0);
- comboBoxSexo.setSelectedIndex(0);
- textContacto.setText("");
- textMorada.setText("");
- textEmail.setText("Tudo em minúsculas");
- textEmail.setForeground(Color.GRAY);
- textDataNascimento.setText("AAAA-MM-DD");
- textDataNascimento.setForeground(Color.GRAY);
- }
- else {
- JOptionPane.showMessageDialog(null,"O username (" + username + ") já está a ser utilizado, escolha outro.");
- textUsername.setText("");
- }
- }catch (SQLException e) {
- JOptionPane.showMessageDialog(frame, "Base de dados indisponivel: " + e.getMessage());
- }
- try {
- Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
- PreparedStatement inst = lig.prepareStatement("SELECT MAX(idCliente) FROM cliente");
- ResultSet res = inst.executeQuery();
- if (res.next()) {
- idCliente = res.getInt(1);
- textID.setText("" + (idCliente + 1));
- }
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(frame, "BD indisponível!" + ex.getMessage());
- }
- }
- });
- GridBagConstraints gbc_btnRegistar = new GridBagConstraints();
- gbc_btnRegistar.gridwidth = 4;
- gbc_btnRegistar.insets = new Insets(0, 0, 0, 5);
- gbc_btnRegistar.gridx = 2;
- gbc_btnRegistar.gridy = 13;
- panelRegisto.add(btnRegistar, gbc_btnRegistar);
- panelPerfil = new JPanel();
- frame.getContentPane().add(panelPerfil, "name_205706181382062");
- GridBagLayout gbl_panelPerfil = new GridBagLayout();
- gbl_panelPerfil.columnWidths = new int[]{0, 214, 44, 44, 0, 0, 0, 0, 0, 0, 0, 0};
- gbl_panelPerfil.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- 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};
- 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};
- panelPerfil.setLayout(gbl_panelPerfil);
- JLabel labelPerfil = new JLabel("Perfil");
- GridBagConstraints gbc_labelPerfil = new GridBagConstraints();
- gbc_labelPerfil.gridwidth = 11;
- gbc_labelPerfil.insets = new Insets(0, 0, 5, 0);
- gbc_labelPerfil.gridx = 0;
- gbc_labelPerfil.gridy = 0;
- panelPerfil.add(labelPerfil, gbc_labelPerfil);
- JLabel labelNomePerfil = new JLabel("Nome:");
- GridBagConstraints gbc_labelNomePerfil = new GridBagConstraints();
- gbc_labelNomePerfil.anchor = GridBagConstraints.WEST;
- gbc_labelNomePerfil.insets = new Insets(0, 0, 5, 5);
- gbc_labelNomePerfil.gridx = 0;
- gbc_labelNomePerfil.gridy = 1;
- panelPerfil.add(labelNomePerfil, gbc_labelNomePerfil);
- textNomePerfil = new JTextField();
- textNomePerfil.setEditable(false);
- textNomePerfil.setColumns(10);
- GridBagConstraints gbc_textNomePerfil = new GridBagConstraints();
- gbc_textNomePerfil.fill = GridBagConstraints.HORIZONTAL;
- gbc_textNomePerfil.gridwidth = 3;
- gbc_textNomePerfil.insets = new Insets(0, 0, 5, 5);
- gbc_textNomePerfil.gridx = 1;
- gbc_textNomePerfil.gridy = 1;
- panelPerfil.add(textNomePerfil, gbc_textNomePerfil);
- JLabel labelApelidoPerfil = new JLabel("Apelido:");
- GridBagConstraints gbc_labelApelidoPerfil = new GridBagConstraints();
- gbc_labelApelidoPerfil.anchor = GridBagConstraints.WEST;
- gbc_labelApelidoPerfil.insets = new Insets(0, 0, 5, 5);
- gbc_labelApelidoPerfil.gridx = 0;
- gbc_labelApelidoPerfil.gridy = 2;
- panelPerfil.add(labelApelidoPerfil, gbc_labelApelidoPerfil);
- textApelidoPerfil = new JTextField();
- textApelidoPerfil.setEditable(false);
- textApelidoPerfil.setColumns(10);
- GridBagConstraints gbc_textApelidoPerfil = new GridBagConstraints();
- gbc_textApelidoPerfil.fill = GridBagConstraints.HORIZONTAL;
- gbc_textApelidoPerfil.gridwidth = 3;
- gbc_textApelidoPerfil.insets = new Insets(0, 0, 5, 5);
- gbc_textApelidoPerfil.gridx = 1;
- gbc_textApelidoPerfil.gridy = 2;
- panelPerfil.add(textApelidoPerfil, gbc_textApelidoPerfil);
- JLabel lblImagemDePerfil = new JLabel("Imagem de Perfil");
- GridBagConstraints gbc_lblImagemDePerfil = new GridBagConstraints();
- gbc_lblImagemDePerfil.gridwidth = 4;
- gbc_lblImagemDePerfil.gridheight = 4;
- gbc_lblImagemDePerfil.insets = new Insets(0, 0, 5, 5);
- gbc_lblImagemDePerfil.gridx = 6;
- gbc_lblImagemDePerfil.gridy = 1;
- panelPerfil.add(lblImagemDePerfil, gbc_lblImagemDePerfil);
- JLabel labelIDPerfil = new JLabel("ID:");
- GridBagConstraints gbc_labelIDPerfil = new GridBagConstraints();
- gbc_labelIDPerfil.anchor = GridBagConstraints.WEST;
- gbc_labelIDPerfil.insets = new Insets(0, 0, 5, 5);
- gbc_labelIDPerfil.gridx = 0;
- gbc_labelIDPerfil.gridy = 3;
- panelPerfil.add(labelIDPerfil, gbc_labelIDPerfil);
- textIDPerfil = new JTextField();
- textIDPerfil.setEnabled(false);
- textIDPerfil.setEditable(false);
- textIDPerfil.setColumns(10);
- GridBagConstraints gbc_textIDPerfil = new GridBagConstraints();
- gbc_textIDPerfil.fill = GridBagConstraints.HORIZONTAL;
- gbc_textIDPerfil.insets = new Insets(0, 0, 5, 5);
- gbc_textIDPerfil.gridx = 1;
- gbc_textIDPerfil.gridy = 3;
- panelPerfil.add(textIDPerfil, gbc_textIDPerfil);
- JLabel labelUsernamePerfil = new JLabel("Username:");
- GridBagConstraints gbc_labelUsernamePerfil = new GridBagConstraints();
- gbc_labelUsernamePerfil.anchor = GridBagConstraints.WEST;
- gbc_labelUsernamePerfil.insets = new Insets(0, 0, 5, 5);
- gbc_labelUsernamePerfil.gridx = 0;
- gbc_labelUsernamePerfil.gridy = 4;
- panelPerfil.add(labelUsernamePerfil, gbc_labelUsernamePerfil);
- textUsernamePerfil = new JTextField();
- textUsernamePerfil.setEditable(false);
- textUsernamePerfil.setColumns(10);
- GridBagConstraints gbc_textUsernamePerfil = new GridBagConstraints();
- gbc_textUsernamePerfil.fill = GridBagConstraints.HORIZONTAL;
- gbc_textUsernamePerfil.gridwidth = 3;
- gbc_textUsernamePerfil.insets = new Insets(0, 0, 5, 5);
- gbc_textUsernamePerfil.gridx = 1;
- gbc_textUsernamePerfil.gridy = 4;
- panelPerfil.add(textUsernamePerfil, gbc_textUsernamePerfil);
- JLabel labelPasswordPerfil = new JLabel("Password:");
- GridBagConstraints gbc_labelPasswordPerfil = new GridBagConstraints();
- gbc_labelPasswordPerfil.anchor = GridBagConstraints.WEST;
- gbc_labelPasswordPerfil.insets = new Insets(0, 0, 5, 5);
- gbc_labelPasswordPerfil.gridx = 0;
- gbc_labelPasswordPerfil.gridy = 5;
- panelPerfil.add(labelPasswordPerfil, gbc_labelPasswordPerfil);
- JButton btnEditarPassword = new JButton("Mudar a palavra-passe");
- btnEditarPassword.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- //Mudar para o painel de mudar password
- frame.getContentPane().removeAll();
- frame.getContentPane().add(panelPassword);
- frame.revalidate();
- frame.repaint();
- }
- });
- GridBagConstraints gbc_btnEditarPassword = new GridBagConstraints();
- gbc_btnEditarPassword.anchor = GridBagConstraints.WEST;
- gbc_btnEditarPassword.gridwidth = 2;
- gbc_btnEditarPassword.insets = new Insets(0, 0, 5, 5);
- gbc_btnEditarPassword.gridx = 1;
- gbc_btnEditarPassword.gridy = 5;
- panelPerfil.add(btnEditarPassword, gbc_btnEditarPassword);
- JLabel lblHistrico = new JLabel("Hist\u00F3rico");
- GridBagConstraints gbc_lblHistrico = new GridBagConstraints();
- gbc_lblHistrico.gridwidth = 5;
- gbc_lblHistrico.insets = new Insets(0, 0, 5, 5);
- gbc_lblHistrico.gridx = 5;
- gbc_lblHistrico.gridy = 5;
- panelPerfil.add(lblHistrico, gbc_lblHistrico);
- JLabel labelDataNascimentoPerfil = new JLabel("Data de Nascimento:");
- GridBagConstraints gbc_labelDataNascimentoPerfil = new GridBagConstraints();
- gbc_labelDataNascimentoPerfil.anchor = GridBagConstraints.WEST;
- gbc_labelDataNascimentoPerfil.insets = new Insets(0, 0, 5, 5);
- gbc_labelDataNascimentoPerfil.gridx = 0;
- gbc_labelDataNascimentoPerfil.gridy = 6;
- panelPerfil.add(labelDataNascimentoPerfil, gbc_labelDataNascimentoPerfil);
- textDataNascimentoPerfil = new JTextField();
- textDataNascimentoPerfil.setEditable(false);
- GridBagConstraints gbc_textDataNascimentoPerfil = new GridBagConstraints();
- gbc_textDataNascimentoPerfil.fill = GridBagConstraints.HORIZONTAL;
- gbc_textDataNascimentoPerfil.gridwidth = 3;
- gbc_textDataNascimentoPerfil.insets = new Insets(0, 0, 5, 5);
- gbc_textDataNascimentoPerfil.gridx = 1;
- gbc_textDataNascimentoPerfil.gridy = 6;
- panelPerfil.add(textDataNascimentoPerfil, gbc_textDataNascimentoPerfil);
- JList listaHistoricoPerfil = new JList();
- GridBagConstraints gbc_listaHistoricoPerfil = new GridBagConstraints();
- gbc_listaHistoricoPerfil.gridheight = 7;
- gbc_listaHistoricoPerfil.gridwidth = 5;
- gbc_listaHistoricoPerfil.insets = new Insets(0, 0, 5, 5);
- gbc_listaHistoricoPerfil.fill = GridBagConstraints.BOTH;
- gbc_listaHistoricoPerfil.gridx = 5;
- gbc_listaHistoricoPerfil.gridy = 6;
- panelPerfil.add(listaHistoricoPerfil, gbc_listaHistoricoPerfil);
- JLabel labelTipoSanguePerfil = new JLabel("Tipo de Sangue:");
- GridBagConstraints gbc_labelTipoSanguePerfil = new GridBagConstraints();
- gbc_labelTipoSanguePerfil.anchor = GridBagConstraints.WEST;
- gbc_labelTipoSanguePerfil.insets = new Insets(0, 0, 5, 5);
- gbc_labelTipoSanguePerfil.gridx = 0;
- gbc_labelTipoSanguePerfil.gridy = 7;
- panelPerfil.add(labelTipoSanguePerfil, gbc_labelTipoSanguePerfil);
- textTipoSanguePerfil = new JTextField();
- textTipoSanguePerfil.setEditable(false);
- GridBagConstraints gbc_textTipoSanguePerfil = new GridBagConstraints();
- gbc_textTipoSanguePerfil.gridwidth = 3;
- gbc_textTipoSanguePerfil.insets = new Insets(0, 0, 5, 5);
- gbc_textTipoSanguePerfil.fill = GridBagConstraints.HORIZONTAL;
- gbc_textTipoSanguePerfil.gridx = 1;
- gbc_textTipoSanguePerfil.gridy = 7;
- panelPerfil.add(textTipoSanguePerfil, gbc_textTipoSanguePerfil);
- textTipoSanguePerfil.setColumns(10);
- JLabel labelSexoPerfil = new JLabel("Sexo:");
- GridBagConstraints gbc_labelSexoPerfil = new GridBagConstraints();
- gbc_labelSexoPerfil.anchor = GridBagConstraints.WEST;
- gbc_labelSexoPerfil.insets = new Insets(0, 0, 5, 5);
- gbc_labelSexoPerfil.gridx = 0;
- gbc_labelSexoPerfil.gridy = 8;
- panelPerfil.add(labelSexoPerfil, gbc_labelSexoPerfil);
- textSexoPerfil = new JTextField();
- textSexoPerfil.setEditable(false);
- GridBagConstraints gbc_textSexoPerfil = new GridBagConstraints();
- gbc_textSexoPerfil.gridwidth = 3;
- gbc_textSexoPerfil.insets = new Insets(0, 0, 5, 5);
- gbc_textSexoPerfil.fill = GridBagConstraints.HORIZONTAL;
- gbc_textSexoPerfil.gridx = 1;
- gbc_textSexoPerfil.gridy = 8;
- panelPerfil.add(textSexoPerfil, gbc_textSexoPerfil);
- textSexoPerfil.setColumns(10);
- JLabel labelEmailPerfil = new JLabel("Email:");
- GridBagConstraints gbc_labelEmailPerfil = new GridBagConstraints();
- gbc_labelEmailPerfil.anchor = GridBagConstraints.WEST;
- gbc_labelEmailPerfil.insets = new Insets(0, 0, 5, 5);
- gbc_labelEmailPerfil.gridx = 0;
- gbc_labelEmailPerfil.gridy = 9;
- panelPerfil.add(labelEmailPerfil, gbc_labelEmailPerfil);
- textEmailPerfil = new JTextField();
- textEmailPerfil.setEditable(false);
- textEmailPerfil.setColumns(10);
- GridBagConstraints gbc_textEmailPerfil = new GridBagConstraints();
- gbc_textEmailPerfil.fill = GridBagConstraints.HORIZONTAL;
- gbc_textEmailPerfil.gridwidth = 3;
- gbc_textEmailPerfil.insets = new Insets(0, 0, 5, 5);
- gbc_textEmailPerfil.gridx = 1;
- gbc_textEmailPerfil.gridy = 9;
- panelPerfil.add(textEmailPerfil, gbc_textEmailPerfil);
- JLabel labelContactoPerfil = new JLabel("Contacto:");
- GridBagConstraints gbc_labelContactoPerfil = new GridBagConstraints();
- gbc_labelContactoPerfil.anchor = GridBagConstraints.WEST;
- gbc_labelContactoPerfil.insets = new Insets(0, 0, 5, 5);
- gbc_labelContactoPerfil.gridx = 0;
- gbc_labelContactoPerfil.gridy = 10;
- panelPerfil.add(labelContactoPerfil, gbc_labelContactoPerfil);
- textContactoPerfil = new JTextField();
- textContactoPerfil.setEditable(false);
- textContactoPerfil.setColumns(10);
- GridBagConstraints gbc_textContactoPerfil = new GridBagConstraints();
- gbc_textContactoPerfil.fill = GridBagConstraints.HORIZONTAL;
- gbc_textContactoPerfil.gridwidth = 3;
- gbc_textContactoPerfil.insets = new Insets(0, 0, 5, 5);
- gbc_textContactoPerfil.gridx = 1;
- gbc_textContactoPerfil.gridy = 10;
- panelPerfil.add(textContactoPerfil, gbc_textContactoPerfil);
- JLabel labelMoradaPerfil = new JLabel("Morada:");
- GridBagConstraints gbc_labelMoradaPerfil = new GridBagConstraints();
- gbc_labelMoradaPerfil.anchor = GridBagConstraints.WEST;
- gbc_labelMoradaPerfil.insets = new Insets(0, 0, 5, 5);
- gbc_labelMoradaPerfil.gridx = 0;
- gbc_labelMoradaPerfil.gridy = 11;
- panelPerfil.add(labelMoradaPerfil, gbc_labelMoradaPerfil);
- textMoradaPerfil = new JTextField();
- textMoradaPerfil.setEditable(false);
- textMoradaPerfil.setColumns(10);
- GridBagConstraints gbc_textMoradaPerfil = new GridBagConstraints();
- gbc_textMoradaPerfil.fill = GridBagConstraints.HORIZONTAL;
- gbc_textMoradaPerfil.gridwidth = 3;
- gbc_textMoradaPerfil.insets = new Insets(0, 0, 5, 5);
- gbc_textMoradaPerfil.gridx = 1;
- gbc_textMoradaPerfil.gridy = 11;
- panelPerfil.add(textMoradaPerfil, gbc_textMoradaPerfil);
- btnEditar = new JButton("Editar");
- btnEditar.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- /** Botao Editar Perfil */
- btnEditar.setEnabled(false);
- btnGuardar.setEnabled(true);
- //textUsernamePerfil.setEditable(true);
- textNomePerfil.setEditable(true);
- textApelidoPerfil.setEditable(true);
- textEmailPerfil.setEditable(true);
- textContactoPerfil.setEditable(true);
- textMoradaPerfil.setEditable(true);
- }
- });
- GridBagConstraints gbc_btnEditar = new GridBagConstraints();
- gbc_btnEditar.insets = new Insets(0, 0, 0, 5);
- gbc_btnEditar.gridx = 1;
- gbc_btnEditar.gridy = 13;
- panelPerfil.add(btnEditar, gbc_btnEditar);
- btnGuardar = new JButton("Guardar");
- btnGuardar.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- btnEditar.setEnabled(true);
- btnGuardar.setEnabled(false);
- try {
- Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
- String nome = textNomePerfil.getText();
- String apelido = textApelidoPerfil.getText();
- String email = textEmailPerfil.getText();
- String contacto = textContactoPerfil.getText();
- String morada = textMoradaPerfil.getText();
- PreparedStatement inst = lig.prepareStatement(
- "UPDATE cliente SET nome = ?, apelido = ?, email = ?, contacto = ?, morada = ? WHERE idCliente = '" + currentUserID + "'");
- inst.setString(1, nome);
- inst.setString(2, apelido);
- inst.setString(3, email);
- inst.setString(4, contacto);
- inst.setString(5, morada);
- int linhasAlteradas = inst.executeUpdate();
- if (linhasAlteradas == 1) {
- JOptionPane.showMessageDialog(null, "Perfil Atualizado");
- } else {
- JOptionPane.showMessageDialog(null, "Registo não atualizado");
- }
- lig.close();
- }catch (SQLException ex) {
- JOptionPane.showMessageDialog(frame, "Base de dados indisponivel: " + ex.getMessage());
- }
- //textUsernamePerfil.setEditable(false);
- textNomePerfil.setEditable(false);
- textApelidoPerfil.setEditable(false);
- textEmailPerfil.setEditable(false);
- textContactoPerfil.setEditable(false);
- textMoradaPerfil.setEditable(false);
- perfilSetup();
- }
- });
- btnGuardar.setEnabled(false);
- GridBagConstraints gbc_btnGuardar = new GridBagConstraints();
- gbc_btnGuardar.gridwidth = 6;
- gbc_btnGuardar.insets = new Insets(0, 0, 0, 5);
- gbc_btnGuardar.gridx = 2;
- gbc_btnGuardar.gridy = 13;
- panelPerfil.add(btnGuardar, gbc_btnGuardar);
- panelPassword = new JPanel();
- frame.getContentPane().add(panelPassword, "name_277697535854293");
- GridBagLayout gbl_panelPassword = new GridBagLayout();
- gbl_panelPassword.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- gbl_panelPassword.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
- 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};
- gbl_panelPassword.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
- panelPassword.setLayout(gbl_panelPassword);
- JLabel label = new JLabel("Login");
- GridBagConstraints gbc_label = new GridBagConstraints();
- gbc_label.gridwidth = 15;
- gbc_label.insets = new Insets(0, 0, 5, 0);
- gbc_label.gridx = 0;
- gbc_label.gridy = 0;
- panelPassword.add(label, gbc_label);
- Component verticalStrut_1 = Box.createVerticalStrut(20);
- GridBagConstraints gbc_verticalStrut_1 = new GridBagConstraints();
- gbc_verticalStrut_1.gridwidth = 2;
- gbc_verticalStrut_1.insets = new Insets(0, 0, 5, 5);
- gbc_verticalStrut_1.gridx = 7;
- gbc_verticalStrut_1.gridy = 1;
- panelPassword.add(verticalStrut_1, gbc_verticalStrut_1);
- Component horizontalStrut_12 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_12 = new GridBagConstraints();
- gbc_horizontalStrut_12.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_12.gridx = 1;
- gbc_horizontalStrut_12.gridy = 2;
- panelPassword.add(horizontalStrut_12, gbc_horizontalStrut_12);
- Component horizontalStrut_13 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_13 = new GridBagConstraints();
- gbc_horizontalStrut_13.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_13.gridx = 2;
- gbc_horizontalStrut_13.gridy = 2;
- panelPassword.add(horizontalStrut_13, gbc_horizontalStrut_13);
- Component horizontalStrut_14 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_14 = new GridBagConstraints();
- gbc_horizontalStrut_14.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_14.gridx = 3;
- gbc_horizontalStrut_14.gridy = 2;
- panelPassword.add(horizontalStrut_14, gbc_horizontalStrut_14);
- Component horizontalStrut_15 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_15 = new GridBagConstraints();
- gbc_horizontalStrut_15.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_15.gridx = 4;
- gbc_horizontalStrut_15.gridy = 2;
- panelPassword.add(horizontalStrut_15, gbc_horizontalStrut_15);
- Component horizontalStrut_16 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_16 = new GridBagConstraints();
- gbc_horizontalStrut_16.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_16.gridx = 5;
- gbc_horizontalStrut_16.gridy = 2;
- panelPassword.add(horizontalStrut_16, gbc_horizontalStrut_16);
- JLabel labelOldPassword = new JLabel("Password antiga:");
- GridBagConstraints gbc_labelOldPassword = new GridBagConstraints();
- gbc_labelOldPassword.anchor = GridBagConstraints.EAST;
- gbc_labelOldPassword.insets = new Insets(0, 0, 5, 5);
- gbc_labelOldPassword.gridx = 6;
- gbc_labelOldPassword.gridy = 2;
- panelPassword.add(labelOldPassword, gbc_labelOldPassword);
- passwordVelha = new JTextField();
- passwordVelha.setColumns(10);
- GridBagConstraints gbc_passwordVelha = new GridBagConstraints();
- gbc_passwordVelha.fill = GridBagConstraints.HORIZONTAL;
- gbc_passwordVelha.gridwidth = 2;
- gbc_passwordVelha.insets = new Insets(0, 0, 5, 5);
- gbc_passwordVelha.gridx = 7;
- gbc_passwordVelha.gridy = 2;
- panelPassword.add(passwordVelha, gbc_passwordVelha);
- Component horizontalStrut_17 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_17 = new GridBagConstraints();
- gbc_horizontalStrut_17.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_17.gridx = 10;
- gbc_horizontalStrut_17.gridy = 2;
- panelPassword.add(horizontalStrut_17, gbc_horizontalStrut_17);
- Component horizontalStrut_18 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_18 = new GridBagConstraints();
- gbc_horizontalStrut_18.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_18.gridx = 11;
- gbc_horizontalStrut_18.gridy = 2;
- panelPassword.add(horizontalStrut_18, gbc_horizontalStrut_18);
- Component horizontalStrut_19 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_19 = new GridBagConstraints();
- gbc_horizontalStrut_19.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_19.gridx = 12;
- gbc_horizontalStrut_19.gridy = 2;
- panelPassword.add(horizontalStrut_19, gbc_horizontalStrut_19);
- Component horizontalStrut_20 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_20 = new GridBagConstraints();
- gbc_horizontalStrut_20.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_20.gridx = 13;
- gbc_horizontalStrut_20.gridy = 2;
- panelPassword.add(horizontalStrut_20, gbc_horizontalStrut_20);
- Component horizontalStrut_21 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_21 = new GridBagConstraints();
- gbc_horizontalStrut_21.insets = new Insets(0, 0, 5, 0);
- gbc_horizontalStrut_21.gridx = 14;
- gbc_horizontalStrut_21.gridy = 2;
- panelPassword.add(horizontalStrut_21, gbc_horizontalStrut_21);
- Component verticalStrut_2 = Box.createVerticalStrut(20);
- GridBagConstraints gbc_verticalStrut_2 = new GridBagConstraints();
- gbc_verticalStrut_2.insets = new Insets(0, 0, 5, 5);
- gbc_verticalStrut_2.gridx = 7;
- gbc_verticalStrut_2.gridy = 3;
- panelPassword.add(verticalStrut_2, gbc_verticalStrut_2);
- JLabel labelNewPassword = new JLabel("Password nova:");
- GridBagConstraints gbc_labelNewPassword = new GridBagConstraints();
- gbc_labelNewPassword.anchor = GridBagConstraints.EAST;
- gbc_labelNewPassword.insets = new Insets(0, 0, 5, 5);
- gbc_labelNewPassword.gridx = 6;
- gbc_labelNewPassword.gridy = 4;
- panelPassword.add(labelNewPassword, gbc_labelNewPassword);
- passwordNova = new JTextField();
- passwordNova.setColumns(10);
- GridBagConstraints gbc_passwordNova = new GridBagConstraints();
- gbc_passwordNova.fill = GridBagConstraints.HORIZONTAL;
- gbc_passwordNova.gridwidth = 2;
- gbc_passwordNova.insets = new Insets(0, 0, 5, 5);
- gbc_passwordNova.gridx = 7;
- gbc_passwordNova.gridy = 4;
- panelPassword.add(passwordNova, gbc_passwordNova);
- JLabel lblConfirmarPassword = new JLabel("Confirmar password:");
- GridBagConstraints gbc_lblConfirmarPassword = new GridBagConstraints();
- gbc_lblConfirmarPassword.anchor = GridBagConstraints.EAST;
- gbc_lblConfirmarPassword.insets = new Insets(0, 0, 5, 5);
- gbc_lblConfirmarPassword.gridx = 6;
- gbc_lblConfirmarPassword.gridy = 5;
- panelPassword.add(lblConfirmarPassword, gbc_lblConfirmarPassword);
- passwordConfirmar = new JTextField();
- passwordConfirmar.setColumns(10);
- GridBagConstraints gbc_passwordConfirmar = new GridBagConstraints();
- gbc_passwordConfirmar.gridwidth = 2;
- gbc_passwordConfirmar.insets = new Insets(0, 0, 5, 5);
- gbc_passwordConfirmar.fill = GridBagConstraints.HORIZONTAL;
- gbc_passwordConfirmar.gridx = 7;
- gbc_passwordConfirmar.gridy = 5;
- panelPassword.add(passwordConfirmar, gbc_passwordConfirmar);
- Component verticalStrut_3 = Box.createVerticalStrut(20);
- GridBagConstraints gbc_verticalStrut_3 = new GridBagConstraints();
- gbc_verticalStrut_3.insets = new Insets(0, 0, 5, 5);
- gbc_verticalStrut_3.gridx = 8;
- gbc_verticalStrut_3.gridy = 6;
- panelPassword.add(verticalStrut_3, gbc_verticalStrut_3);
- JButton btnMudarPassword = new JButton("Confirmar");
- btnMudarPassword.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- //Mudar password
- String passwordVelha1 = passwordVelha.getText();
- String passwordNova1 = passwordNova.getText();
- String passwordConfirmar1 = passwordConfirmar.getText();
- //comparar as 2 passwords
- if(passwordNova1.equals(passwordConfirmar1)) {
- //comparar a password velha com a da base de dados
- try {
- Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
- Statement inst = lig.createStatement();
- ResultSet resultado = inst
- .executeQuery("select palavraChave, idCliente FROM cliente where idCliente = '" + currentUserID + "'");
- while (resultado.next()) {
- String passworddb = resultado.getString("palavraChave");
- if(passwordVelha1.equals(passworddb)) {
- PreparedStatement instPassword = lig.prepareStatement(
- "UPDATE cliente SET palavraChave = ? WHERE idCliente = '" + currentUserID + "'");
- instPassword.setString(1, passwordNova1);
- int linhasAlteradas = instPassword.executeUpdate();
- if (linhasAlteradas == 1) {
- JOptionPane.showMessageDialog(null, "Palavra-Passe atualizada");
- //volta para o perfil
- frame.getContentPane().removeAll();
- frame.getContentPane().add(panelPerfil);
- frame.revalidate();
- frame.repaint();
- } else {
- JOptionPane.showMessageDialog(null, "Palavra-Passe não atualizada");
- }
- }
- else {
- JOptionPane.showMessageDialog(null, "A palavra-Passe não corresponde à antiga.");
- passwordLogin.setText("");
- }
- }
- lig.close();
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "BD indísponivel! \n" + ex.getMessage());
- }
- }
- else {
- JOptionPane.showMessageDialog(null, "As palavras-Passe não correspondem.");
- }
- passwordVelha.setText("");
- passwordNova.setText("");
- passwordConfirmar.setText("");
- }
- });
- GridBagConstraints gbc_btnMudarPassword = new GridBagConstraints();
- gbc_btnMudarPassword.gridwidth = 15;
- gbc_btnMudarPassword.insets = new Insets(0, 0, 0, 5);
- gbc_btnMudarPassword.gridx = 0;
- gbc_btnMudarPassword.gridy = 7;
- panelPassword.add(btnMudarPassword, gbc_btnMudarPassword);
- panelMensagem = new JPanel();
- frame.getContentPane().add(panelMensagem, "name_947820898540649");
- GridBagLayout gbl_panelMensagem = new GridBagLayout();
- gbl_panelMensagem.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
- gbl_panelMensagem.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
- gbl_panelMensagem.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
- gbl_panelMensagem.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
- panelMensagem.setLayout(gbl_panelMensagem);
- JLabel lblMensagem = new JLabel("Mensagem");
- GridBagConstraints gbc_lblMensagem = new GridBagConstraints();
- gbc_lblMensagem.gridwidth = 5;
- gbc_lblMensagem.insets = new Insets(0, 0, 5, 5);
- gbc_lblMensagem.gridx = 1;
- gbc_lblMensagem.gridy = 0;
- panelMensagem.add(lblMensagem, gbc_lblMensagem);
- comboBoxDestinatario = new JComboBox();
- comboBoxDestinatario.setModel(new DefaultComboBoxModel(new String[] {"M\u00E9dico", "Cliente"}));
- GridBagConstraints gbc_comboBoxDestinatario = new GridBagConstraints();
- gbc_comboBoxDestinatario.insets = new Insets(0, 0, 5, 5);
- gbc_comboBoxDestinatario.fill = GridBagConstraints.HORIZONTAL;
- gbc_comboBoxDestinatario.gridx = 2;
- gbc_comboBoxDestinatario.gridy = 1;
- panelMensagem.add(comboBoxDestinatario, gbc_comboBoxDestinatario);
- comboBoxIdentificador = new JComboBox();
- comboBoxIdentificador.setModel(new DefaultComboBoxModel(new String[] {"ID", "Username"}));
- GridBagConstraints gbc_comboBoxIdentificador = new GridBagConstraints();
- gbc_comboBoxIdentificador.insets = new Insets(0, 0, 5, 5);
- gbc_comboBoxIdentificador.fill = GridBagConstraints.HORIZONTAL;
- gbc_comboBoxIdentificador.gridx = 3;
- gbc_comboBoxIdentificador.gridy = 1;
- panelMensagem.add(comboBoxIdentificador, gbc_comboBoxIdentificador);
- JComboBox comboBoxCategoria = new JComboBox();
- comboBoxCategoria.setModel(new DefaultComboBoxModel(new String[] {"Mensagem", "Exames", "Consultas", "Relat\u00F3rios"}));
- GridBagConstraints gbc_comboBoxCategoria = new GridBagConstraints();
- gbc_comboBoxCategoria.insets = new Insets(0, 0, 5, 5);
- gbc_comboBoxCategoria.fill = GridBagConstraints.HORIZONTAL;
- gbc_comboBoxCategoria.gridx = 4;
- gbc_comboBoxCategoria.gridy = 1;
- panelMensagem.add(comboBoxCategoria, gbc_comboBoxCategoria);
- JLabel lblDestinatrio = new JLabel("Destinat\u00E1rio:");
- GridBagConstraints gbc_lblDestinatrio = new GridBagConstraints();
- gbc_lblDestinatrio.anchor = GridBagConstraints.WEST;
- gbc_lblDestinatrio.insets = new Insets(0, 0, 5, 5);
- gbc_lblDestinatrio.gridx = 1;
- gbc_lblDestinatrio.gridy = 2;
- panelMensagem.add(lblDestinatrio, gbc_lblDestinatrio);
- textDestinatario = new JTextField();
- GridBagConstraints gbc_textDestinatario = new GridBagConstraints();
- gbc_textDestinatario.gridwidth = 2;
- gbc_textDestinatario.insets = new Insets(0, 0, 5, 5);
- gbc_textDestinatario.fill = GridBagConstraints.HORIZONTAL;
- gbc_textDestinatario.gridx = 2;
- gbc_textDestinatario.gridy = 2;
- panelMensagem.add(textDestinatario, gbc_textDestinatario);
- textDestinatario.setColumns(10);
- Component horizontalStrut_32 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_32 = new GridBagConstraints();
- gbc_horizontalStrut_32.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_32.gridx = 0;
- gbc_horizontalStrut_32.gridy = 3;
- panelMensagem.add(horizontalStrut_32, gbc_horizontalStrut_32);
- JLabel lblAssunto = new JLabel("Assunto:");
- GridBagConstraints gbc_lblAssunto = new GridBagConstraints();
- gbc_lblAssunto.anchor = GridBagConstraints.EAST;
- gbc_lblAssunto.insets = new Insets(0, 0, 5, 5);
- gbc_lblAssunto.gridx = 1;
- gbc_lblAssunto.gridy = 3;
- panelMensagem.add(lblAssunto, gbc_lblAssunto);
- textAssunto = new JTextField();
- GridBagConstraints gbc_textAssunto = new GridBagConstraints();
- gbc_textAssunto.gridwidth = 4;
- gbc_textAssunto.insets = new Insets(0, 0, 5, 5);
- gbc_textAssunto.fill = GridBagConstraints.HORIZONTAL;
- gbc_textAssunto.gridx = 2;
- gbc_textAssunto.gridy = 3;
- panelMensagem.add(textAssunto, gbc_textAssunto);
- textAssunto.setColumns(10);
- JLabel lblCorpo = new JLabel("Corpo:");
- GridBagConstraints gbc_lblCorpo = new GridBagConstraints();
- gbc_lblCorpo.anchor = GridBagConstraints.EAST;
- gbc_lblCorpo.insets = new Insets(0, 0, 5, 5);
- gbc_lblCorpo.gridx = 1;
- gbc_lblCorpo.gridy = 4;
- panelMensagem.add(lblCorpo, gbc_lblCorpo);
- Component horizontalStrut_33 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_33 = new GridBagConstraints();
- gbc_horizontalStrut_33.insets = new Insets(0, 0, 5, 0);
- gbc_horizontalStrut_33.gridx = 6;
- gbc_horizontalStrut_33.gridy = 4;
- panelMensagem.add(horizontalStrut_33, gbc_horizontalStrut_33);
- JScrollPane scrollPaneMensagem = new JScrollPane();
- GridBagConstraints gbc_scrollPaneMensagem = new GridBagConstraints();
- gbc_scrollPaneMensagem.gridwidth = 4;
- gbc_scrollPaneMensagem.insets = new Insets(0, 0, 5, 5);
- gbc_scrollPaneMensagem.fill = GridBagConstraints.BOTH;
- gbc_scrollPaneMensagem.gridx = 2;
- gbc_scrollPaneMensagem.gridy = 5;
- panelMensagem.add(scrollPaneMensagem, gbc_scrollPaneMensagem);
- textCorpo = new JTextPane();
- scrollPaneMensagem.setViewportView(textCorpo);
- JButton btnEnviar = new JButton("Enviar");
- btnEnviar.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- //Definir variaveis
- String tipoDestinatario = (String) comboBoxDestinatario.getSelectedItem();
- String identificador = (String) comboBoxIdentificador.getSelectedItem();
- String categoria = (String) comboBoxCategoria.getSelectedItem();
- String destinatario = textDestinatario.getText();
- String assunto = textAssunto.getText();
- String corpo = textCorpo.getText();
- java.sql.Timestamp data = new java.sql.Timestamp(new java.util.Date().getTime());
- int id_mail_cliente_medico = 0;
- int id_mail_cliente_cliente = 0;
- //obter os ids dos mails
- try {
- Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
- PreparedStatement inst = lig.prepareStatement("SELECT MAX(emailID) FROM mail_cliente_medico");
- ResultSet res = inst.executeQuery();
- if (res.next()) {
- id_mail_cliente_medico = res.getInt("MAX(emailID)") +1;
- }
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(frame, "BD indisponível!" + ex.getMessage());
- }
- try {
- Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
- PreparedStatement inst = lig.prepareStatement("SELECT MAX(emailID) FROM mail_cliente_cliente");
- ResultSet res = inst.executeQuery();
- if (res.next()) {
- id_mail_cliente_cliente = res.getInt("MAX(emailID)") + 1;
- JOptionPane.showMessageDialog(null,id_mail_cliente_cliente + " " + res.getInt("MAX(emailID)") );
- }
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(frame, "BD indisponível!" + ex.getMessage());
- }
- //ligação à base de dados
- try {
- Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
- //se o destinatario for medico
- if(tipoDestinatario == "Médico") {
- if(identificador == "ID") {
- PreparedStatement inst = lig.prepareStatement(
- "INSERT INTO mail_cliente_medico (Medico_ID, Cliente_idCliente, assunto, conteudo, categoria, data, emailID) VALUES(?, ?, ?, ?, ?, ?, ?);");
- inst.setString(1, destinatario);
- inst.setInt(2, currentUserID);
- inst.setString(3, assunto);
- inst.setString(4, corpo);
- inst.setString(5, categoria);
- inst.setTimestamp(6, data);
- inst.setInt(7, id_mail_cliente_medico);
- int linhasAlteradas = inst.executeUpdate();
- if (linhasAlteradas == 1) {
- JOptionPane.showMessageDialog(null, "Mensagem Enviada");
- } else {
- JOptionPane.showMessageDialog(null, "Mensagem não enviada");
- }
- lig.close();
- textDestinatario.setText("");
- textAssunto.setText("");
- textCorpo.setText("");
- }
- else {
- Statement inst1 = lig.createStatement();
- String medicoID = "";
- ResultSet resultado = inst1.executeQuery("select ID FROM medico where username = '" + destinatario + "'");
- while (resultado.next()) {
- medicoID = resultado.getString("ID");
- }
- PreparedStatement inst2 = lig.prepareStatement(
- "INSERT INTO mail_cliente_medico (Medico_ID, Cliente_idCliente, assunto, conteudo, categoria, data, emailID) VALUES(?, ?, ?, ?, ?, ?, ?);");
- inst2.setString(1, medicoID);
- inst2.setInt(2, currentUserID);
- inst2.setString(3, assunto);
- inst2.setString(4, corpo);
- inst2.setString(5, categoria);
- inst2.setTimestamp(6, data);
- inst2.setInt(7, id_mail_cliente_medico);
- int linhasAlteradas = inst2.executeUpdate();
- if (linhasAlteradas == 1) {
- JOptionPane.showMessageDialog(null, "Mensagem Enviada");
- } else {
- JOptionPane.showMessageDialog(null, "Mensagem não enviada");
- }
- lig.close();
- textDestinatario.setText("");
- textAssunto.setText("");
- textCorpo.setText("");
- }
- }
- //se o destinatario for outro cliente
- else {
- if(identificador == "ID") {
- PreparedStatement inst = lig.prepareStatement(
- "INSERT INTO mail_cliente_cliente (destino_idCliente, origem_idCliente, assunto, conteudo, categoria, data, emailID) VALUES(?, ?, ?, ?, ?, ?, ?);");
- inst.setString(1, destinatario);
- inst.setInt(2, currentUserID);
- inst.setString(3, assunto);
- inst.setString(4, corpo);
- inst.setString(5, categoria);
- inst.setTimestamp(6, data);
- inst.setInt(7, id_mail_cliente_cliente);
- int linhasAlteradas = inst.executeUpdate();
- if (linhasAlteradas == 1) {
- JOptionPane.showMessageDialog(null, "Mensagem Enviada");
- } else {
- JOptionPane.showMessageDialog(null, "Mensagem não enviada");
- }
- lig.close();
- textDestinatario.setText("");
- textAssunto.setText("");
- textCorpo.setText("");
- }
- else {
- Statement inst1 = lig.createStatement();
- String clienteID = "";
- ResultSet resultado = inst1.executeQuery("select idCLiente FROM cliente where username = '" + destinatario + "'");
- while (resultado.next()) {
- clienteID = resultado.getString("idCliente");
- }
- PreparedStatement inst2 = lig.prepareStatement(
- "INSERT INTO mail_cliente_cliente (destino_idCliente, origem_idCliente, assunto, conteudo, categoria, data, emailID) VALUES(?, ?, ?, ?, ?, ?, ?);");
- inst2.setString(1, clienteID);
- inst2.setInt(2, currentUserID);
- inst2.setString(3, assunto);
- inst2.setString(4, corpo);
- inst2.setString(5, categoria);
- inst2.setTimestamp(6, data);
- inst2.setInt(7, id_mail_cliente_cliente);
- int linhasAlteradas = inst2.executeUpdate();
- if (linhasAlteradas == 1) {
- JOptionPane.showMessageDialog(null, "Mensagem Enviada");
- } else {
- JOptionPane.showMessageDialog(null, "Mensagem não enviada");
- }
- lig.close();
- textDestinatario.setText("");
- textAssunto.setText("");
- textCorpo.setText("");
- }
- }
- }catch (SQLException ex) {
- JOptionPane.showMessageDialog(frame, "Base de dados indisponivel: " + ex.getMessage());
- }
- }
- });
- GridBagConstraints gbc_btnEnviar = new GridBagConstraints();
- gbc_btnEnviar.gridwidth = 5;
- gbc_btnEnviar.insets = new Insets(0, 0, 0, 5);
- gbc_btnEnviar.gridx = 1;
- gbc_btnEnviar.gridy = 6;
- panelMensagem.add(btnEnviar, gbc_btnEnviar);
- JPanel panelInbox = new JPanel();
- frame.getContentPane().add(panelInbox, "name_947822139102008");
- GridBagLayout gbl_panelInbox = new GridBagLayout();
- gbl_panelInbox.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- gbl_panelInbox.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0};
- 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};
- gbl_panelInbox.rowWeights = new double[]{0.0, 0.0, 0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
- panelInbox.setLayout(gbl_panelInbox);
- JLabel lblFiltro = new JLabel("Filtro:");
- GridBagConstraints gbc_lblFiltro = new GridBagConstraints();
- gbc_lblFiltro.insets = new Insets(0, 0, 5, 5);
- gbc_lblFiltro.gridx = 1;
- gbc_lblFiltro.gridy = 1;
- panelInbox.add(lblFiltro, gbc_lblFiltro);
- Component horizontalStrut_34 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_34 = new GridBagConstraints();
- gbc_horizontalStrut_34.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_34.gridx = 2;
- gbc_horizontalStrut_34.gridy = 1;
- panelInbox.add(horizontalStrut_34, gbc_horizontalStrut_34);
- JLabel labelFiltroOrigem = new JLabel("Origem:");
- GridBagConstraints gbc_labelFiltroOrigem = new GridBagConstraints();
- gbc_labelFiltroOrigem.insets = new Insets(0, 0, 5, 5);
- gbc_labelFiltroOrigem.anchor = GridBagConstraints.EAST;
- gbc_labelFiltroOrigem.gridx = 3;
- gbc_labelFiltroOrigem.gridy = 1;
- panelInbox.add(labelFiltroOrigem, gbc_labelFiltroOrigem);
- comboBoxFiltroOrigem = new JComboBox();
- comboBoxFiltroOrigem.setModel(new DefaultComboBoxModel(new String[] {"Clientes", "M\u00E9dicos"}));
- GridBagConstraints gbc_comboBoxFiltroOrigem = new GridBagConstraints();
- gbc_comboBoxFiltroOrigem.insets = new Insets(0, 0, 5, 5);
- gbc_comboBoxFiltroOrigem.fill = GridBagConstraints.HORIZONTAL;
- gbc_comboBoxFiltroOrigem.gridx = 4;
- gbc_comboBoxFiltroOrigem.gridy = 1;
- panelInbox.add(comboBoxFiltroOrigem, gbc_comboBoxFiltroOrigem);
- Component horizontalStrut_35 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_35 = new GridBagConstraints();
- gbc_horizontalStrut_35.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_35.gridx = 5;
- gbc_horizontalStrut_35.gridy = 1;
- panelInbox.add(horizontalStrut_35, gbc_horizontalStrut_35);
- JLabel lblCategoriaFiltro = new JLabel("Categoria:");
- GridBagConstraints gbc_lblCategoriaFiltro = new GridBagConstraints();
- gbc_lblCategoriaFiltro.anchor = GridBagConstraints.EAST;
- gbc_lblCategoriaFiltro.insets = new Insets(0, 0, 5, 5);
- gbc_lblCategoriaFiltro.gridx = 6;
- gbc_lblCategoriaFiltro.gridy = 1;
- panelInbox.add(lblCategoriaFiltro, gbc_lblCategoriaFiltro);
- comboBoxFiltroCategoria = new JComboBox();
- comboBoxFiltroCategoria.setModel(new DefaultComboBoxModel(new String[] {"Todas", "Mensagem", "Exames", "Consultas", "Relat\u00F3rios"}));
- GridBagConstraints gbc_comboBoxFiltroCategoria = new GridBagConstraints();
- gbc_comboBoxFiltroCategoria.insets = new Insets(0, 0, 5, 5);
- gbc_comboBoxFiltroCategoria.fill = GridBagConstraints.HORIZONTAL;
- gbc_comboBoxFiltroCategoria.gridx = 7;
- gbc_comboBoxFiltroCategoria.gridy = 1;
- panelInbox.add(comboBoxFiltroCategoria, gbc_comboBoxFiltroCategoria);
- Component horizontalStrut_36 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_36 = new GridBagConstraints();
- gbc_horizontalStrut_36.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_36.gridx = 0;
- gbc_horizontalStrut_36.gridy = 3;
- panelInbox.add(horizontalStrut_36, gbc_horizontalStrut_36);
- JScrollPane scrollPane = new JScrollPane();
- GridBagConstraints gbc_scrollPane = new GridBagConstraints();
- gbc_scrollPane.gridwidth = 13;
- gbc_scrollPane.insets = new Insets(0, 0, 5, 5);
- gbc_scrollPane.fill = GridBagConstraints.BOTH;
- gbc_scrollPane.gridx = 1;
- gbc_scrollPane.gridy = 3;
- panelInbox.add(scrollPane, gbc_scrollPane);
- tableMensagem = new JTable();
- tableMensagem.setModel(modeloInbox = new DefaultTableModel(
- new Object[][] {
- },
- new String[] {
- "ID", "Nome", "Categoria", "Assunto", "Data"
- }
- ) {
- Class[] columnTypes = new Class[] {
- String.class, String.class, String.class, String.class, String.class
- };
- public Class getColumnClass(int columnIndex) {
- return columnTypes[columnIndex];
- }
- });
- tableMensagem.getColumnModel().getColumn(0).setPreferredWidth(40);
- tableMensagem.getColumnModel().getColumn(1).setPreferredWidth(125);
- tableMensagem.getColumnModel().getColumn(3).setPreferredWidth(275);
- tableMensagem.getColumnModel().getColumn(4).setPreferredWidth(125);
- scrollPane.setViewportView(tableMensagem);
- Component horizontalStrut_37 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_37 = new GridBagConstraints();
- gbc_horizontalStrut_37.insets = new Insets(0, 0, 5, 0);
- gbc_horizontalStrut_37.gridx = 14;
- gbc_horizontalStrut_37.gridy = 3;
- panelInbox.add(horizontalStrut_37, gbc_horizontalStrut_37);
- JButton btnLer = new JButton("Ler");
- btnLer.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- //Selecionar o ID do email
- int column = 0;
- int row = tableMensagem.getSelectedRow();
- String emailID = tableMensagem.getModel().getValueAt(row, column).toString();
- currentEmail = emailID;
- //Definir a mensagem no outro painel
- try {
- textOrigemLer.setText("");
- textCategorialer.setText("");
- textAssuntoLer.setText("");
- textDataLer.setText("");
- textCorpoLer.setText("");
- String nome = "";
- String apelido = "";
- String categoria = "";
- String assunto = "";
- String conteudo = "";
- String data = "";
- String idCLienteLer ="";
- String username = "";
- Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
- Statement inst = lig.createStatement();
- ResultSet resultado = inst
- .executeQuery("SELECT * FROM mail_cliente_cliente where emailID = '" + emailID +"'");
- while(resultado.next()) {
- idCLienteLer = resultado.getString("origem_idCliente");
- categoria = resultado.getString("categoria");
- assunto = resultado.getString("assunto");
- conteudo = resultado.getString("conteudo");
- data = resultado.getString("data");
- Statement inst1 = lig.createStatement();
- ResultSet resultado1 = inst1
- .executeQuery("SELECT nome, apelido, username FROM cliente where idCliente = '" + idCLienteLer +"'");
- while(resultado1.next()) {
- nome = resultado1.getString("nome");
- apelido = resultado1.getString("apelido");
- username = resultado1.getString("username");
- }
- }
- textOrigemLer.setText(nome + " " + apelido + " (" + username + ")");
- textCategorialer.setText(categoria);
- textAssuntoLer.setText(assunto);
- textDataLer.setText(data);
- textCorpoLer.setText(conteudo);
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "BD indísponivel! | " + ex);
- }
- frame.getContentPane().removeAll();
- frame.getContentPane().add(panelLer);
- frame.revalidate();
- frame.repaint();
- }
- });
- GridBagConstraints gbc_btnLer = new GridBagConstraints();
- gbc_btnLer.insets = new Insets(0, 0, 5, 5);
- gbc_btnLer.gridx = 10;
- gbc_btnLer.gridy = 4;
- panelInbox.add(btnLer, gbc_btnLer);
- JButton btnAtualizar = new JButton("Atualizar");
- btnAtualizar.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String origemFiltro = (String) comboBoxFiltroOrigem.getSelectedItem();
- currentFilter = origemFiltro;
- if(origemFiltro == "Clientes") {
- MensagensClienteCategoria();
- }
- }
- });
- GridBagConstraints gbc_btnAtualizar = new GridBagConstraints();
- gbc_btnAtualizar.insets = new Insets(0, 0, 5, 5);
- gbc_btnAtualizar.gridx = 11;
- gbc_btnAtualizar.gridy = 4;
- panelInbox.add(btnAtualizar, gbc_btnAtualizar);
- JButton btnEscrever = new JButton("Escrever");
- GridBagConstraints gbc_btnEscrever = new GridBagConstraints();
- gbc_btnEscrever.anchor = GridBagConstraints.WEST;
- gbc_btnEscrever.insets = new Insets(0, 0, 5, 5);
- gbc_btnEscrever.gridx = 12;
- gbc_btnEscrever.gridy = 4;
- panelInbox.add(btnEscrever, gbc_btnEscrever);
- JButton btnApagarLer = new JButton("Apagar");
- btnApagarLer.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- //apanhar o ID do email
- int column = 0;
- int row = tableMensagem.getSelectedRow();
- String emailID = tableMensagem.getModel().getValueAt(row, column).toString();
- try {
- Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root","");
- if(currentFilter == "Clientes") {
- PreparedStatement inst = lig.prepareStatement("DELETE FROM mail_cliente_cliente WHERE emailID = ?");
- inst.setString(1, emailID);
- inst.executeUpdate();
- MensagensClienteCategoria();
- }
- else {
- PreparedStatement inst = lig.prepareStatement("DELETE FROM mail_cliente_medico WHERE emailID = ?");
- inst.setString(1, emailID);
- inst.executeUpdate();
- }
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(frame, "Erro ao eliminar: " + ex.getMessage());
- }
- }
- });
- GridBagConstraints gbc_btnApagarLer = new GridBagConstraints();
- gbc_btnApagarLer.anchor = GridBagConstraints.WEST;
- gbc_btnApagarLer.insets = new Insets(0, 0, 5, 5);
- gbc_btnApagarLer.gridx = 13;
- gbc_btnApagarLer.gridy = 4;
- panelInbox.add(btnApagarLer, gbc_btnApagarLer);
- Component verticalStrut_7 = Box.createVerticalStrut(20);
- GridBagConstraints gbc_verticalStrut_7 = new GridBagConstraints();
- gbc_verticalStrut_7.insets = new Insets(0, 0, 0, 5);
- gbc_verticalStrut_7.gridx = 1;
- gbc_verticalStrut_7.gridy = 5;
- panelInbox.add(verticalStrut_7, gbc_verticalStrut_7);
- panelForgot = new JPanel();
- frame.getContentPane().add(panelForgot, "name_279474687724319");
- GridBagLayout gbl_panelForgot = new GridBagLayout();
- gbl_panelForgot.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- gbl_panelForgot.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
- 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};
- gbl_panelForgot.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
- panelForgot.setLayout(gbl_panelForgot);
- JLabel label_1 = new JLabel("Login");
- GridBagConstraints gbc_label_1 = new GridBagConstraints();
- gbc_label_1.gridwidth = 15;
- gbc_label_1.insets = new Insets(0, 0, 5, 0);
- gbc_label_1.gridx = 0;
- gbc_label_1.gridy = 0;
- panelForgot.add(label_1, gbc_label_1);
- Component verticalStrut_4 = Box.createVerticalStrut(20);
- GridBagConstraints gbc_verticalStrut_4 = new GridBagConstraints();
- gbc_verticalStrut_4.gridwidth = 2;
- gbc_verticalStrut_4.insets = new Insets(0, 0, 5, 5);
- gbc_verticalStrut_4.gridx = 7;
- gbc_verticalStrut_4.gridy = 1;
- panelForgot.add(verticalStrut_4, gbc_verticalStrut_4);
- Component horizontalStrut_22 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_22 = new GridBagConstraints();
- gbc_horizontalStrut_22.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_22.gridx = 1;
- gbc_horizontalStrut_22.gridy = 2;
- panelForgot.add(horizontalStrut_22, gbc_horizontalStrut_22);
- Component horizontalStrut_23 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_23 = new GridBagConstraints();
- gbc_horizontalStrut_23.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_23.gridx = 2;
- gbc_horizontalStrut_23.gridy = 2;
- panelForgot.add(horizontalStrut_23, gbc_horizontalStrut_23);
- Component horizontalStrut_24 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_24 = new GridBagConstraints();
- gbc_horizontalStrut_24.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_24.gridx = 3;
- gbc_horizontalStrut_24.gridy = 2;
- panelForgot.add(horizontalStrut_24, gbc_horizontalStrut_24);
- Component horizontalStrut_25 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_25 = new GridBagConstraints();
- gbc_horizontalStrut_25.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_25.gridx = 4;
- gbc_horizontalStrut_25.gridy = 2;
- panelForgot.add(horizontalStrut_25, gbc_horizontalStrut_25);
- Component horizontalStrut_26 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_26 = new GridBagConstraints();
- gbc_horizontalStrut_26.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_26.gridx = 5;
- gbc_horizontalStrut_26.gridy = 2;
- panelForgot.add(horizontalStrut_26, gbc_horizontalStrut_26);
- JLabel lblUsernameForgot = new JLabel("Username");
- GridBagConstraints gbc_lblUsernameForgot = new GridBagConstraints();
- gbc_lblUsernameForgot.anchor = GridBagConstraints.EAST;
- gbc_lblUsernameForgot.insets = new Insets(0, 0, 5, 5);
- gbc_lblUsernameForgot.gridx = 6;
- gbc_lblUsernameForgot.gridy = 2;
- panelForgot.add(lblUsernameForgot, gbc_lblUsernameForgot);
- textUsernameForgot = new JTextField();
- textUsernameForgot.setColumns(10);
- GridBagConstraints gbc_textUsernameForgot = new GridBagConstraints();
- gbc_textUsernameForgot.fill = GridBagConstraints.HORIZONTAL;
- gbc_textUsernameForgot.gridwidth = 2;
- gbc_textUsernameForgot.insets = new Insets(0, 0, 5, 5);
- gbc_textUsernameForgot.gridx = 7;
- gbc_textUsernameForgot.gridy = 2;
- panelForgot.add(textUsernameForgot, gbc_textUsernameForgot);
- Component horizontalStrut_27 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_27 = new GridBagConstraints();
- gbc_horizontalStrut_27.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_27.gridx = 10;
- gbc_horizontalStrut_27.gridy = 2;
- panelForgot.add(horizontalStrut_27, gbc_horizontalStrut_27);
- Component horizontalStrut_28 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_28 = new GridBagConstraints();
- gbc_horizontalStrut_28.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_28.gridx = 11;
- gbc_horizontalStrut_28.gridy = 2;
- panelForgot.add(horizontalStrut_28, gbc_horizontalStrut_28);
- Component horizontalStrut_29 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_29 = new GridBagConstraints();
- gbc_horizontalStrut_29.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_29.gridx = 12;
- gbc_horizontalStrut_29.gridy = 2;
- panelForgot.add(horizontalStrut_29, gbc_horizontalStrut_29);
- Component horizontalStrut_30 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_30 = new GridBagConstraints();
- gbc_horizontalStrut_30.insets = new Insets(0, 0, 5, 5);
- gbc_horizontalStrut_30.gridx = 13;
- gbc_horizontalStrut_30.gridy = 2;
- panelForgot.add(horizontalStrut_30, gbc_horizontalStrut_30);
- Component horizontalStrut_31 = Box.createHorizontalStrut(20);
- GridBagConstraints gbc_horizontalStrut_31 = new GridBagConstraints();
- gbc_horizontalStrut_31.insets = new Insets(0, 0, 5, 0);
- gbc_horizontalStrut_31.gridx = 14;
- gbc_horizontalStrut_31.gridy = 2;
- panelForgot.add(horizontalStrut_31, gbc_horizontalStrut_31);
- JLabel lblEmail_1 = new JLabel("Email:");
- GridBagConstraints gbc_lblEmail_1 = new GridBagConstraints();
- gbc_lblEmail_1.anchor = GridBagConstraints.EAST;
- gbc_lblEmail_1.insets = new Insets(0, 0, 5, 5);
- gbc_lblEmail_1.gridx = 6;
- gbc_lblEmail_1.gridy = 3;
- panelForgot.add(lblEmail_1, gbc_lblEmail_1);
- textEmailForgot = new JTextField();
- GridBagConstraints gbc_textEmailForgot = new GridBagConstraints();
- gbc_textEmailForgot.gridwidth = 2;
- gbc_textEmailForgot.insets = new Insets(0, 0, 5, 5);
- gbc_textEmailForgot.fill = GridBagConstraints.HORIZONTAL;
- gbc_textEmailForgot.gridx = 7;
- gbc_textEmailForgot.gridy = 3;
- panelForgot.add(textEmailForgot, gbc_textEmailForgot);
- textEmailForgot.setColumns(10);
- textEmailForgot.addFocusListener(new FocusAdapter() {
- public void focusGained(FocusEvent e){
- if(textEmailForgot.getText().equals("Tudo em minúsculas")){
- textEmailForgot.setText("");
- textEmailForgot.setForeground(Color.BLACK);
- }
- }
- public void focusLost(FocusEvent x){
- if(textEmailForgot.getText().equals("")){
- textEmailForgot.setText("Tudo em minúsculas");
- textEmailForgot.setForeground(Color.GRAY);
- }
- }
- });
- JLabel label_3 = new JLabel("Password nova:");
- GridBagConstraints gbc_label_3 = new GridBagConstraints();
- gbc_label_3.anchor = GridBagConstraints.EAST;
- gbc_label_3.insets = new Insets(0, 0, 5, 5);
- gbc_label_3.gridx = 6;
- gbc_label_3.gridy = 4;
- panelForgot.add(label_3, gbc_label_3);
- passwordNovaForgot = new JTextField();
- passwordNovaForgot.setColumns(10);
- GridBagConstraints gbc_passwordNovaForgot = new GridBagConstraints();
- gbc_passwordNovaForgot.fill = GridBagConstraints.HORIZONTAL;
- gbc_passwordNovaForgot.gridwidth = 2;
- gbc_passwordNovaForgot.insets = new Insets(0, 0, 5, 5);
- gbc_passwordNovaForgot.gridx = 7;
- gbc_passwordNovaForgot.gridy = 4;
- panelForgot.add(passwordNovaForgot, gbc_passwordNovaForgot);
- JLabel label_4 = new JLabel("Confirmar password:");
- GridBagConstraints gbc_label_4 = new GridBagConstraints();
- gbc_label_4.anchor = GridBagConstraints.EAST;
- gbc_label_4.insets = new Insets(0, 0, 5, 5);
- gbc_label_4.gridx = 6;
- gbc_label_4.gridy = 5;
- panelForgot.add(label_4, gbc_label_4);
- passwordConfirmarForgot = new JTextField();
- passwordConfirmarForgot.setColumns(10);
- GridBagConstraints gbc_passwordConfirmarForgot = new GridBagConstraints();
- gbc_passwordConfirmarForgot.fill = GridBagConstraints.HORIZONTAL;
- gbc_passwordConfirmarForgot.gridwidth = 2;
- gbc_passwordConfirmarForgot.insets = new Insets(0, 0, 5, 5);
- gbc_passwordConfirmarForgot.gridx = 7;
- gbc_passwordConfirmarForgot.gridy = 5;
- panelForgot.add(passwordConfirmarForgot, gbc_passwordConfirmarForgot);
- Component verticalStrut_6 = Box.createVerticalStrut(20);
- GridBagConstraints gbc_verticalStrut_6 = new GridBagConstraints();
- gbc_verticalStrut_6.insets = new Insets(0, 0, 5, 5);
- gbc_verticalStrut_6.gridx = 8;
- gbc_verticalStrut_6.gridy = 6;
- panelForgot.add(verticalStrut_6, gbc_verticalStrut_6);
- JButton button = new JButton("Confirmar");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- //esqueceu-se da palavra-Chave?
- //Mudar password
- String username = textUsernameForgot.getText();
- String email = textEmailForgot.getText();
- String passwordNovaForgot1 = passwordNovaForgot.getText();
- String passwordConfirmarForgot1 = passwordConfirmarForgot.getText();
- //comparar as 2 passwords
- if(passwordNovaForgot1.equals(passwordConfirmarForgot1)) {
- //Verificar se o username existe
- try {
- Connection lig = DriverManager.getConnection("jdbc:mysql://localhost/consultorio", "root", "");
- Statement instRegisto = lig.createStatement();
- ResultSet resultadoRegisto = instRegisto
- .executeQuery("SELECT username, email FROM cliente where username = '" + username +"'");
- if(resultadoRegisto.next() == true) {
- String emailDB = resultadoRegisto.getString("email");
- if(email.equals(emailDB)) {
- PreparedStatement instPassword = lig.prepareStatement(
- "UPDATE cliente SET palavraChave = ? WHERE username = '" + username + "'");
- instPassword.setString(1, passwordNovaForgot1);
- int linhasAlteradas = instPassword.executeUpdate();
- if (linhasAlteradas == 1) {
- JOptionPane.showMessageDialog(null, "Palavra-Passe atualizada");
- //volta para o login
- frame.getContentPane().removeAll();
- frame.getContentPane().add(panelLogin);
- frame.revalidate();
- frame.repaint();
- } else {
- JOptionPane.showMessageDialog(null, "Palavra-Passe não atualizada");
- }
- }
- else {
- JOptionPane.showMessageDialog(null, "Email errado");
- textEmailForgot.setText("");
- }
- }
- else {
- JOptionPane.showMessageDialog(null, "O username não existe.");
- }
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "BD indísponivel! | " + ex);
- }
- }
- else {
- JOptionPane.showMessageDialog(null, "As palavras-Passe não correspondem.");
- passwordNovaForgot.setText("");
- passwordConfirmarForgot.setText("");
- }
- passwordNovaForgot.setText("");
- passwordConfirmarForgot.setText("");
- }
- });
- GridBagConstraints gbc_button = new GridBagConstraints();
- gbc_button.gridwidth = 15;
- gbc_button.gridx = 0;
- gbc_button.gridy = 7;
- panelForgot.add(button, gbc_button);
- JMenuBar menuBar = new JMenuBar();
- frame.setJMenuBar(menuBar);
- JMenu mnIncio = new JMenu("In\u00EDcio");
- menuBar.add(mnIncio);
- mntmLogin = new JMenuItem("Login");
- mntmLogin.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- frame.getContentPane().removeAll();
- frame.getContentPane().add(panelLogin);
- frame.revalidate();
- frame.repaint();
- }
- });
- mnIncio.add(mntmLogin);
- mntmRegisto = new JMenuItem("Registo");
- mntmRegisto.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- frame.getContentPane().removeAll();
- frame.getContentPane().add(panelRegisto);
- frame.revalidate();
- frame.repaint();
- }
- });
- mnIncio.add(mntmRegisto);
- JMenu mnUtilizador = new JMenu("utilizador");
- menuBar.add(mnUtilizador);
- mntmPerfil = new JMenuItem("Perfil");
- mntmPerfil.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- frame.getContentPane().removeAll();
- frame.getContentPane().add(panelPerfil);
- frame.revalidate();
- frame.repaint();
- }
- });
- mnUtilizador.add(mntmPerfil);
- JMenu mnMensagem = new JMenu("Mensagem");
- menuBar.add(mnMensagem);
- mntmInbox = new JMenuItem("Inbox");
- mntmInbox.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- frame.getContentPane().removeAll();
- frame.getContentPane().add(panelInbox);
- frame.revalidate();
- frame.repaint();
- comboBoxFiltroCategoria.setSelectedIndex(0);
- String origemFiltro = (String) comboBoxFiltroOrigem.getSelectedItem();
- currentFilter = origemFiltro;
- if(origemFiltro == "Clientes") {
- MensagensCliente();
- }
- else {
- }
- }
- });
- mntmInbox.setEnabled(false);
- mnMensagem.add(mntmInbox);
- mntmEscrever = new JMenuItem("Escrever");
- mntmEscrever.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- textDestinatario.setText("");
- textAssunto.setText("");
- textCorpo.setText("");
- comboBoxIdentificador.setSelectedIndex(0);
- comboBoxIdentificador.setSelectedIndex(0);
- comboBoxIdentificador.setSelectedIndex(0);
- frame.getContentPane().removeAll();
- frame.getContentPane().add(panelMensagem);
- frame.revalidate();
- frame.repaint();
- }
- });
- mntmEscrever.setEnabled(false);
- mnMensagem.add(mntmEscrever);
- JMenu mnOutros = new JMenu("Outros");
- menuBar.add(mnOutros);
- mntmCancelar = new JMenuItem("Cancelar todas as a\u00E7\u00F5es");
- mntmCancelar.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- comboBoxTipoSangue.setSelectedIndex(0);
- comboBoxSexo.setSelectedIndex(0);
- textNome.setText("");
- textApelido.setText("");
- textUsername.setText("");
- textDataNascimento.setText("AAAA-MM-DD");
- textDataNascimento.setForeground(Color.GRAY);
- textContacto.setText("");
- textEmail.setText("Tudo em minúsculas");
- textEmail.setForeground(Color.GRAY);
- textMorada.setText("");
- textUsernameLogin.setText("");
- passwordVelha.setText("");
- passwordNova.setText("");
- passwordConfirmar.setText("");
- textUsernameForgot.setText("");
- textEmailForgot.setText("Tudo em minúsculas");
- textEmailForgot.setForeground(Color.GRAY);
- passwordNovaForgot.setText("");
- passwordConfirmarForgot.setText("");
- textDestinatario.setText("");
- textAssunto.setText("");
- passwordLogin.setText("");;
- passwordRegisto.setText("");;
- textEmailForgot.setText("");;
- textOrigemLer.setText("");;
- textAssuntoLer.setText("");;
- textCategorialer.setText("");;
- textDataLer.setText("");;
- /** Perfil - Para avaliação para ver se se tira os campos ou não - Provavelmente não */
- /*
- textNomePerfil.setText("");
- textApelidoPerfil.setText("");
- textIDPerfil.setText("");
- textUsernamePerfil.setText("");
- textDataNascimentoPerfil.setText("");
- textEmailPerfil.setText("");
- textContactoPerfil.setText("");
- textMoradaPerfil.setText("");
- textTipoSanguePerfil.setText("");
- textSexoPerfil.setText("");
- */
- passwordLogin.setText("");
- passwordRegisto.setText("");
- /** JcomboBoxes */
- comboBoxFiltroOrigem.setSelectedIndex(0);
- comboBoxFiltroCategoria.setSelectedIndex(0);
- comboBoxDestinatario.setSelectedIndex(0);
- comboBoxIdentificador.setSelectedIndex(0);
- /** textpanes */
- textCorpo.setText("");
- textCorpoLer.setText("");
- }
- });
- mnOutros.add(mntmCancelar);
- mntmLogout = new JMenuItem("Terminar Sess\u00E3o");
- mntmLogout.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- currentUserID = 0;
- frame.getContentPane().removeAll();
- frame.getContentPane().add(panelLogin);
- frame.revalidate();
- frame.repaint();
- mntmLogin.setEnabled(true);
- mntmRegisto.setEnabled(true);
- mntmPerfil.setEnabled(false);
- mntmLogout.setEnabled(false);
- mntmEscrever.setEnabled(false);
- mntmInbox.setEnabled(false);
- passwordVelha.setText("");
- passwordNova.setText("");
- passwordConfirmar.setText("");
- }
- });
- mnOutros.add(mntmLogout);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement