Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/06/2012, 14:35
yesid_ospina11
 
Fecha de Ingreso: junio-2012
Mensajes: 1
Antigüedad: 11 años, 10 meses
Puntos: 0
Pedir varias veces los datos con JFrame

Hola me gustaria saber como puedo hacer para pedir varias veces los datos al manejar JFrame y que esos datos se guarden en un array de 5 pocisiones para asi despues imprimirlos en un Jtextarea
Comparto el codigo

Gracias



package clases;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Ejercicio2 extends JFrame implements ActionListener {

private JTextField txtMatricula;
private JLabel labMatricula;
private JLabel labNota;
private JTextField txtNota;
private JTextArea respuesta;
private JButton boton;

public Ejercicio2(){
super("Notas alumnos");

Container contenedor = getContentPane();
contenedor.setLayout(new FlowLayout());
labMatricula = new JLabel("Digite la matricula");
txtMatricula = new JTextField(10);
labNota = new JLabel("Digite las notas");
txtNota = new JTextField(10);
boton = new JButton("Aceptar");

respuesta = new JTextArea();
contenedor.add(labMatricula);
contenedor.add(txtMatricula);
contenedor.add(labNota);
contenedor.add(txtNota);
contenedor.add(boton);
boton.addActionListener(this);
contenedor.add(respuesta);

setSize( 300, 400 );
setVisible( true );
}
public void actionPerformed(ActionEvent ae){

String matricula;
double[] arrayNotas = new double[5];
double nota = Double.parseDouble(txtNota.getText());;
double total = 0;

matricula =txtMatricula.getText();
for(int i=0; i<arrayNotas.length; i++){
total = arrayNotas[i] = nota;
}
respuesta.setText("La matricula es: "+ matricula+"\n\n" + "La Nota es: "+ total + "\n");
}
public static void main(String []args){

JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
Ejercicio2 aplicacion = new Ejercicio2();
aplicacion.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}