ola…
ok…
esta é a classe Aluno()
[code]public class Aluno {
private String nome, cpf;
private int idade, matricula;
private boolean status=true;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public int getMatricula() {
return matricula;
}
public void setMatricula(int matricula) {
this.matricula = matricula;
}
[/code]
a mesma coisa para getCpf(), setCpf(), getIdade(), getStatus() e setStatus() - Status é se o aluno estuda ou nao estuda mais na escola
no setIdade fiz um teste p ver se a idade é maior q 0.
public void setIdade(int idade) {
if(idade>0) this.idade = idade;
else System.out.println("ERRO! Idade Inválida!");
}
Agora a main
[code]public static void main(String[] args) {
JRadioButton rb0, rb1, rb2, rb3, rb4, rb5;
rb0 = new JRadioButton(“Sair”, true);
rb1 = new JRadioButton(“Matricular”, false);
rb2 = new JRadioButton(“Listar”, false);
rb3 = new JRadioButton(“Excluir”, false);
rb4 = new JRadioButton(“Alterar”, false);
rb5 = new JRadioButton(“Consultar”, false);
rb0.setActionCommand(“0”);
rb1.setActionCommand(“1”);
rb2.setActionCommand(“2”);
rb3.setActionCommand(“3”);
rb4.setActionCommand(“4”);
rb5.setActionCommand(“5”);
JPanel p3 = new JPanel(new GridLayout(4,2,10,1));
p3.add(rb0);
p3.add(rb1);
p3.add(rb2);
p3.add(rb3);
p3.add(rb4);
p3.add(rb5);
JButton ok = new JButton(“OK”);
p3.add(ok);
JPanel p1 = new JPanel(new GridLayout(1,2));
princ.removeAll();
p1.removeAll();
p1.add(p2);
p1.add(p3);
princ.add(p1);
j.getContentPane().add(princ);
j.setVisible(true);
ButtonGroup grupo = new ButtonGroup();
grupo.add(rb0);
grupo.add(rb1);
grupo.add(rb2);
grupo.add(rb3);
grupo.add(rb4);
grupo.add(rb5);
JFrame j3 = new JFrame(“Executando…”);
j3.setSize(690,240);
j3.setLocation(195,195);
JPanel p10 = new JPanel();
JPanel princ2 = new JPanel(new GridLayout(2,1));
JPanel ll = new JPanel();
JFrame j2 = new JFrame(“Confimação”);
j2.setSize(200,150);
j2.setLocation(400,250);
ok.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
switch(Integer.parseInt(grupo.getSelection().getActionCommand())){
case 0:
System.exit(0);
break;
case 1:
p10.removeAll();
ll.removeAll();
princ2.removeAll();
a = new Aluno();
JLabel l1 = new JLabel("Entre com o Nome do Aluno: ");
JLabel l2 = new JLabel("Entre com a Idade do Aluno: ");
JLabel l3 = new JLabel("Entre com o CPF do Aluno: ");
JLabel l4 = new JTextField(30);
JLabel l5 = new JTextField(“1”,5);
JLabel l6 = new JTextField(20);
p4.removeAll();
p5.removeAll();
p4.add(l1);
p4.add(l2);
p4.add(l3);
p5.add(l4);
p5.add(l5);
p5.add(l6);
p10.add(p4);
p10.add(p5);
princ2.add(p10);
JButton matr = new JButton(“Matricular”);
ll.add(matr);
princ2.add(ll);
j3.getContentPane().add(princ2);
j3.setVisible(true);
matr.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
a.setNome(l4.getText());
a.setIdade(Integer.parseInt(l5.getText()));
a.setCpf(l6.getText());
a.setMatricula(vAlunos.size());
vAlunos.addElement(a);
JLabel con = new JLabel("Guardado com Sucesso!!");
JLabel con1 = new JLabel("Seu número de Matrícula é: "+String.valueOf(a.getMatricula()));
JButton bo = new JButton("OK");
JPanel la = new JPanel();
la.add(con);
la.add(con1);
la.add(bo);
j2.add(la);
j2.setVisible(true);
bo.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
j2.dispose();
j3.dispose();
}
});
}
});
break;}
}
});
[/code]
pronto… esta meio bagunçado mais axo que da pra entender…
repetindo… o Frame j2 imprime sempre matricula 0. pq?