Advertisement
Guest User

Untitled

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