Advertisement
Guest User

Untitled

a guest
May 4th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.event.*;
  3.  
  4. public class Ventana extends JFrame implements ActionListener {
  5.  
  6. Ventana v;
  7. JLabel lnombre, ldireccion, lcorreo;
  8. JTextField tfnombre, tfdireccion, tfcorreo;
  9. JButton botona, botonc, botons;
  10. JTextArea area;
  11. JPanel panel;
  12. String Datos[][];
  13. String mensaje = "";
  14. int P = 0;
  15.  
  16. public Ventana() {
  17.  
  18. lnombre = new JLabel("Nombre");
  19. lnombre.setBounds(15, 20, 450, 20);
  20.  
  21. ldireccion = new JLabel("Direccion");
  22. ldireccion.setBounds(15, 50, 450, 20);
  23.  
  24. lcorreo = new JLabel("Correo");
  25. lcorreo.setBounds(15, 80, 450, 20);
  26.  
  27. tfnombre = new JTextField();
  28. tfnombre.setBounds(100, 20, 450, 20);
  29.  
  30. tfdireccion = new JTextField();
  31. tfdireccion.setBounds(100, 50, 450, 20);
  32.  
  33. tfcorreo = new JTextField();
  34. tfcorreo.setBounds(100, 80, 450, 20);
  35.  
  36. botona = new JButton("Aceptar");
  37. botona.setBounds(60, 300, 140, 20);
  38. botona.addActionListener(this);
  39.  
  40. botonc = new JButton("Cancelar");
  41. botonc.setBounds(220, 300, 140, 20);
  42. botonc.addActionListener(this);
  43.  
  44. botons = new JButton("Salir");
  45. botons.setBounds(380, 300, 140, 20);
  46. botons.addActionListener(this);
  47.  
  48. area = new JTextArea();
  49. area.setBounds(10, 120, 565, 150);
  50.  
  51. panel = new JPanel();
  52. panel.setLayout(null);
  53.  
  54. panel.add(lnombre);
  55. panel.add(ldireccion);
  56. panel.add(lcorreo);
  57. panel.add(tfnombre);
  58. panel.add(tfdireccion);
  59. panel.add(tfcorreo);
  60. panel.add(botona);
  61. panel.add(botonc);
  62. panel.add(botons);
  63. panel.add(area);
  64.  
  65. add(panel);
  66. setSize(600, 380);
  67. setTitle("Unidad 1");
  68. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  69. setVisible(true);
  70. Datos = new String[5][3];
  71. }
  72.  
  73. public static void main(String[] args) {
  74.  
  75. Ventana v = new Ventana();
  76.  
  77. }
  78.  
  79. public void actionPerformed(ActionEvent e) {
  80.  
  81. if (e.getSource() == botona) {
  82. Capturar();
  83. P = P + 1;
  84. }
  85. if (e.getSource() == botonc) {
  86. Borrar();
  87. }
  88. if (e.getSource() == botons) {
  89. Salir();
  90. }
  91. }
  92.  
  93. void Capturar() {
  94. Guardar();
  95. Mostrar(Datos);
  96. // area.setText("Los datos ingresados son: n Nombre : " + tfnombre.getText() + "n
  97. //Direccion : " + tfdireccion.getText() + "n
  98. //Correo : " + tfcorreo.getText());
  99. }
  100.  
  101. void Borrar() {
  102. area.setText("");
  103. }
  104.  
  105. void Salir() {
  106. super.dispose();
  107. }
  108.  
  109. void Guardar() {
  110. if (P < 5) {
  111. Datos[P][0] = tfnombre.getText();
  112. Datos[P][1] = tfdireccion.getText();
  113. Datos[P][2] = tfcorreo.getText();
  114. } else {
  115. mensaje = "Memoria llena.";
  116. }
  117. tfnombre.setText("");
  118. tfdireccion.setText("");
  119. tfcorreo.setText("");
  120. }
  121.  
  122. void Mostrar(String[][] a) {
  123.  
  124.  
  125. // if(a[i][j] != "" || a[i][j] !=null);
  126. area.setText("Nombre: " + a[0][0] + " Direccion: " + a[0][1] + " Correo: " + a[0][2] + "n"
  127. + "Nombre: " + a[1][0] + " Direccion: " + a[1][1] + " Correo: " + a[1][2] + "n"
  128. + "Nombre: " + a[2][0] + " Direccion: " + a[2][1] + " Correo: " + a[2][2] + "n"
  129. + "Nombre: " + a[3][0] + " Direccion: " + a[3][1] + " Correo: " + a[3][2] + "n"
  130. + "Nombre: " + a[4][0] + " Direccion: " + a[4][1] + " Correo: " + a[4][2] + "n" + mensaje);
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement