-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClienteGUI2.java
More file actions
366 lines (303 loc) · 11.8 KB
/
Copy pathClienteGUI2.java
File metadata and controls
366 lines (303 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JOptionPane;
import javax.swing.JComboBox;
import java.awt.GridLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class ClienteGUI2 extends JFrame implements ActionListener
{
private JTextField tfNocta, tfNombre, tfTipo, tfSaldo;
private JButton bCapturar, bConsultar, bSalir, bConsultarClientes, bConsultarNocta;
private JButton bRetiro, bDeposito, bCancelar;
private JButton bConRetL, bConDepL, bConRetTxt, bConDepTxt,bConBajaTxt;
private JButton bAddFirst, bEliminarCliente;
private JPanel panel1, panel2;
private JTextArea taDatos;
private JComboBox comboCuentas;
private String opcionesCuenta[] = {"INVERSION","CREDITO","AHORRO","HIPOTECA"};
//private BancoAD bancoad = new BancoAD();
private BancoADLL bancoad = new BancoADLL();
public ClienteGUI2()
{
super("BANCO VB CITY LL");
// 1. Crear los objetos de los atributos
tfNocta = new JTextField();
tfNombre = new JTextField();
tfTipo = new JTextField();
tfSaldo = new JTextField();
bCapturar = new JButton("Capturar datos (LList)");
bConsultar = new JButton("Consultar Clientes (LList)");
bConsultarNocta = new JButton("Consultar No. Cuenta");
bConsultarClientes = new JButton("Consultar Clientes (Archivo)");
bRetiro = new JButton("Retiro de Cuenta (Arreglo)");
bDeposito = new JButton("Deposito a Cuenta (Arreglo)");
bCancelar = new JButton("Cancelar Transaccion");
bConRetL = new JButton("Consultar Retiros LList");
bConDepL = new JButton("Consultar Depositos LList");
bConRetTxt = new JButton("Consultar Retiros Txt");
bConDepTxt = new JButton("Consultar Depositos Txt");
bAddFirst = new JButton("Add First (LList)");
bEliminarCliente = new JButton("Eliminar Clientes (LList)");
bSalir = new JButton("Exit");
bConBajaTxt = new JButton("Consultar BajaClientes Txt");
panel1 = new JPanel();
panel2 = new JPanel();
taDatos = new JTextArea(10,30);
comboCuentas = new JComboBox(opcionesCuenta);
// Adicionar addActionListener a lo JButtons
bCapturar.addActionListener(this);
bConsultar.addActionListener(this);
bConsultarNocta.addActionListener(this);
bConsultarClientes.addActionListener(this);
bDeposito.addActionListener(this);
bRetiro.addActionListener(this);
bCancelar.addActionListener(this);
bSalir.addActionListener(this);
bConRetL.addActionListener(this);
bConDepL.addActionListener(this);
bConRetTxt.addActionListener(this);
bConDepTxt.addActionListener(this);
bAddFirst.addActionListener(this);
bEliminarCliente.addActionListener(this);
bConBajaTxt.addActionListener(this);
bRetiro.setEnabled(false);
bDeposito.setEnabled(false);
bCancelar.setEnabled(false);
bEliminarCliente.setEnabled(false);
// 2. Definir los Layouts de los JPanels
panel1.setLayout(new GridLayout(12,2));
panel2.setLayout(new FlowLayout());
// 3. Colocar los objetos de los atributos en los JPanels correspondientes
panel1.add(new JLabel("No. DE CUENTA"));
panel1.add(tfNocta);
panel1.add(new JLabel("NOMBRE: "));
panel1.add(tfNombre);
panel1.add(new JLabel("TIPO DE CUENTA"));
//panel1.add(tfTipo);
panel1.add(comboCuentas);
panel1.add(new JLabel("SALDO"));
panel1.add(tfSaldo);
panel1.add(bCapturar);
panel1.add(bConsultar);
panel1.add(bConsultarNocta);
panel1.add(bConsultarClientes);
panel1.add(bRetiro);
panel1.add(bDeposito);
panel1.add(bConRetL);
panel1.add(bConDepL);
panel1.add(bConRetTxt);
panel1.add(bConDepTxt);
panel1.add(bConBajaTxt);
panel1.add(bCancelar);
panel1.add(bAddFirst);
panel1.add(bEliminarCliente);
panel1.add(bSalir);
panel2.add(panel1);
panel2.add(new JScrollPane(taDatos));
// 4. Adicionar el panel2 al JFrame y hacerlo visible
add(panel2);
setSize(500,500);
setVisible(true);
}
private void inactivarBotones()
{
bCapturar.setEnabled(false);
bConsultar.setEnabled(false);
bConsultarNocta.setEnabled(false);
bConsultarClientes.setEnabled(false);
bRetiro.setEnabled(true);
bDeposito.setEnabled(true);
bCancelar.setEnabled(true);
bEliminarCliente.setEnabled(true);
}
private void activarBotones()
{
bCapturar.setEnabled(true);
bConsultar.setEnabled(true);
bConsultarNocta.setEnabled(true);
bConsultarClientes.setEnabled(true);
bRetiro.setEnabled(false);
bDeposito.setEnabled(false);
bCancelar.setEnabled(false);
bEliminarCliente.setEnabled(false);
}
private String obtenerDatos()
{
String datos;
String nocta = tfNocta.getText();
String nombre = tfNombre.getText();
//String tipo = tfTipo.getText();
String tipo = (String)comboCuentas.getSelectedItem();
String saldo = tfSaldo.getText();
if(nocta.equals("") || nombre.isEmpty() || tipo.equals("") || saldo.isEmpty())
datos = "VACIO";
else
{
try
{
int n = Integer.parseInt(saldo);
datos = nocta+"_"+nombre+"_"+tipo+"_"+saldo;
}
catch(NumberFormatException nfe)
{
datos = "NO_NUMERICO";
}
}
return datos;
}
public void actionPerformed(ActionEvent e)
{
String datos, respuesta;
if(e.getSource() == bCapturar)
{
// 1. Obtener datos
datos = obtenerDatos();
// 2. Checar datos: datos no vacios y saldo numerico, y realizar la captura de datos
if(datos.equals("VACIO"))
respuesta = "Algun campo esta vacio...";
else
{
String numBuscar = tfNocta.getText();
int r = 0;
//r = bancoad.funcionComprobacion(numBuscar);
if(r==1)
{
respuesta = "YA EXISTE ESE NUMERO DE CUENTA...";
}
else
{
respuesta = bancoad.capturar(datos);
}
//respuesta = datos;
}
// 3. Desplegar esultado de transaccion
taDatos.setText(respuesta);
}
if(e.getSource() == bConsultar)
{
// 1. Realizar consulta de clientes
datos = bancoad.consultarClientes();
// 2. Desplegar datos
taDatos.setText(datos);
//taDatos.setText("Consultar Clientes ...");
}
if(e.getSource() == bAddFirst)
{
// 1. Obtener datos
datos = obtenerDatos();
// 2. Checar datos: datos no vacios y saldo numerico, y realizar la captura de datos
if(datos.equals("VACIO"))
respuesta = "Algun campo esta vacio...";
else
{
String numBuscar = tfNocta.getText();
int r = 0;
//r = bancoad.funcionComprobacion(numBuscar);
if(r==1)
{
respuesta = "YA EXISTE ESE NUMERO DE CUENTA...";
}
else
{
respuesta = bancoad.addFirst(datos);
}
//respuesta = datos;
}
// 3. Desplegar esultado de transaccion
taDatos.setText(respuesta);
}
if(e.getSource() == bConsultarClientes)
{
// 1. Realizar consulta de clientes en el archivo
datos = bancoad.consultarArchivo("Clientes");
// 2. Desplegar datos
taDatos.setText(datos);
}
if(e.getSource() == bConsultarNocta)
{
// 1. Obtener el no. de cuenta a buscar
String ncta = tfNocta.getText();
// 2. Realizar transaccion de consultar no. de cuenta
respuesta = bancoad.consultarNocta(ncta);
if(respuesta.equals("NOT_FOUND"))
respuesta = "No. de Cuenta no localizado: "+ncta;
else
if(respuesta.equals("EMPTY"))
respuesta = "LISTA VACIA...";
else
inactivarBotones();
// 3. Desplegar resultado de la transaccion
taDatos.setText(respuesta);
}
if(e.getSource() == bCancelar)
{
activarBotones();
}
if(e.getSource() == bEliminarCliente)
{
respuesta = bancoad.eliminarNodoCliente();
taDatos.setText(respuesta);
activarBotones();
}
if(e.getSource() == bRetiro)
{
int cantidad = Integer.parseInt(JOptionPane.showInputDialog("Cantidad a Retirar: "));
//String ncta = tfNocta.getText();
respuesta = bancoad.retiro(cantidad);
activarBotones();
taDatos.setText(respuesta);
}
if(e.getSource() == bDeposito)
{
int cantidad = Integer.parseInt(JOptionPane.showInputDialog("Cantidad a Depositar: "));
String ncta = tfNocta.getText();
respuesta = bancoad.deposito(cantidad);
activarBotones();
taDatos.setText(respuesta);
}
if(e.getSource() == bSalir)
{
bancoad.guardarArchivo();
bancoad.guardarDatosLLRetirosArchRetiros();
bancoad.guardarDatosLLDepositosArchDepositos();
//System.out.println(respuesta);
System.exit(0);
}
if(e.getSource() == bConDepL)
{
respuesta = bancoad.consultarDep();
taDatos.setText(respuesta);
}
if(e.getSource() == bConRetL)
{
respuesta = bancoad.consultarRet();
taDatos.setText(respuesta);
}
if(e.getSource() == bConRetTxt)
{
respuesta = bancoad.consultarArchivo("Retiros");
taDatos.setText(respuesta);
}
if(e.getSource() == bConDepTxt)
{
respuesta = bancoad.consultarArchivo("Depositos");
taDatos.setText(respuesta);
}
if(e.getSource() == bConBajaTxt)
{
respuesta = bancoad.consultarArchivo("BajaClientes");
taDatos.setText(respuesta);
}
}
public static void main(String args[])
{
new ClienteGUI2();
}
}