OBS - Todos os códigos JFrame, estão esquisitos pois copio uma coisa e ele cola outra. Os códigos JFrame são bem menores do que apareceram aqui no fórum, acho que tem fantasma no meu código. rsrsrs
Classe Aluno
[code]public class Aluno {
private String nome;
private String curso;
private long matricula;
private Endereco endereco;
public Aluno(){}
public Aluno(String n, String c, long m, Endereco e){
nome = n;
curso = c;
matricula = m;
endereco = e;
}
public String toString(){
String aux = "";
if (endereco != null){
aux = endereco.toString();
}
return nome + curso + matricula + aux;
}
public String getCurso() {
return curso;
}
public void setCurso(String curso) {
this.curso = curso;
}
public long getMatricula() {
return matricula;
}
public void setMatricula(long matricula) {
this.matricula = matricula;
}
public String getNome() {
return nome;
}
public Endereco getEndereco() {
return endereco;
}
public void setEndereco(Endereco endereco) {
this.endereco = endereco;
}
public void setNome(String nome) {
this.nome = nome;
}
}[/code]
Classe Endereço
[code]public class Endereco {
private String logradouro;
private String complemento;
private String cidade;
public Endereco(){}
public Endereco(String l, String c, String ci){
logradouro = l;
complemento = c;
cidade = ci;
}
public String getComplento(){
return complemento;
}
public void setComplemento(String c){
complemento = c;
}
public String getCidade() {
return cidade;
}
public void setCidade(String cidade) {
this.cidade = cidade;
}
public String getLogradouro() {
return logradouro;
}
public void setLogradouro(String logradouro) {
this.logradouro = logradouro;
}
}[/code]
Classe CadAluno, JFrame
[code]public class CadAluno extends javax.swing.JFrame {
public CadAluno(Lista<Aluno> listaAlunos) {
initComponents();
this.listaAlunos = listaAlunos;
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
txtNome = new javax.swing.JTextField();
txtMatricula = new javax.swing.JTextField();
cmbCurso = new javax.swing.JComboBox();
jPanel1 = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
txtLogradouro = new javax.swing.JTextField();
txtComplemento = new javax.swing.JTextField();
cmbCidade = new javax.swing.JComboBox();
btOk = new javax.swing.JButton();
btCancelar = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Cadastro Aluno");
jLabel1.setText("Nome:");
jLabel2.setText("Curso");
jLabel3.setText("Matrícula:");
txtNome.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtNomeActionPerformed(evt);
}
});
cmbCurso.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Administração", "Informática", "Direito" }));
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Endereço"));
jLabel4.setText("Logradouro");
jLabel5.setText("Complemento");
jLabel6.setText("Cidade");
cmbCidade.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Porto Alegre", "São Paulo", "Rio de Janeiro" }));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(jLabel6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(cmbCidade, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtComplemento)
.addComponent(txtLogradouro, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE))
.addContainerGap(222, javax.swing.GroupLayout.PREFERRED_SIZE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(txtLogradouro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(txtComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(cmbCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(31, Short.MAX_VALUE))
);
btOk.setText("OK");
btOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btOkActionPerformed(evt);
}
});
btCancelar.setText("Cancelar");
btCancelar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btCancelarActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(33, 33, 33)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txtMatricula, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(txtNome, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE))
.addGap(17, 17, 17)
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(cmbCurso, 0, 192, Short.MAX_VALUE)))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(341, Short.MAX_VALUE)
.addComponent(btOk)
.addGap(27, 27, 27)
.addComponent(btCancelar)
.addGap(45, 45, 45))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(44, 44, 44)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(19, 19, 19)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jLabel2)
.addComponent(txtMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cmbCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(40, 40, 40)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btCancelar)
.addComponent(btOk))
.addContainerGap(34, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void txtNomeActionPerformed(java.awt.event.ActionEvent evt) {
}
private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}
private void btOkActionPerformed(java.awt.event.ActionEvent evt) {
String nome = txtNome.getText();
long matricula = Long.parseLong(txtMatricula.getText());
String curso = cmbCurso.getSelectedItem().toString();
String logradouro = txtLogradouro.getText();
String complemento = txtComplemento.getText();
String cidade = cmbCidade.getSelectedItem().toString();
Endereco ed = new Endereco(logradouro, complemento, cidade);
Aluno alu = new Aluno(nome, curso, matricula, ed);
listaAlunos.adicionar(alu);
if(listaAlunos.adicionar(alu) == true)
JOptionPane.showMessageDialog(null, "Adicionou a Lista");
else
JOptionPane.showMessageDialog(null, "Não Adicionou");
}
// Variables declaration - do not modify
private javax.swing.JButton btCancelar;
private javax.swing.JButton btOk;
private javax.swing.JComboBox cmbCidade;
private javax.swing.JComboBox cmbCurso;
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.JPanel jPanel1;
private javax.swing.JTextField txtComplemento;
private javax.swing.JTextField txtLogradouro;
private javax.swing.JTextField txtMatricula;
private javax.swing.JTextField txtNome;
// End of variables declaration
private Lista<Aluno> listaAlunos;
}[/code]
Classe ListAluno
[code]public class ListAluno extends javax.swing.JFrame {
/** Creates new form ListAlunos */
public ListAluno(Lista<Aluno> listaAlunos){
initComponents();
this.listaAlunos = listaAlunos;
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
txtNome = new javax.swing.JTextField();
txtMatricula = new javax.swing.JTextField();
cmbCurso = new javax.swing.JComboBox();
jPanel1 = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
txtLogradouro = new javax.swing.JTextField();
txtComplemento = new javax.swing.JTextField();
cmbCidade = new javax.swing.JComboBox();
btPrimeiro = new javax.swing.JButton();
btAnterior = new javax.swing.JButton();
btUltimo = new javax.swing.JButton();
btProximo = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Lista de Alunos");
jLabel1.setText("Nome:");
jLabel2.setText("Curso:");
jLabel3.setText("Matrícula");
cmbCurso.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Administração", "Informática", "Direito" }));
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Endereço"));
jLabel4.setText("Logradouro");
jLabel5.setText("Complemento");
jLabel6.setText("Cidade");
cmbCidade.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Porto Alegre", "São Paulo", "Rio de Janeiro" }));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(jLabel6))
.addGap(22, 22, 22)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(cmbCidade, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtComplemento)
.addComponent(txtLogradouro, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE))
.addContainerGap(118, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(txtLogradouro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(txtComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(cmbCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
btPrimeiro.setText("|<");
btPrimeiro.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btPrimeiroActionPerformed(evt);
}
});
btAnterior.setText("<");
btAnterior.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btAnteriorActionPerformed(evt);
}
});
btUltimo.setText(">|");
btUltimo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btUltimoActionPerformed(evt);
}
});
btProximo.setText(">");
btProximo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btProximoActionPerformed(evt);
}
});
jButton5.setText("Fechar");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(btPrimeiro, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(btAnterior, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(btProximo, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(btUltimo, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 103, Short.MAX_VALUE)
.addComponent(jButton5))
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(31, 31, 31)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmbCurso, 0, 183, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(27, 27, 27)
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(34, 34, 34)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(txtMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(cmbCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(43, 43, 43)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btPrimeiro, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE)
.addComponent(btAnterior, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE)
.addComponent(btProximo, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE)
.addComponent(btUltimo, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE)))
.addContainerGap())
);
pack();
}// </editor-fold>
private void btAnteriorActionPerformed(java.awt.event.ActionEvent evt) {
i--;
if(i<0)
i=listaAlunos.totalizar()-1;
if (i >= 0 && i - 1 < listaAlunos.totalizar())
mostraDados(i);
}
private void btUltimoActionPerformed(java.awt.event.ActionEvent evt) {
i = listaAlunos.totalizar() - 1;
mostraDados(i);
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void btPrimeiroActionPerformed(java.awt.event.ActionEvent evt) {
mostraDados(0);
}
private void btProximoActionPerformed(java.awt.event.ActionEvent evt) {
i++;
if (i>=listaAlunos.totalizar())
i=0;
if (i >= 0 && i - i< listaAlunos.totalizar())
mostraDados(i);
}
public void mostraDados(int posicao){
Aluno alu = listaAlunos.get(posicao);
txtNome.setText(alu.getNome());
txtMatricula.setText(String.valueOf(alu.getMatricula()));
cmbCurso.setSelectedItem(alu.getCurso());
txtLogradouro.setText(alu.getEndereco().getLogradouro());
txtComplemento.setText(alu.getEndereco().getComplento());
cmbCidade.setSelectedItem(alu.getEndereco().getCidade());
}
// Variables declaration - do not modify
private javax.swing.JButton btAnterior;
private javax.swing.JButton btPrimeiro;
private javax.swing.JButton btProximo;
private javax.swing.JButton btUltimo;
private javax.swing.JComboBox cmbCidade;
private javax.swing.JComboBox cmbCurso;
private javax.swing.JButton jButton5;
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.JPanel jPanel1;
private javax.swing.JTextField txtComplemento;
private javax.swing.JTextField txtLogradouro;
private javax.swing.JTextField txtMatricula;
private javax.swing.JTextField txtNome;
// End of variables declaration
private Lista<Aluno> listaAlunos;
private int i;
}[/code]
Classe MenuPrincipal, JFrame
[code]public class MenuPrincipal extends javax.swing.JFrame {
/** Creates new form MenuPrincipal */
public MenuPrincipal() {
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() {
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem3 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Menu Principal");
jMenu1.setText("Arquivo");
jMenuItem3.setText("Sair");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem3ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem3);
jMenuBar1.add(jMenu1);
jMenu2.setText("Operações");
jMenuItem1.setText("Cadastro de Alunos");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem1);
jMenuItem2.setText("Lista de Alunos");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem2);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 411, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
new CadAluno(listaAlunos).setVisible(true);
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
new ListAluno(listaAlunos).setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MenuPrincipal().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
// End of variables declaration
private Lista<Aluno> listaAlunos = new Lista<Aluno>();
}[/code]
Interface Operações Lista
public interface OperacoesLista<E> {
public boolean adicionar(E obj);
public String toString();
public int totalizar();
public E get(int indice);
}
Classe Lista
[code]public class Lista implements OperacoesLista {
private LinkedList<E> lista;
public Lista(){
lista = new LinkedList<E>();
}
public boolean adicionar(E obj) {
return lista.add(obj);
}
public int totalizar() {
return lista.size();
}
public E get(int indice) {
return lista.get(indice);
}
public String toString(){
String aux = "";
for (E obj : lista) {
aux = aux + obj.toString();
}
return aux;
}
}[/code]