Good evening programmers, I have a problem with my code and I do not understand where it is wrong.
I created the following jFrame and the "<" and ">" should, after the registrations have been made, navigate among the registered items. However, only the last and the penultimate values are displayed. Can someone help me?
Part 1:
public class TelaAcessorio extends javax.swing.JFrame {
/**
* Creates new form TelaAcessorio
*/
public TelaAcessorio() {
initComponents();
// desativar botoes
jBAntes.setEnabled(false);
jBNext.setEnabled(false);
}
//intanciação
Acessorio aces = new Acessorio();
// vetor acessorio
Acessorio[] vet = new Acessorio[5];
int i =0;
private void jBGravarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// verifica
if(i<=4){
aces.setCodigo(jTCod.getText());
aces.setDesc(jTDesc.getText());
aces.setPreco(jTPreco.getText());
//add obj no vetor
vet[i]=aces;
i++;
limpar();
}
else{
jBNext.setEnabled(true);
jTCod.setEditable(false);
jTDesc.setEditable(false);
jTPreco.setEditable(false);
jBGravar.setEnabled(false);
i=0;
}
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
TelaPrincipal tela = new TelaPrincipal();
tela.setVisible(true);
this.dispose();
}
private void jBNextActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// if(i==1){
// jBNext.setEnabled(true);
//}
aces = vet[i];
jTCod.setText(aces.getCodigo());
jTDesc.setText(aces.getDesc());
jTPreco.setText(aces.getPreco());
i++;
if(i==5){
i=4;
}
}
private void jBAntesActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(i==3){
jBAntes.setEnabled(true);
}
aces = vet[i];
jTCod.setText(aces.getCodigo());
jTDesc.setText(aces.getDesc());
jTPreco.setText(aces.getPreco());
i--;
if(i==0){
jBAntes.setEnabled(false);
}
}
private void limpar(){
//limpar
jTCod.setText(null);
jTDesc.setText(null);
jTPreco.setText(null);
// foco
jTCod.requestFocus();
}
It's all part of the same class Accessories, I just hacked because of the hidden part of the code that is unnecessary to show here.
I believe that there is an error in logic, I just do not understand which