{"action":"opened","issue":{"url":"https://api.github.com/repos/alekzander1/cruzaito/issues/2","labels_url":"https://api.github.com/repos/alekzander1/cruzaito/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/alekzander1/cruzaito/issues/2/comments","events_url":"https://api.github.com/repos/alekzander1/cruzaito/issues/2/events","html_url":"https://github.com/alekzander1/cruzaito/issues/2","id":83336381,"number":2,"title":"maikeyacson","user":{"login":"alekzander1","id":12685765,"avatar_url":"https://avatars.githubusercontent.com/u/12685765?v=3","gravatar_id":"","url":"https://api.github.com/users/alekzander1","html_url":"https://github.com/alekzander1","followers_url":"https://api.github.com/users/alekzander1/followers","following_url":"https://api.github.com/users/alekzander1/following{/other_user}","gists_url":"https://api.github.com/users/alekzander1/gists{/gist_id}","starred_url":"https://api.github.com/users/alekzander1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alekzander1/subscriptions","organizations_url":"https://api.github.com/users/alekzander1/orgs","repos_url":"https://api.github.com/users/alekzander1/repos","events_url":"https://api.github.com/users/alekzander1/events{/privacy}","received_events_url":"https://api.github.com/users/alekzander1/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-06-01T06:12:05Z","updated_at":"2015-06-01T06:12:05Z","closed_at":null,"body":"/*\r\n * To change this template, choose Tools | Templates\r\n * and open the template in the editor.\r\n */\r\npackage interfaz;\r\n\r\nimport entidades.Empleado;\r\nimport java.awt.Color;\r\nimport java.awt.Dimension;\r\nimport java.awt.FlowLayout;\r\nimport java.awt.GridLayout;\r\nimport java.awt.event.ActionEvent;\r\nimport java.awt.event.ActionListener;\r\nimport javax.swing.BorderFactory;\r\nimport javax.swing.BoxLayout;\r\nimport javax.swing.JOptionPane;\r\nimport javax.swing.JPanel;\r\nimport javax.swing.JScrollPane;\r\nimport javax.swing.JTextArea;\r\nimport javax.swing.JTextField;\r\nimport javax.swing.border.EmptyBorder;\r\nimport javax.swing.border.EtchedBorder;\r\n\r\n/**\r\n *\r\n * @author DAM1415\r\n */\r\npublic class PanelAlta extends JPanel implements IPantalla{\r\n    private JTextField jtfNifBusca, jtfNif;\r\n    private JTextField jtfNombre;\r\n    private JTextField jtfApellido1;\r\n    private JTextField jtfApellido2;\r\n    private JTextField jtfSueldo;\r\n    private Boton jbtBuscar;\r\n    private Boton jbtGuardar;\r\n    private Boton jbtCancelar;\r\n    private VentanaPrincipal vp;\r\n    \r\n    public PanelAlta(VentanaPrincipal vp){\r\n        super();\r\n        this.vp=vp;\r\n        inicializaPanel();\r\n        inicializaComponentes();\r\n        distribuyeComponentes();\r\n        controlComponentes();\r\n     }\r\n    private void inicializaPanel(){\r\n        setBackground(COLOR_FONDO_ALTA);\r\n        setOpaque(true);\r\n    }\r\n    private void inicializaComponentes(){\r\n        jtfNifBusca=new JTextField(20);\r\n        jtfNif=new JTextField(20);\r\n        jtfNombre=new JTextField(20);\r\n        jtfApellido1= new JTextField(20);\r\n        jtfApellido2= new JTextField(20);\r\n        jtfSueldo= new JTextField(5);\r\n        \r\n        jbtBuscar = new Boton(\"buscar\");\r\n        jbtGuardar= new Boton(\"guardar\");\r\n        jbtCancelar= new Boton(\"cancelar\");\r\n        jbtGuardar.setEnabled(false);\r\n        activacionCampos(false);\r\n    }\r\n    private void distribuyeComponentes(){\r\n        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));\r\n        \r\n        JPanel jpTitulo = new JPanel(new FlowLayout());\r\n        jpTitulo.add(new LabelTitulo(\"Empleados\"));\r\n        jpTitulo.setOpaque(true);\r\n        \r\n        JPanel jpBusca = new JPanel(new FlowLayout());\r\n        jpBusca.setBackground(Color.GRAY);\r\n        jpBusca.setOpaque(true);\r\n        jpBusca.setBorder(BorderFactory.createCompoundBorder(new EmptyBorder(10,10,10,10), new EtchedBorder()));\r\n        jpBusca.add(new LabelCampos(\"Nif\"));\r\n        jpBusca.add(jtfNifBusca);\r\n        jpBusca.add(jbtBuscar);\r\n        \r\n        JPanel jpDatos = new JPanel(new GridLayout(5,2));\r\n        jpDatos.setBackground(COLOR_FONDO_DATOS_ALTA);\r\n        JPanel jpBotones = new JPanel(new FlowLayout());\r\n        jpBotones.setBackground(COLOR_FONDO_BOTONES_ALTA);\r\n        \r\n        jpDatos.add(new LabelCampos(\"Nif\"));\r\n        jpDatos.add(jtfNif);\r\n        jtfNif.setEditable(false);\r\n        jtfNif.setBackground(Color.YELLOW);\r\n        jpDatos.add(new LabelCampos(\"Nombre\"));\r\n        jpDatos.add(jtfNombre);\r\n        jpDatos.add(new LabelCampos(\"Apellido1\"));\r\n        jpDatos.add(jtfApellido1);\r\n        jpDatos.add(new LabelCampos(\"Apellido2\"));\r\n        jpDatos.add(jtfApellido2);\r\n        jpDatos.add(new LabelCampos(\"Sueldo\"));\r\n        jpDatos.add(jtfSueldo);\r\n        \r\n        jpBotones.add(jbtGuardar);\r\n        jpBotones.add(jbtCancelar);        \r\n        \r\n        add(jpTitulo);\r\n        add(jpBusca);\r\n        add(jpDatos);\r\n        add(jpBotones);\r\n    }\r\n    \r\n    private void activacionCampos(boolean activa){\r\n        jtfNombre.setEditable(activa);\r\n        jtfApellido1.setEditable(activa);\r\n        jtfApellido2.setEditable(activa);\r\n        jtfSueldo.setEditable(activa);\r\n        if(activa){\r\n            jtfNombre.setBackground(new Color(255,255,255));\r\n            jtfApellido1.setBackground(new Color(255,255,255));\r\n            jtfApellido2.setBackground(new Color(255,255,255));\r\n            jtfSueldo.setBackground(new Color(255,255,255));\r\n        }else{\r\n            jtfNombre.setBackground(new Color(150,150,150));\r\n            jtfApellido1.setBackground(new Color(150,150,150));\r\n            jtfApellido2.setBackground(new Color(150,150,150));\r\n            jtfSueldo.setBackground(new Color(150,150,150));\r\n        }\r\n    }\r\n    \r\n    private void vaciaComponentes(){\r\n        jtfNif.setText(\"\");\r\n        jtfNombre.setText(\"\");\r\n        jtfApellido1.setText(\"\");\r\n        jtfApellido2.setText(\"\");\r\n        jtfSueldo.setText(\"\");\r\n    }\r\n    private void controlComponentes() {\r\n        jbtBuscar.addActionListener(new ActionListener() {\r\n            @Override\r\n            public void actionPerformed(ActionEvent ae) {\r\n                if (!vp.getConectaBD().existEmpleado(jtfNifBusca.getText())) {\r\n                    vaciaComponentes();\r\n                    activacionCampos(true);\r\n                    jbtGuardar.setEnabled(true);\r\n                    jtfNif.setText(jtfNifBusca.getText());\r\n                } else {\r\n                    JOptionPane.showMessageDialog(vp, \"El empleado ya está dado de alta\");\r\n                }\r\n            }\r\n        }\r\n        );\r\n        jbtGuardar.addActionListener(\r\n                new ActionListener() {\r\n                    @Override\r\n                    public void actionPerformed(ActionEvent ae) {\r\n                        Empleado empleado = new Empleado();\r\n                        empleado.setNif(jtfNif.getText());\r\n                        empleado.setNombre(jtfNombre.getText());\r\n                        empleado.setApellido1(jtfApellido1.getText());\r\n                        empleado.setApellido2(jtfApellido2.getText());\r\n                        double sueldo;\r\n                        try {\r\n                            sueldo = Double.parseDouble(jtfSueldo.getText());\r\n                        } catch (NumberFormatException ex) {\r\n                            sueldo = 0;\r\n                        }\r\n                        empleado.setSueldo(sueldo);\r\n                        if (vp.getConectaBD().addEmpleado(empleado)) {\r\n                            JOptionPane.showMessageDialog(vp, \"Empleado guardado\");\r\n                            vaciaComponentes();\r\n                        } else {\r\n                            JOptionPane.showMessageDialog(vp, \"Empleado no guardado\");\r\n                        }\r\n                        jtfNifBusca.setText(\"\");\r\n                    }\r\n                }\r\n        );\r\n\r\n        jbtCancelar.addActionListener(new ActionListener() {\r\n            @Override\r\n            public void actionPerformed(ActionEvent ae) {\r\n                vp.panelPortada();\r\n            }\r\n        }\r\n        );\r\n\r\n    }\r\n\r\n    \r\n   }\r\n    \r\n"}}