Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FormLogin
- package Teste2018;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.GridLayout;
- import java.awt.Image;
- import javax.swing.JTextField;
- import java.awt.event.FocusAdapter;
- import java.awt.event.FocusEvent;
- import java.io.IOException;
- import java.net.URISyntaxException;
- import java.sql.SQLException;
- import java.text.DateFormat;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import javax.swing.border.TitledBorder;
- import javax.swing.text.JTextComponent;
- import javax.swing.border.LineBorder;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.SwingConstants;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import java.awt.SystemColor;
- import javax.swing.UIManager;
- import java.awt.Font;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.awt.event.KeyAdapter;
- import java.awt.event.KeyEvent;
- import javax.swing.JComboBox;
- import javax.swing.DefaultComboBoxModel;
- import java.awt.Toolkit;
- public class FormLogin extends JFrame {
- private static final long serialVersionUID = 1L;
- private JTextField nifLocaliza;
- private JTextField nomee;
- private JTextField dadospw;
- private JTextField dadosemail;
- private JPanel painelacoes;
- JPanel painelrelogio;
- private int registoAtual=0;
- List <loginOO> listaLogin = new ArrayList<loginOO>();
- operacaocrud op=new operacaocrud();
- loginOO login=new loginOO();
- private List<loginOO> loginList;
- private JTextComponent dadosnome;
- private int idlogin;
- private JTextComponent nacionalidade;
- private String SelectImagem00;
- private String imag;
- private JComboBox txttipo;
- static String tipo;
- public FormLogin(String tipo) {
- this.tipo = tipo;
- setTitle("Constru\u00E7\u00F5es Isipal : Gest\u00E3o de Contas");
- setIconImage(Toolkit.getDefaultToolkit().getImage(FormLogin.class.getResource("/Imagens/isi32.png")));
- setBounds(100,80,900,650);
- getContentPane().setLayout(null);
- JPanel PainelPrincipal = new JPanel();
- PainelPrincipal.setBackground(new Color(210, 105, 30));
- PainelPrincipal.setBounds(0, 0, 884, 611);
- getContentPane().add(PainelPrincipal);
- PainelPrincipal.setLayout(null);
- JPanel painelpesquisa = new JPanel();
- painelpesquisa.setBackground(new Color(255, 127, 80));
- painelpesquisa.setBorder(new TitledBorder(new LineBorder(new Color(255, 255, 255), 2, true), "Pesquisa", TitledBorder.CENTER, TitledBorder.TOP, null, new Color(255, 255, 255)));
- painelpesquisa.setBounds(10, 145, 589, 82);
- PainelPrincipal.add(painelpesquisa);
- painelpesquisa.setLayout(null);
- nifLocaliza = new JTextField();
- nifLocaliza.setHorizontalAlignment(SwingConstants.LEFT);
- nifLocaliza.setBounds(34, 34, 86, 20);
- painelpesquisa.add(nifLocaliza);
- nifLocaliza.setColumns(10);
- JLabel lblNif = new JLabel("User:");
- lblNif.setFont(new Font("Nirmala UI Semilight", Font.PLAIN, 11));
- lblNif.setForeground(UIManager.getColor("Button.highlight"));
- lblNif.setBounds(9, 37, 46, 14);
- painelpesquisa.add(lblNif);
- JButton primeiro = new JButton("Primeiro");
- primeiro.setFont(new Font("Nirmala UI Semilight", Font.PLAIN, 11));
- primeiro.setBackground(new Color(255, 160, 122));
- primeiro.setForeground(new Color(255, 250, 240));
- primeiro.setBounds(222, 32, 85, 23);
- painelpesquisa.add(primeiro);
- JButton anterior = new JButton("Anterior");
- anterior.setFont(new Font("Nirmala UI Semilight", Font.PLAIN, 11));
- anterior.setForeground(new Color(255, 250, 250));
- anterior.setBackground(new Color(255, 160, 122));
- anterior.setBounds(317, 32, 81, 23);
- painelpesquisa.add(anterior);
- JButton seguinte = new JButton("Seguinte");
- seguinte.setFont(new Font("Nirmala UI Semilight", Font.PLAIN, 11));
- seguinte.setForeground(new Color(255, 250, 240));
- seguinte.setBackground(new Color(255, 160, 122));
- seguinte.setBounds(408, 32, 86, 23);
- painelpesquisa.add(seguinte);
- JButton ultimo = new JButton("\u00DAltimo");
- ultimo.setFont(new Font("Nirmala UI Semilight", Font.PLAIN, 11));
- ultimo.setForeground(new Color(245, 255, 250));
- ultimo.setBackground(new Color(255, 160, 122));
- ultimo.setBounds(504, 32, 75, 23);
- painelpesquisa.add(ultimo);
- JButton pesquisar = new JButton("Pesquisar");
- pesquisar.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- try {
- onClickLocalizar();
- } catch (NumberFormatException | SQLException | IOException | InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- });
- pesquisar.setFont(new Font("Nirmala UI Semilight", Font.PLAIN, 11));
- pesquisar.setForeground(new Color(255, 250, 240));
- pesquisar.setBackground(new Color(255, 160, 122));
- pesquisar.setBounds(130, 32, 86, 23);
- painelpesquisa.add(pesquisar);
- ultimo.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- onClickUltimo();
- } catch (SQLException | IOException | InterruptedException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- });
- seguinte.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- onClickProximo();
- } catch (SQLException | IOException | InterruptedException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- });
- anterior.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- onClickAnterior();
- } catch (SQLException | IOException | InterruptedException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- });
- primeiro.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- try {
- onClickPrimeiro();
- } catch (SQLException | IOException | InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- });
- JPanel painelinformacao = new JPanel();
- painelinformacao.setForeground(UIManager.getColor("Button.highlight"));
- painelinformacao.setBackground(new Color(255, 127, 80));
- painelinformacao.setBorder(new TitledBorder(new LineBorder(new Color(255, 255, 255), 2), "Informa\u00E7\u00E3o", TitledBorder.CENTER, TitledBorder.TOP, null, new Color(255, 255, 255)));
- painelinformacao.setBounds(10, 253, 589, 197);
- PainelPrincipal.add(painelinformacao);
- painelinformacao.setLayout(null);
- JLabel user = new JLabel("User:");
- user.setFont(new Font("Nirmala UI Semilight", Font.PLAIN, 11));
- user.setForeground(UIManager.getColor("Button.highlight"));
- user.setBackground(SystemColor.textInactiveText);
- user.setBounds(10, 35, 46, 14);
- painelinformacao.add(user);
- JLabel pw = new JLabel("Password:");
- pw.setFont(new Font("Nirmala UI Semilight", Font.PLAIN, 11));
- pw.setForeground(UIManager.getColor("Button.highlight"));
- pw.setBounds(10, 60, 130, 14);
- painelinformacao.add(pw);
- JLabel tipo1 = new JLabel("Tipo:");
- tipo1.setFont(new Font("Nirmala UI Semilight", Font.PLAIN, 11));
- tipo1.setForeground(UIManager.getColor("Button.light"));
- tipo1.setToolTipText("");
- tipo1.setBounds(10, 85, 46, 14);
- painelinformacao.add(tipo1);
- JLabel email = new JLabel("Email:");
- email.setFont(new Font("Nirmala UI Semilight", Font.PLAIN, 11));
- email.setForeground(UIManager.getColor("Button.highlight"));
- email.setBounds(10, 110, 35, 14);
- painelinformacao.add(email);
- nomee = new JTextField();
- nomee.setBounds(47, 32, 174, 20);
- painelinformacao.add(nomee);
- nomee.setColumns(10);
- dadospw = new JTextField();
- dadospw.setColumns(10);
- dadospw.setBounds(57, 57, 164, 20);
- painelinformacao.add(dadospw);
- dadosemail = new JTextField();
- dadosemail.setColumns(10);
- dadosemail.setBounds(47, 107, 174, 20);
- painelinformacao.add(dadosemail);
- JButton button = new JButton("Limpar");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- limparcampos();
- }
- });
- button.setForeground(new Color(255, 250, 240));
- button.setFont(new Font("Dialog", Font.PLAIN, 11));
- button.setBackground(new Color(255, 160, 122));
- button.setBounds(498, 152, 81, 33);
- painelinformacao.add(button);
- txttipo = new JComboBox();
- txttipo.setModel(new DefaultComboBoxModel(new String[] {"Selecione...", "Admin", "User"}));
- txttipo.setBounds(47, 83, 174, 20);
- painelinformacao.add(txttipo);
- painelacoes = new JPanel();
- painelacoes.setBackground(new Color(255, 127, 80));
- painelacoes.setBorder(new TitledBorder(new LineBorder(new Color(255, 255, 255), 2), "A\u00E7\u00F5es", TitledBorder.CENTER, TitledBorder.TOP, null, new Color(255, 255, 255)));
- painelacoes.setBounds(641, 253, 211, 197);
- PainelPrincipal.add(painelacoes);
- JButton guardar = new JButton("Guardar");
- guardar.setFont(new Font("Dialog", Font.PLAIN, 13));
- guardar.setBackground(new Color(255, 160, 122));
- guardar.setForeground(new Color(255, 250, 240));
- guardar.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- try {
- onClickGuardar();
- } catch (NumberFormatException | SQLException | IOException | InterruptedException | ParseException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- });
- painelacoes.setLayout(new GridLayout(0, 1, 10, 0));
- JButton btnNovo = new JButton("Novo");
- btnNovo.setFont(new Font("Dialog", Font.PLAIN, 13));
- btnNovo.setBackground(new Color(255, 160, 122));
- btnNovo.setForeground(new Color(255, 250, 240));
- btnNovo.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- }
- });
- btnNovo.setForeground(Color.WHITE);
- btnNovo.setFont(new Font("Dialog", Font.PLAIN, 13));
- painelacoes.add(btnNovo);
- painelacoes.add(guardar);
- JButton eliminar = new JButton("Eliminar");
- eliminar.setFont(new Font("Dialog", Font.PLAIN, 13));
- eliminar.setBackground(new Color(255, 160, 122));
- eliminar.setForeground(new Color(255, 250, 240));
- eliminar.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- try {
- onClickRemover();
- } catch (SQLException | IOException | InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- });
- painelacoes.add(eliminar);
- JButton atualizar = new JButton("Atualizar");
- atualizar.setFont(new Font("Dialog", Font.PLAIN, 13));
- atualizar.setBackground(new Color(255, 160, 122));
- atualizar.setForeground(new Color(255, 250, 240));
- atualizar.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- try {
- onClickAlterar();
- } catch (NumberFormatException | SQLException | IOException | InterruptedException | ParseException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- });
- painelacoes.add(atualizar);
- JPanel CAbecalho = new JPanel();
- CAbecalho.setBackground(new Color(255, 127, 80));
- CAbecalho.setBounds(10, 11, 842, 112);
- PainelPrincipal.add(CAbecalho);
- CAbecalho.setLayout(null);
- painelrelogio = new JPanel();
- painelrelogio.setBackground(new Color(255, 127, 80));
- painelrelogio.setBounds(503, 11, 310, 80);
- CAbecalho.add(painelrelogio);
- painelrelogio.setLayout(null);
- JLabel lblMenu = new JLabel("Zona");
- lblMenu.setForeground(new Color(255, 250, 250));
- lblMenu.setFont(new Font("DIN Next LT Pro Black", Font.PLAIN, 30));
- lblMenu.setHorizontalAlignment(SwingConstants.CENTER);
- lblMenu.setBounds(320, 0, 103, 53);
- CAbecalho.add(lblMenu);
- JLabel lblCliente = new JLabel("Conta");
- lblCliente.setHorizontalAlignment(SwingConstants.CENTER);
- lblCliente.setForeground(new Color(255, 250, 250));
- lblCliente.setFont(new Font("DIN Next LT Pro Black", Font.PLAIN, 47));
- lblCliente.setBounds(351, 32, 160, 80);
- CAbecalho.add(lblCliente);
- JLabel label_2 = new JLabel("");
- label_2.setIcon(new ImageIcon(FormLogin.class.getResource("/Imagens/LOGO-3.png")));
- label_2.setHorizontalAlignment(SwingConstants.CENTER);
- label_2.setBounds(20, 11, 310, 101);
- CAbecalho.add(label_2);
- JPanel menuuu = new JPanel();
- menuuu.setBackground(new Color(255, 160, 122));
- menuuu.setBounds(641, 480, 211, 83);
- PainelPrincipal.add(menuuu);
- menuuu.setLayout(null);
- JButton menu = new JButton("Menu");
- menu.setForeground(new Color(255, 250, 240));
- menu.setFont(new Font("DIN Next LT Pro Black", Font.PLAIN, 30));
- menu.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- dispose();
- Principal janela = new Principal(tipo);
- janela.setVisible(true);
- JDClock relogio = new JDClock(new Dimension(300, 75), 5, 10, new Color(255,127,80), Color.WHITE, new Color(255,127,80));
- relogio.setLocation(5, 5);
- janela.painelrelogio.add(relogio);
- }
- });
- menu.setFocusPainted(false);
- menu.setContentAreaFilled(false);
- menu.setBounds(0, 0, 211, 83);
- menuuu.add(menu);
- JPanel panel = new JPanel();
- panel.setLayout(null);
- panel.setBackground(new Color(255, 160, 122));
- panel.setBounds(10, 481, 589, 82);
- PainelPrincipal.add(panel);
- JLabel label = new JLabel("2017/2018 \u00A9 Fernando Almeida");
- label.setHorizontalAlignment(SwingConstants.CENTER);
- label.setForeground(Color.WHITE);
- label.setFont(new Font("Nirmala UI Semilight", Font.PLAIN, 17));
- label.setBounds(244, 15, 253, 51);
- panel.add(label);
- JLabel label_1 = new JLabel("");
- label_1.setIcon(new ImageIcon(FormLogin.class.getResource("/Imagens/isi32.png")));
- label_1.setBounds(525, 27, 32, 32);
- panel.add(label_1);
- JButton button_1 = new JButton("");
- button_1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- java.awt.Desktop.getDesktop().browse(new java.net.URI("http://www.aesampaio.pt/"));
- } catch (IOException | URISyntaxException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- });
- button_1.setIcon(new ImageIcon(FormLogin.class.getResource("/Imagens/Escola2.png")));
- button_1.setFocusPainted(false);
- button_1.setBorder(null);
- button_1.setBackground((Color) null);
- button_1.setBounds(172, 15, 54, 51);
- panel.add(button_1);
- JButton button_2 = new JButton("");
- button_2.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- java.awt.Desktop.getDesktop().browse(new java.net.URI("http://www.twitter.com/"));
- } catch (IOException | URISyntaxException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- });
- button_2.setIcon(new ImageIcon(FormLogin.class.getResource("/Imagens/TwitterB.png")));
- button_2.setFocusPainted(false);
- button_2.setBorder(null);
- button_2.setBackground((Color) null);
- button_2.setBounds(88, 15, 54, 51);
- panel.add(button_2);
- JButton button_3 = new JButton("");
- button_3.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- java.awt.Desktop.getDesktop().browse(new java.net.URI("http://www.facebook.com/"));
- } catch (IOException | URISyntaxException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- });
- button_3.setIcon(new ImageIcon(FormLogin.class.getResource("/Imagens/FacebookB.png")));
- button_3.setFocusPainted(false);
- button_3.setBorder(null);
- button_3.setBackground((Color) null);
- button_3.setBounds(10, 15, 54, 51);
- panel.add(button_3);
- JPanel panel_1 = new JPanel();
- panel_1.setLayout(null);
- panel_1.setBackground(new Color(255, 160, 122));
- panel_1.setBounds(641, 145, 211, 83);
- PainelPrincipal.add(panel_1);
- JButton btnListagens = new JButton("Listagens");
- btnListagens.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- }
- });
- btnListagens.setForeground(new Color(255, 250, 240));
- btnListagens.setFont(new Font("DIN Next LT Pro Black", Font.PLAIN, 30));
- btnListagens.setFocusPainted(false);
- btnListagens.setContentAreaFilled(false);
- btnListagens.setBounds(0, 0, 211, 83);
- panel_1.add(btnListagens);
- // TODO Auto-generated constructor stub
- }
- protected void onClickLocalizar() throws NumberFormatException, SQLException, IOException, InterruptedException {
- // TODO Auto-generated method stub
- if(nifLocaliza.getText()=="") {
- nifLocaliza.requestFocus();
- }else {
- loginOO log = op.obtemUserLogin(String.valueOf(nifLocaliza.getText()));
- idlogin=log.getIdlogin();
- nomee.setText(log.getUser());
- dadospw.setText(log.getPw());
- txttipo.setSelectedItem(String.valueOf(log.getTipo()));
- dadosemail.setText(String.valueOf(log.getEmail()));
- }
- }
- void getValores(int index) throws SQLException, IOException, InterruptedException {
- loginList= op.obtemlogin();
- if (index <= loginList.size()-1) {
- loginOO log = loginList.get(index);
- idlogin=log.getIdlogin();
- nomee.setText(log.getUser());
- dadospw.setText(log.getPw());
- txttipo.setSelectedItem(String.valueOf(log.getTipo()));
- dadosemail.setText(String.valueOf(log.getEmail()));
- }
- }
- private void onClickGuardar() throws NumberFormatException, SQLException, IOException, InterruptedException, ParseException {
- op.guardarlogin(nomee.getText(), dadospw.getText(), String.valueOf(txttipo.getSelectedItem()), dadosemail.getText());
- JOptionPane.showMessageDialog(this, "Novo login inserido com sucesso");
- limparcampos();
- }
- private void onClickAlterar() throws NumberFormatException, SQLException, IOException, InterruptedException, ParseException {
- op.alterarlogin(nomee.getText(), dadospw.getText(), String.valueOf(txttipo.getSelectedItem()), dadosemail.getText(), idlogin);
- JOptionPane.showMessageDialog(this, "Login atualizado com sucesso");
- limparcampos();
- }
- private void onClickRemover() throws SQLException, IOException, InterruptedException {
- op.apagarclientes(idlogin);
- JOptionPane.showMessageDialog(this, "Login removido com sucesso");
- limparcampos();
- }
- private void onClickPrimeiro() throws SQLException, IOException, InterruptedException {
- nifLocaliza.setText("");
- registoAtual = 0;
- getValores(registoAtual);
- nifLocaliza.setText("");
- }
- private void onClickUltimo() throws SQLException, IOException, InterruptedException {
- nifLocaliza.setText("");
- loginList= new operacaocrud().obtemlogin();
- registoAtual = loginList.size() - 1;
- getValores(registoAtual);
- nifLocaliza.setText("");
- }
- private void onClickProximo() throws SQLException, IOException, InterruptedException {
- loginList= new operacaocrud().obtemlogin();
- if (registoAtual != loginList.size() - 1) {
- getValores(++registoAtual);
- }
- nifLocaliza.setText("");
- }
- private void onClickAnterior() throws SQLException, IOException, InterruptedException {
- nifLocaliza.setText("");
- if (registoAtual != 0) {
- getValores(--registoAtual);
- }
- nifLocaliza.setText("");
- }
- private void limparcampos() {
- nomee.setText("");
- dadospw.setText("");
- dadosemail.setText("");
- nifLocaliza.setText("");
- txttipo.setSelectedIndex(0);
- }
- void redimencionaImagem(JButton label, String directoria, String nomeFoto,int comprimento, int altura){
- label.setIcon(new ImageIcon(new ImageIcon(FormProdutos.class.getResource("/Imagens/"+directoria+"/"+nomeFoto)).getImage().getScaledInstance(comprimento, altura, Image.SCALE_DEFAULT)));
- }
- void redimencionaImagemLabel(JLabel label, String directoria, String nomeFoto,int comprimento, int altura){
- label.setIcon(new ImageIcon(new ImageIcon(FormProdutos.class.getResource("/Imagens/"+directoria+"/"+nomeFoto)).getImage().getScaledInstance(comprimento, altura, Image.SCALE_DEFAULT)));
- }
- /*void guardarclientes() throws NumberFormatException, SQLException, IOException, InterruptedException, ParseException {
- op.guardarclientes(nomee.getText(), dadosdatanascimento.getText(), Integer.parseInt(dadostelefone.getText()), Integer.parseInt(dadostelemovel.getText()), dadosmorada.getText(), dadoslocalidade.getText(), dadoscodigopostal.getText(), Integer.parseInt(dadosnif.getText()), dadosemail.getText(), dadosnacionalidade.getText(), dadosfoto.getText());
- }
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- FormLogin janela = new FormLogin(tipo);
- janela.setVisible(true);
- JDClock relogio = new JDClock(new Dimension(300, 75), 5, 10, new Color(255,127,80), Color.WHITE, new Color(255,127,80));
- relogio.setLocation(5, 5);
- janela.painelrelogio.add(relogio);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement