package escola;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
* @author 210259
*/
public class TelaCadastro extends JInternalFrame {
JLabel lblMatricula, lblNome, lblNota1, lblNota2, lblNota3, lblNota4, txtMedia, txtResultado, lblMedia, lblResultado, lblNotas, lblNumAlun, lblNumAl, lblBusca;
JTextField txtMatricula, txtNome, txtNota1, txtNota2, txtNota3, txtNota4, txtBusca;
JPanel pnPrincipal, pnNota, pnBusca;
JButton bttOK, bttLIMPAR, bttFIM, bttANT, bttBusca;
String [] nome= new String [40];
String [] resultado= new String [40];
Double [] Media= new Double [40];
Double [] Nota1= new Double [40];
Double [] Nota2= new Double [40];
Double [] Nota3= new Double [40];
Double [] Nota4= new Double [40];
String [] Matricula= new String [40];
int j,i,k=0, b=0, t=0;
public TelaCadastro() {
setTitle("Cadastro Aluno");
setBounds(100, 100, 400, 300);
setVisible(true);
i=0;
txtBusca= new JTextField();
lblBusca= new JLabel("Buscar");
pnBusca= new JPanel();
lblMatricula = new JLabel("Matricula:");
lblNome = new JLabel("Nome:");
lblNota1 = new JLabel("1º Bimestre");
lblNota2 = new JLabel("2º Bimestre");
lblNota3 = new JLabel("3º Bimestre");
lblNota4 = new JLabel("4º Bimestre");
lblNotas = new JLabel("Nota:");
lblMedia = new JLabel("Média:");
lblResultado = new JLabel("Resultado:");
lblNumAlun = new JLabel("Aluno nº:");
lblNumAl = new JLabel("1");
txtMatricula = new JTextField();
txtNome = new JTextField();
txtNota1 = new JTextField();
txtNota2 = new JTextField();
txtNota3 = new JTextField();
txtNota4 = new JTextField();
txtMedia = new JLabel();
txtResultado = new JLabel();
pnPrincipal = new JPanel();
pnNota = new JPanel();
bttOK = new JButton("OK");
bttOK.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(i<40){
Matricula[i]=txtMatricula.getText();
nome[i]=txtNome.getText();
Nota1[i]=Double.parseDouble(txtNota1.getText());
Nota2[i]=Double.parseDouble(txtNota2.getText());
Nota3[i]=Double.parseDouble(txtNota3.getText());
Nota4[i]=Double.parseDouble(txtNota4.getText());
txtMedia.setText(String.valueOf((Nota1[i]+Nota2[i]+Nota3[i]+Nota4[i])/4));
Media[i]=Double.parseDouble(txtMedia.getText());
if(Media[i]>=7.0){
txtResultado.setText("APROVADO");
}
if((Media[i]>=3.5)&&(Media[i]<7.0)){
txtResultado.setText("RECUPERAÇÃO");
}
if(Media[i]<3.5){
txtResultado.setText("REPROVADO");
}
resultado[i]=txtResultado.getText();
i=i+1;
j=i;
}else{
JOptionPane.showMessageDialog(null,"Impossivel processar dados, número máximo alcançado!","Erro",1);
}
}
});
bttLIMPAR = new JButton("Próximo >>");
bttLIMPAR.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(k==j&&k<i-1){
j=j+1;
lblNumAl.setText(String.valueOf(j+1));
j=j-1;
txtMatricula.setText(String.valueOf(Matricula[j+1]));
txtNome.setText(String.valueOf(nome[j+1]));
txtNota1.setText(String.valueOf(Nota1[j+1]));
txtNota2.setText(String.valueOf(Nota2[j+1]));
txtNota3.setText(String.valueOf(Nota3[j+1]));
txtNota4.setText(String.valueOf(Nota4[j+1]));
txtMedia.setText(String.valueOf(Media[j+1]));
txtResultado.setText(String.valueOf(resultado[j+1]));
j=j+1;
k=j;
}
else if(i<40){
lblNumAl.setText(String.valueOf(i+1));
txtMatricula.setText("");
txtNome.setText("");
txtNota1.setText("");
txtNota2.setText("");
txtNota3.setText("");
txtNota4.setText("");
txtMedia.setText("");
txtResultado.setText("");
}else{
JOptionPane.showMessageDialog(null,"Impossivel armazenar, limite de 40 alunos alcançado!","Erro",1);
}
}
});
bttFIM = new JButton("Finalizar");
bttFIM.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int totap=0;
int totrp = 0;
int totrc = 0;
Double somaap = 0.0;
Double somarp = 0.0;
Double somarc = 0.0;
Double mediaap = 0.0;
Double mediarp = 0.0;
Double mediarc = 0.0;
for(int q=0; q<i+1; q++){
if(resultado[q]=="APROVADO"){
somaap=somaap+Media[q];
totap=totap+1;
}
if(resultado[q]=="RECUPERAÇÃO"){
somarp=somarp+Media[q];
totrp=totrp+1;
}
if(resultado[q]=="REPROVADO"){
somarc=somarc+Media[q];
totrc=totrc+1;
}
}
mediaap = somaap / totap;
mediarp = somarp / totrp;
mediarc = somarc / totrc;
JOptionPane.showMessageDialog(null,"Total de: " +
"\nAprovados: "+totap+
"\nRecuperação: "+totrp+
"\nReprovados: "+totrc+
"\n "+
"\nMédia dos: "+
"\nAprovados: "+mediaap+
"\nRecuperação: "+mediarp+
"\nReprovados: "+mediarc);
}});
bttANT = new JButton("<<Anterior");
bttANT.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(j>0){
lblNumAl.setText(String.valueOf(j));
txtMatricula.setText(String.valueOf(Matricula[j-1]));
txtNome.setText(String.valueOf(nome[j-1]));
txtNota1.setText(String.valueOf(Nota1[j-1]));
txtNota2.setText(String.valueOf(Nota2[j-1]));
txtNota3.setText(String.valueOf(Nota3[j-1]));
txtNota4.setText(String.valueOf(Nota4[j-1]));
txtMedia.setText(String.valueOf(Media[j-1]));
txtResultado.setText(String.valueOf(resultado[j-1]));
j=j-1;
k=j;
}
}});
bttBusca= new JButton("Ir");
bttBusca.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(b<i){
t=Integer.parseInt(txtBusca.getText());
b=t;
lblNumAl.setText(String.valueOf(b));
txtMatricula.setText(String.valueOf(Matricula[b-1]));
txtNome.setText(String.valueOf(nome[b-1]));
txtNota1.setText(String.valueOf(Nota1[b-1]));
txtNota2.setText(String.valueOf(Nota2[b-1]));
txtNota3.setText(String.valueOf(Nota3[b-1]));
txtNota4.setText(String.valueOf(Nota4[b-1]));
txtMedia.setText(String.valueOf(Media[b-1]));
txtResultado.setText(String.valueOf(resultado[b-1]));
}else { JOptionPane.showMessageDialog(null,"Campo vazio!","Erro",0);
txtBusca.setText("");}
}});
pnBusca.setLayout(new GridLayout(1,2));
pnBusca.add(txtBusca);
pnBusca.add(bttBusca);
pnNota.setLayout(new GridLayout(2,4));
pnNota.add(lblNota1);
pnNota.add(lblNota2);
pnNota.add(lblNota3);
pnNota.add(lblNota4);
pnNota.add(txtNota1);
pnNota.add(txtNota2);
pnNota.add(txtNota3);
pnNota.add(txtNota4);
pnPrincipal.setLayout(new GridLayout(9, 2));
pnPrincipal.add(lblNumAlun);
pnPrincipal.add(lblNumAl);
pnPrincipal.add(lblMatricula);
pnPrincipal.add(txtMatricula);
pnPrincipal.add(lblNome);
pnPrincipal.add(txtNome);
pnPrincipal.add(lblNotas);
pnPrincipal.add(pnNota);
pnPrincipal.add(lblMedia);
pnPrincipal.add(txtMedia);
pnPrincipal.add(lblResultado);
pnPrincipal.add(txtResultado);
pnPrincipal.add(bttOK);
pnPrincipal.add(bttLIMPAR);
pnPrincipal.add(bttFIM);
pnPrincipal.add(bttANT);
pnPrincipal.add(lblBusca);
pnPrincipal.add(pnBusca);
add(pnPrincipal);
setClosable(true);
}
}
Obrigado desde já :D
)