Chamar lista através da interface gráfica![RESOLVIDO]

Não axei nada sobre o assunto e ainda naum consegui pensar em nada se alguem souber algo q possa me ajudar eu agradeço! :wink:

vlw!

Gente olha soh, eu naum sei onde ta o erro, soh pode ser nos testes que estou fazendo, pq ele coloca bonitinho os elementos na lista e retorna!

Mas a minha GUI ta dando uma IndexOutOfBoundsE. segue abaixo os codigos das classes se puderem dar uma revisada para mim! :wink:

Main

public class Main {

    public static void main(String args[]) throws ParseException{
        
        CadastroDePessoas cdp = new CadastroDePessoas();

        Pessoa p1 = new Pessoa("TESTE", "a", "a", "a", "a", "a", "a", "a");
        Pessoa p2 = new Pessoa("GUILHERME", "2a", "2a", "22a", "2a", "2a", "2a", "2a");
        Pessoa p3 = new Pessoa("JACO", "wow", "wow", "wow", "wow", "wow", "wow", "wow");
        Pessoa p4 = new Pessoa("LUIS", "2", "2", "2", "2", "2", "2", "2");
        Pessoa p5 = new Pessoa("ANA", "AA", "AA", "AA", "AA", "AA", "AA", "AA");

        cdp.adiciona(p4); //Adicionado desta forma
        cdp.adiciona(p5);

        JanelaCadastroDePessoas jcp = new JanelaCadastroDePessoas();
        jcp.getCdp().getLista().add(p1);
        jcp.getCdp().getLista().add(p2);
        jcp.getCdp().getLista().add(p3); //Adicionado de maneira diferente para não ter duvidas!
        jcp.getCdp().getLista().add(p4);
        jcp.getCdp().getLista().add(p5);

Cadastro de Pessoas

public class CadastroDePessoas{

    private List<Pessoa> lista;
    private int posicao = -1;

    public CadastroDePessoas(){
        lista = new ArrayList<Pessoa>();
    }

    public boolean adiciona(Pessoa p){
        return lista.add(p);
    }

    public Pessoa prox() throws NoSuchElementException, IndexOutOfBoundsException{
        return lista.get(++posicao);
    }

    public Pessoa ant() throws NoSuchElementException, IndexOutOfBoundsException{
        return lista.get(--posicao);
    }

    public Pessoa ultimoDaLista() throws NoSuchElementException, IndexOutOfBoundsException{
        return lista.get(lista.size()-1);
    }

    public Pessoa primeiroDaLista() throws NoSuchElementException, IndexOutOfBoundsException{
        return lista.get(0);
    }

    public int getPosicao() {
        return posicao;
    }

    public AList<Pessoa> getLista(){
        return lista;
    }

    @Override
    public String toString(){
        StringBuffer s = new StringBuffer();
        for(Pessoa p : lista){
            s.append(p.toString());
        }
        return s.toString();
    }
}

Interface grafica

package Interface;
import Classes.CadastroDePessoas;
import Classes.Pessoa;
import Classes.PlainDocument;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author P Informática
 */
public class JanelaCadastroDePessoas extends javax.swing.JFrame {
    
    CadastroDePessoas cadp = new CadastroDePessoas();

    public JanelaCadastroDePessoas() {
        initComponents();
       /* try {
            cdp = CadastroDePessoas.class.newInstance();
        }
        catch (InstantiationException ex) {
            Logger.getLogger(JanelaCadastroDePessoas.class.getName()).log(Level.SEVERE, "Erro", ex);
        }
        catch (IllegalAccessException ex) {
            Logger.getLogger(JanelaCadastroDePessoas.class.getName()).log(Level.SEVERE, "Erro", ex);
        }*/
    }

   //Aqui codigo gerado pelo netBeans

    private void btnFecharActionPerformed(java.awt.event.ActionEvent evt) {                                          
        this.dispose();
    }                                         

    private void btnProximoElemActionPerformed(java.awt.event.ActionEvent evt) {                                               
        try{
            txtNome.setText(cadp.prox().getNome());
            txtPosicaoLista.setText(String.valueOf(cadp.getPosicao()+2)+1);
        }
        catch(NoSuchElementException nsee){
            JOptionPane.showMessageDialog(null, "Não há registros na lista!", "ERRO", JOptionPane.ERROR_MESSAGE);
        }
        catch(IndexOutOfBoundsException iofbe){
            JOptionPane.showMessageDialog(null, "Não há proximo registro", "ERRO", JOptionPane.ERROR_MESSAGE);
        }
        catch(NullPointerException npe){
            JOptionPane.showMessageDialog(null, "Não há proximo registro!", "ERRO", JOptionPane.ERROR_MESSAGE);
        }
    }                                              

    private void btnUltimoElemActionPerformed(java.awt.event.ActionEvent evt) {                                              
        try{
            txtNome.setText(cadp.ultimoDaLista().getNome()); // ALTERAR ISSO
            txtPosicaoLista.setText(String.valueOf(cadp.ultimoDaLista()));
        }
        catch(NoSuchElementException nsee){
            JOptionPane.showMessageDialog(null, "Não há registros na lista", "ERRO", JOptionPane.ERROR_MESSAGE);
        }
        catch(IndexOutOfBoundsException iofbe){
            JOptionPane.showMessageDialog(null, "Não há registros", "ERRO", JOptionPane.ERROR_MESSAGE);
        }
        catch(NullPointerException npe){
            JOptionPane.showMessageDialog(null, "Não há mais registros!", "ERRO", JOptionPane.ERROR_MESSAGE);
        }
    }                                             

    private void btnPrimeiroElemActionPerformed(java.awt.event.ActionEvent evt) {                                                
        try{
            txtNome.setText(cadp.primeiroDaLista().getNome()); // ALTERAR ISSO
            txtPosicaoLista.setText(String.valueOf(cadp.primeiroDaLista()));
        }
        catch(NoSuchElementException nsee){
            JOptionPane.showMessageDialog(null, "Não há registros na lista", "ERRO", JOptionPane.ERROR_MESSAGE);
        }
        catch(IndexOutOfBoundsException iofbe){
            JOptionPane.showMessageDialog(null, "Não há registros", "ERRO", JOptionPane.ERROR_MESSAGE);
        }
        catch(NullPointerException npe){
            JOptionPane.showMessageDialog(null, "Não há registros!", "ERRO", JOptionPane.ERROR_MESSAGE);
        }
    }                                               

    private void btnAnteriorElemActionPerformed(java.awt.event.ActionEvent evt) {                                                
        try{
            txtNome.setText(cadp.primeiroDaLista().getNome()); // ALTERAR ISSO
            txtPosicaoLista.setText(String.valueOf((cadp.getPosicao()+2)-1));
        }
        catch(NoSuchElementException nsee){
            JOptionPane.showMessageDialog(null, "Não há registros na lista", "ERRO", JOptionPane.ERROR_MESSAGE);
        }
        catch(IndexOutOfBoundsException iofbe){
            JOptionPane.showMessageDialog(null, "Não há registro anterior", "ERRO", JOptionPane.ERROR_MESSAGE);
        }
        catch(NullPointerException npe){
            JOptionPane.showMessageDialog(null, "Não há registro anterior!", "ERRO", JOptionPane.ERROR_MESSAGE);
        }
    }                                               

    private void btnIrParaActionPerformed(java.awt.event.ActionEvent evt) {                                          
        try{
        cadp.getLista().get(Integer.parseInt(txtIrPara.getText().trim()));
        }
        catch(IndexOutOfBoundsException iofbe){
            JOptionPane.showMessageDialog(null, "Não há elementos na posição selecionada", "ERRO", JOptionPane.ERROR_MESSAGE);
        }
        catch(NumberFormatException nfe){
            JOptionPane.showMessageDialog(null, "Este campo deve ser preenchido com números e sem espaços entre eles", "ERRO", JOptionPane.WARNING_MESSAGE);
        }
        finally{txtIrPara.setText("");}
    }                                         

    private void btnAddNovaPessoaActionPerformed(java.awt.event.ActionEvent evt) {  //EM CONSTRUÇÃO
        try{
            if(txtNome.getText().trim().equals("") ){

            }
            txtApelido.setText("");
            txtBairro.setText("");
            txtCep.setText("");
            txtCidade.setText("");
            txtEmailGeral.setText("");
            txtEndereco.setText("");
            txtFax.setText("");
            txtHomePage.setText("");
            txtIrPara.setText("");
            txtNome.setText("");
            txtPosicaoLista.setText("");
            txtTelefone.setText("");
            txtUF.setText("");
            
        }
        finally{

        }
    }

    public CadastroDePessoas getCdp(){
        return cadp;
    }
    public JTextField getTxtNome(){
        return txtNome;
    }
    public JTextField getTxtApelido(){
        return txtApelido;
    }
    public JTextField getTxtBairro(){
        return txtBairro;
    }
    public JTextField getTxtCep(){
        return txtCep;
    }
    public JTextField getTxtCidade(){
        return txtCidade;
    }
    public JTextField getTxtEmailGeral(){
        return txtEmailGeral;
    }
    public JTextField getTxtEndereco(){
        return txtEndereco;
    }
    public JTextField getTxtFax(){
        return txtFax;
    }
    public JTextField getTxtUf(){
        return txtUF;
    }
    public JTextField getTxtTelefone(){
        return txtTelefone;
    }
    public JTextField getTxtHomePage(){
        return txtHomePage;
    }
    public JTextField getTxtPosicaoLista(){
        return txtPosicaoLista;
    }

    // Variables declaration - do not modify
    private javax.swing.JButton btnAddNovaPessoa;
    private javax.swing.JButton btnAnteriorElem;
    private javax.swing.JButton btnFechar;
    private javax.swing.JButton btnIrPara;
    private javax.swing.JButton btnPrimeiroElem;
    private javax.swing.JButton btnProximoElem;
    private javax.swing.JButton btnUltimoElem;
    private javax.swing.JLabel lbl1;
    private javax.swing.JLabel lblApelido;
    private javax.swing.JLabel lblBairro;
    private javax.swing.JLabel lblCadastroDePessoas;
    private javax.swing.JLabel lblCep;
    private javax.swing.JLabel lblCidade;
    private javax.swing.JLabel lblEmailGeral;
    private javax.swing.JLabel lblEndereco;
    private javax.swing.JLabel lblFax;
    private javax.swing.JLabel lblHomePage;
    private javax.swing.JLabel lblNome;
    private javax.swing.JLabel lblTelefone;
    private javax.swing.JPanel painel;
    private javax.swing.JTextField txtApelido;
    private javax.swing.JTextField txtBairro;
    private javax.swing.JTextField txtCep;
    private javax.swing.JTextField txtCidade;
    private javax.swing.JTextField txtEmailGeral;
    private javax.swing.JTextField txtEndereco;
    private javax.swing.JTextField txtFax;
    private javax.swing.JTextField txtHomePage;
    private javax.swing.JTextField txtIrPara;
    private javax.swing.JTextField txtNome;
    private javax.swing.JTextField txtPosicaoLista;
    private javax.swing.JTextField txtTelefone;
    private javax.swing.JTextField txtUF;
    // End of variables declaration

}

Alguma idéia?

PS.: Olhem post acima!

Apenas deixando o post na primeira pagina, para se alguem tiver uma idéia!

vlw! :wink: