Sei sulla pagina 1di 1

package num;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Num extends JFrame implements ActionListener{
//extends: hereda Jfram hacia la clase area
JLabel etiqueta;
JTextArea txtlista;
JButton btnReportar;
public Num(){
setLayout(null);
etiqueta=new JLabel ("Numeros");
etiqueta.setBounds (20,30,50,30);
add (etiqueta);
txtlista =new JTextArea();
txtlista.setBounds (100,30,100,50);
add(txtlista);
btnReportar = new JButton("Reportar:");
btnReportar.setBounds(50,180,100,30);
btnReportar.addActionListener(this);
add(btnReportar);
}
public void ActionPerformed (ActionEvent e){
int Numeros[] =new int[7];
if (e.getSource()==btnReportar){
for(int i = 0; i<7; i++){
Numeros [i]=i+1;
txtlista.append(Integer.toString(Numeros[i]));
}
for (int i=0; i<Numeros.length;i++){
JOptionPane.showMessageDialog(null,Numeros[i]);
}
}
}
public static void main (String[] args) {
Num a=new Num();
a.setTitle ("Vectores: Almacena y reporta");
a.setBounds(10,20,400,400);
a.setVisible(true);
}
//ejecucin de la lgica:
public void actionPerformed (ActionEvent e){
int Numeros[] =new int[7];
if (e.getSource()==btnReportar){
for(int i = 0; i<7; i++){
Numeros [i]=i*i;
txtlista.append(Integer.toString(Numeros[i]));
}
for (int i=0; i<Numeros.length;i++){
JOptionPane.showMessageDialog(null,Numeros[i]);
}
}
}
}

Potrebbero piacerti anche