Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.event.*;
- public class Ventana extends JFrame implements ActionListener {
- Ventana v;
- JLabel lnombre, ldireccion, lcorreo;
- JTextField tfnombre, tfdireccion, tfcorreo;
- JButton botona, botonc, botons;
- JTextArea area;
- JPanel panel;
- String Datos[][];
- String mensaje = "";
- int P = 0;
- public Ventana() {
- lnombre = new JLabel("Nombre");
- lnombre.setBounds(15, 20, 450, 20);
- ldireccion = new JLabel("Direccion");
- ldireccion.setBounds(15, 50, 450, 20);
- lcorreo = new JLabel("Correo");
- lcorreo.setBounds(15, 80, 450, 20);
- tfnombre = new JTextField();
- tfnombre.setBounds(100, 20, 450, 20);
- tfdireccion = new JTextField();
- tfdireccion.setBounds(100, 50, 450, 20);
- tfcorreo = new JTextField();
- tfcorreo.setBounds(100, 80, 450, 20);
- botona = new JButton("Aceptar");
- botona.setBounds(60, 300, 140, 20);
- botona.addActionListener(this);
- botonc = new JButton("Cancelar");
- botonc.setBounds(220, 300, 140, 20);
- botonc.addActionListener(this);
- botons = new JButton("Salir");
- botons.setBounds(380, 300, 140, 20);
- botons.addActionListener(this);
- area = new JTextArea();
- area.setBounds(10, 120, 565, 150);
- panel = new JPanel();
- panel.setLayout(null);
- panel.add(lnombre);
- panel.add(ldireccion);
- panel.add(lcorreo);
- panel.add(tfnombre);
- panel.add(tfdireccion);
- panel.add(tfcorreo);
- panel.add(botona);
- panel.add(botonc);
- panel.add(botons);
- panel.add(area);
- add(panel);
- setSize(600, 380);
- setTitle("Unidad 1");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setVisible(true);
- Datos = new String[5][3];
- }
- public static void main(String[] args) {
- Ventana v = new Ventana();
- }
- public void actionPerformed(ActionEvent e) {
- if (e.getSource() == botona) {
- Capturar();
- P = P + 1;
- }
- if (e.getSource() == botonc) {
- Borrar();
- }
- if (e.getSource() == botons) {
- Salir();
- }
- }
- void Capturar() {
- Guardar();
- Mostrar(Datos);
- // area.setText("Los datos ingresados son: n Nombre : " + tfnombre.getText() + "n
- //Direccion : " + tfdireccion.getText() + "n
- //Correo : " + tfcorreo.getText());
- }
- void Borrar() {
- area.setText("");
- }
- void Salir() {
- super.dispose();
- }
- void Guardar() {
- if (P < 5) {
- Datos[P][0] = tfnombre.getText();
- Datos[P][1] = tfdireccion.getText();
- Datos[P][2] = tfcorreo.getText();
- } else {
- mensaje = "Memoria llena.";
- }
- tfnombre.setText("");
- tfdireccion.setText("");
- tfcorreo.setText("");
- }
- void Mostrar(String[][] a) {
- // if(a[i][j] != "" || a[i][j] !=null);
- area.setText("Nombre: " + a[0][0] + " Direccion: " + a[0][1] + " Correo: " + a[0][2] + "n"
- + "Nombre: " + a[1][0] + " Direccion: " + a[1][1] + " Correo: " + a[1][2] + "n"
- + "Nombre: " + a[2][0] + " Direccion: " + a[2][1] + " Correo: " + a[2][2] + "n"
- + "Nombre: " + a[3][0] + " Direccion: " + a[3][1] + " Correo: " + a[3][2] + "n"
- + "Nombre: " + a[4][0] + " Direccion: " + a[4][1] + " Correo: " + a[4][2] + "n" + mensaje);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement