GUI Delete Fix when Selecting

1

Thinking that you enter 4 or more values and I try to eliminate any line of those 4 values by selecting the line and pressing a "Delete" button, which method I must implement in < strong> "Delete" , in this case occupy "Hide" .

I need you to really delete it by being selected and pressing the button.

     package Unidad1;

        import javax.swing.*;
        import java.awt.*;
        import java.awt.event.*;

        public class Ventana extends JFrame implements ActionListener {

            Ventana v;
            JLabel lnombre, ldireccion, lcorreo;
            JTextField tfnombre, tfdireccion, tfcorreo;
            JButton botona, botonb, botonc, botons;
            JTextArea area;
            JPanel panel;
            String Datos[][];
            String mensaje = "";
            int P = 0;

            public Ventana() {

                lnombre = new JLabel("Nombre");
                lnombre.setBounds(15, 20, 450, 20);

                ldireccion = new JLabel("Direccion");
                ldireccion.setBounds(15, 50, 450, 20);

                lcorreo = new JLabel("Correo");
                lcorreo.setBounds(15, 80, 450, 20);

                tfnombre = new JTextField();
                tfnombre.setBounds(100, 20, 450, 20);

                tfdireccion = new JTextField();
                tfdireccion.setBounds(100, 50, 450, 20);

                tfcorreo = new JTextField();
                tfcorreo.setBounds(100, 80, 450, 20);

                botona = new JButton("Aceptar");
                botona.setBounds(40, 300, 100, 20);
                botona.addActionListener(this);

                botonb = new JButton("Borrar");
                botonb.setBounds(170, 300, 100, 20);
                botonb.addActionListener(this);

                botonc = new JButton("Cancelar");
                botonc.setBounds(300, 300, 100, 20);
                botonc.addActionListener(this);

                botons = new JButton("Salir");
                botons.setBounds(430, 300, 100, 20);
                botons.addActionListener(this);

                area = new JTextArea();
                area.setBounds(10, 120, 565, 150);

                panel = new JPanel();
                panel.setLayout(null);

                panel.add(lnombre);
                panel.add(ldireccion);
                panel.add(lcorreo);
                panel.add(tfnombre);
                panel.add(tfdireccion);
                panel.add(tfcorreo);
                panel.add(botona);
                panel.add(botonb);
                panel.add(botonc);
                panel.add(botons);
                panel.add(area);

               add(panel);
                setSize(600, 380);
                setTitle("Unidad 1");
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                setVisible(true);
                Datos = new String[15][3];
            }

            public static void main(String[] args) {

                Ventana v = new Ventana();

            }

            @Override
            public void actionPerformed(ActionEvent e) {

                if (e.getSource() == botona) {
                    Capturar();
                    P = P + 1;
                }

                if (e.getSource() == botonb) {
                    Borrar();
                    P = P - 1;
                }

                if (e.getSource() == botonc) {
                    Cancelar();
                }
                if (e.getSource() == botons) {
                    Salir();
                }
            }

            void Capturar() {
                Guardar();
                Mostrar(Datos);
            }

            void Borrar() {
                Ocultar(Datos);
            }

            void Cancelar() {
                area.setText("");
            }

            void Salir() {
                super.dispose();
            }

            void Guardar() {
                if (P <= 15 && !estaVacio(tfnombre.getText())) {
                    Datos[P][0] = tfnombre.getText();
                    Datos[P][1] = tfdireccion.getText();
                    Datos[P][2] = tfcorreo.getText();
                    P = P + 1;
                } else {
                    mensaje = "Memoria llena.";
                }
                tfnombre.setText("");
                tfdireccion.setText("");
                tfcorreo.setText("");
            }

            void Mostrar(final String[][] a) {
                area.setText("");
                for (int i = 0; i < 15; i++) {

                    if (!estaVacio(a[i][0])) {
                area.setText(area.getText() + "Nombre: " + a[i][0] + "     Direccion: " + a[i][1] + "     Correo: " + a[i][2] + "\n");
            }
        }
    }

    void Ocultar(final String[][] a) {
        area.setText("");
        for (int i = 0; i > 15; i--) {

            if (estaVacio(a[i][0])) {
                area.setText(area.getText() + "Nombre: " + a[i][0] + "     Direccion: " + a[i][1] + "     Correo: " + a[i][2] + "\n");
            }
        }

    }


    private boolean estaVacio(final String nombre) {

        return nombre == null || nombre.isEmpty();
    }

}
    
asked by Ivan 05.05.2016 в 17:06
source

0 answers