Pessoal o código tá meio seboso mas dá pra entender né?
Esses botões que fiz até funciona só que quando vou pro ultimo inserido no array e clico no anterior ele diz que não há anterior, portanto esse botão anterior só tá servindo quando uso primeiro o botão último, que vai direto pra última posição do arraylist, bem olha se vcs entende rs.
Obs:Aliás há mais erros as vezes funfa as vezes não, o problema são as váriáveis?
Código completo da janela cadastrar cliente:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Clientes.java
*
* Created on 03/12/2009, 10:24:51
*/
package GUI;
import Objeto.Cliente;
import Objeto.Endereco;
import Operações.*;
import javax.swing.JOptionPane;
/**
*
* @author ESTUDAR
*/
public class Clientes extends javax.swing.JFrame {
Endereco b=new Endereco();
AcmeVideo y=new AcmeVideo();
int contCli=0;
int pri=0;
/** Creates new form Clientes */
public Clientes() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
IDTitCli = new javax.swing.JLabel();
IDCliente = new javax.swing.JLabel();
buttonCadCli = new javax.swing.JButton();
buttonSairCli = new javax.swing.JButton();
separadorCli = new javax.swing.JSeparator();
jLabel3 = new javax.swing.JLabel();
labelRua = new javax.swing.JLabel();
labelBairro = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
textNomeCli = new javax.swing.JTextField();
textCPF = new javax.swing.JTextField();
textRua = new javax.swing.JTextField();
textBairro = new javax.swing.JTextField();
textTel = new javax.swing.JTextField();
textNro = new javax.swing.JTextField();
buttonProx = new javax.swing.JButton();
buttonPri = new javax.swing.JButton();
buttonAnt = new javax.swing.JButton();
buttonUlt = new javax.swing.JButton();
buttonNovo = new javax.swing.JButton();
logo = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
buttonExcluir = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
setTitle("ACME-Cadastros de Clientes");
jLabel1.setText("Nome:");
jLabel2.setText("CPF:");
IDTitCli.setText("ID");
IDCliente.setBorder(javax.swing.BorderFactory.createEtchedBorder());
buttonCadCli.setIcon(new javax.swing.ImageIcon("C:\Meus Programas Java\ACMEGeorge\ico\disc.png")); // NOI18N
buttonCadCli.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonCadCliActionPerformed(evt);
}
});
buttonSairCli.setIcon(new javax.swing.ImageIcon("C:\Meus Programas Java\ACMEGeorge\ico\sair.png")); // NOI18N
buttonSairCli.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonSairCliActionPerformed(evt);
}
});
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
jLabel3.setText("Endereço");
labelRua.setText("Rua:");
labelBairro.setText("Bairro:");
jLabel4.setText("Tel:");
jLabel5.setText("Nº:");
buttonProx.setIcon(new javax.swing.ImageIcon("C:\Meus Programas Java\ACMEGeorge\ico\arrow_up.png")); // NOI18N
buttonProx.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonProxActionPerformed(evt);
}
});
buttonPri.setIcon(new javax.swing.ImageIcon("C:\Meus Programas Java\ACMEGeorge\ico\arrow_left.png")); // NOI18N
buttonPri.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonPriActionPerformed(evt);
}
});
buttonAnt.setIcon(new javax.swing.ImageIcon("C:\Meus Programas Java\ACMEGeorge\ico\arrow_down.png")); // NOI18N
buttonAnt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonAntActionPerformed(evt);
}
});
buttonUlt.setIcon(new javax.swing.ImageIcon("C:\Meus Programas Java\ACMEGeorge\ico\arrow_right.png")); // NOI18N
buttonUlt.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonUltActionPerformed(evt);
}
});
buttonNovo.setIcon(new javax.swing.ImageIcon("C:\Meus Programas Java\ACMEGeorge\ico\file.png")); // NOI18N
buttonNovo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonNovoActionPerformed(evt);
}
});
logo.setIcon(new javax.swing.ImageIcon("C:\Meus Programas Java\ACMEGeorge\ico\macaco.png")); // NOI18N
jLabel6.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
jLabel6.setForeground(new java.awt.Color(102, 0, 0));
jLabel6.setText("Macaco Não Olha o Rabo - Alugue na Acme!");
buttonExcluir.setIcon(new javax.swing.ImageIcon("C:\Meus Programas Java\ACMEGeorge\ico\trash.png")); // NOI18N
buttonExcluir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonExcluirActionPerformed(evt);
}
});
jButton1.setIcon(new javax.swing.ImageIcon("C:\Meus Programas Java\ACMEGeorge\ico\user_edit.png")); // NOI18N
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(logo)
.add(18, 18, 18)
.add(jLabel6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 369, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jLabel3)
.add(18, 18, 18)
.add(separadorCli, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 530, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(labelBairro)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(labelRua)
.add(textRua, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
.add(textBairro, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 400, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel5)
.add(jLabel4)
.add(textTel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(textNro, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(textNomeCli, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 400, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel1))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel2)
.add(textCPF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
.add(96, 96, 96))
.add(layout.createSequentialGroup()
.add(147, 147, 147)
.add(buttonPri, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 71, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(18, 18, 18)
.add(buttonAnt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 71, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(18, 18, 18)
.add(buttonProx, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 71, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(18, 18, 18)
.add(buttonUlt, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 71, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(227, Short.MAX_VALUE))
.add(layout.createSequentialGroup()
.addContainerGap()
.add(IDTitCli)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(IDCliente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 61, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 88, Short.MAX_VALUE)
.add(buttonNovo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 71, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(18, 18, 18)
.add(buttonCadCli, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 71, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(20, 20, 20)
.add(buttonExcluir, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 71, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(18, 18, 18)
.add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 71, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(18, 18, 18)
.add(buttonSairCli, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 71, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(107, 107, 107))
);
layout.linkSize(new java.awt.Component[] {buttonAnt, buttonCadCli, buttonExcluir, buttonNovo, buttonPri, buttonProx, buttonSairCli, buttonUlt}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(logo)
.add(jLabel6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 35, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 56, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(IDTitCli)
.add(IDCliente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(buttonNovo)
.add(buttonCadCli))
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(buttonExcluir)
.add(jButton1)
.add(buttonSairCli)))
.add(26, 26, 26)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1)
.add(jLabel2))
.add(20, 20, 20)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(textNomeCli, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(textCPF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(1, 1, 1)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(32, 32, 32)
.add(separadorCli, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(18, 18, 18)
.add(jLabel3)))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
.add(layout.createSequentialGroup()
.add(labelRua)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(textRua, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(15, 15, 15)
.add(labelBairro)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(textBairro, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(jLabel5)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(textNro, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jLabel4)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(textTel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(32, 32, 32)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(buttonPri)
.add(buttonAnt)
.add(buttonProx))
.add(org.jdesktop.layout.GroupLayout.TRAILING, buttonUlt))
.add(21, 21, 21))
);
layout.linkSize(new java.awt.Component[] {buttonAnt, buttonCadCli, buttonExcluir, buttonNovo, buttonPri, buttonProx, buttonSairCli, buttonUlt}, org.jdesktop.layout.GroupLayout.VERTICAL);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-640)/2, (screenSize.height-460)/2, 640, 460);
}// </editor-fold>
[b]private void buttonCadCliActionPerformed(java.awt.event.ActionEvent evt) {
Cliente a=new Cliente();
contCli++;
int id=a.getIdCliente();
IDCliente.setText(""+id);
String nome=textNomeCli.getText();
a.setNome(nome);
String cpf=textCPF.getText();
a.setCpf(cpf);
String rua=textRua.getText();
b.setRua(rua);
String bairro=textBairro.getText();
b.setBairro(bairro);
String nro=textNro.getText();
b.setNumero(nro);
String tel=textTel.getText();
b.setTelefone(tel);
y.cadastrar(a);
}
private void buttonSairCliActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void buttonProxActionPerformed(java.awt.event.ActionEvent evt) {
/*ok*/
try{
if(pri<y.getClientes().size()){
++pri;
System.out.println(""+y.getClientes().size()+" pri="+pri);
IDCliente.setText(""+y.getClientes().get(pri).getIdCliente());
textNomeCli.setText(""+y.getClientes().get(pri).getNome());
textCPF.setText(""+y.getClientes().get(pri).getCpf());
textRua.setText(""+y.getClientes().get(pri).getEndereco().getRua());
textBairro.setText(""+y.getClientes().get(pri).getEndereco().getBairro());
textNro.setText(""+y.getClientes().get(pri).getEndereco().getBairro());
textTel.setText(""+y.getClientes().get(pri).getEndereco().getTelefone());
}
else
{
JOptionPane.showMessageDialog(null, "Não há posterior!");
}
} catch(Exception e){
}
}
private void buttonUltActionPerformed(java.awt.event.ActionEvent evt) {
try{
int ult=y.getClientes().size()-1;
System.out.println(y.getClientes().size());
System.out.println(y.getClientes().get(ult).getNome());
IDCliente.setText(""+y.getClientes().get(ult).getIdCliente());
textNomeCli.setText(""+y.getClientes().get(ult).getNome());
textCPF.setText(""+y.getClientes().get(ult).getCpf());
textRua.setText(""+y.getClientes().get(ult).getEndereco().getRua());
textBairro.setText(""+y.getClientes().get(ult).getEndereco().getBairro());
textNro.setText(""+y.getClientes().get(ult).getEndereco().getBairro());
textTel.setText(""+y.getClientes().get(ult).getEndereco().getTelefone());
} catch(Exception e){
}
}
private void buttonAntActionPerformed(java.awt.event.ActionEvent evt) {
try{
if(pri<y.getClientes().size() && contCli>0){
--contCli;
System.out.println(""+y.getClientes().size()+" contcli="+contCli);
IDCliente.setText(""+y.getClientes().get(contCli).getIdCliente());
textNomeCli.setText(""+y.getClientes().get(contCli).getNome());
textCPF.setText(""+y.getClientes().get(contCli).getCpf());
textRua.setText(""+y.getClientes().get(contCli).getEndereco().getRua());
textBairro.setText(""+y.getClientes().get(contCli).getEndereco().getBairro());
textNro.setText(""+y.getClientes().get(contCli).getEndereco().getBairro());
textTel.setText(""+y.getClientes().get(contCli).getEndereco().getTelefone());
}
else
if(pri==y.getClientes().size()){
JOptionPane.showMessageDialog(null, "Não há anterior!");
}
} catch(Exception e){
}
}
private void buttonPriActionPerformed(java.awt.event.ActionEvent evt) {
try{
pri=0;
System.out.println(y.getClientes().size());
System.out.println(y.getClientes().get(pri).getNome());
IDCliente.setText(""+y.getClientes().get(pri).getIdCliente());
textNomeCli.setText(""+y.getClientes().get(pri).getNome());
textCPF.setText(""+y.getClientes().get(pri).getCpf());
textRua.setText(""+y.getClientes().get(pri).getEndereco().getRua());
textBairro.setText(""+y.getClientes().get(pri).getEndereco().getBairro());
textNro.setText(""+y.getClientes().get(pri).getEndereco().getBairro());
textTel.setText(""+y.getClientes().get(pri).getEndereco().getTelefone());
} catch(Exception e){
}
}
private void buttonNovoActionPerformed(java.awt.event.ActionEvent evt) {
IDCliente.setText("");
textNomeCli.setText("");
textCPF.setText("");
textRua.setText("");
textBairro.setText("");
textNro.setText("");
textTel.setText("");
textNomeCli.requestFocus();
IDCliente.setEnabled(false);
}
private void buttonExcluirActionPerformed(java.awt.event.ActionEvent evt) {
//?
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
//consulta
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Clientes().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel IDCliente;
private javax.swing.JLabel IDTitCli;
private javax.swing.JButton buttonAnt;
private javax.swing.JButton buttonCadCli;
private javax.swing.JButton buttonExcluir;
private javax.swing.JButton buttonNovo;
private javax.swing.JButton buttonPri;
private javax.swing.JButton buttonProx;
private javax.swing.JButton buttonSairCli;
private javax.swing.JButton buttonUlt;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel labelBairro;
private javax.swing.JLabel labelRua;
private javax.swing.JLabel logo;
private javax.swing.JSeparator separadorCli;
private javax.swing.JTextField textBairro;
private javax.swing.JTextField textCPF;
private javax.swing.JTextField textNomeCli;
private javax.swing.JTextField textNro;
private javax.swing.JTextField textRua;
private javax.swing.JTextField textTel;
// End of variables declaration
}
