@@ -16,12 +16,12 @@ public class BillSearch extends JFrame implements ActionListener {
16
16
RoundedButton buscar ,volver ;
17
17
JComboBox <String > nombre_combo ;
18
18
JPopupMenu nombre_popup ;
19
- Choice ID_choice ,status_choice ,factura_choice ,fecha_choice_mes ,fecha_choice_year ;
19
+ JComboBox ID_choice ,status_choice ,factura_choice ,fecha_choice_mes ,fecha_choice_year ;
20
20
BillSearch (String NIF ,String ID_USER ){
21
21
this .NIF =NIF ;
22
22
this .ID_USER =ID_USER ;
23
23
24
- setContentPane (new BackgroundPanel ("images/Fichas .jpg" ));
24
+ setContentPane (new BackgroundPanel ("images/Fichas3 .jpg" ));
25
25
setLayout (new BorderLayout ());
26
26
Font fuente =new Font ("Roboto" , Font .PLAIN , 20 );
27
27
Font fuente2 =new Font ("Roboto" , Font .PLAIN , 15 );
@@ -127,7 +127,8 @@ public void actionPerformed(ActionEvent e) {
127
127
ex .printStackTrace ();
128
128
}
129
129
if (nombre_popup .getComponentCount () > 0 ) {
130
- nombre_popup .setPreferredSize (new Dimension (227 , nombre_popup .getComponentCount () * 30 ));
130
+ int width = cajon_nombre .getWidth ();
131
+ nombre_popup .setPreferredSize (new Dimension (width , nombre_popup .getComponentCount () * 30 ));
131
132
nombre_popup .show (cajon_nombre , 0 , cajon_nombre .getHeight ());
132
133
} else {
133
134
nombre_popup .setVisible (false );
@@ -144,15 +145,23 @@ public void actionPerformed(ActionEvent e) {
144
145
panel .add (numeroid , gbc );
145
146
146
147
147
- ID_choice = new Choice ();
148
- ID_choice .add ("seleciona ID" );
148
+ ID_choice = new JComboBox ();
149
+ ID_choice .addItem ("seleciona ID" );
149
150
ID_choice .setFont (fuente2 );
150
- ID_choice .setBackground (new Color (70 , 73 , 75 ));
151
- ID_choice .setForeground (new Color (190 , 190 , 190 ));
151
+ ID_choice .setEnabled (false );
152
152
gbc .gridx = 1 ;
153
153
gbc .fill = GridBagConstraints .HORIZONTAL ;
154
154
gbc .weightx = 0 ;
155
- panel .add (ID_choice , gbc );
155
+ panel .add (ID_choice , gbc );
156
+ ID_choice .addItemListener (new ItemListener () {
157
+ @ Override
158
+ public void itemStateChanged (ItemEvent e ) {
159
+ if (e .getStateChange () == ItemEvent .SELECTED ) {
160
+ selectedID =(String ) ID_choice .getSelectedItem ();
161
+ update_factura (selectedID );
162
+ }
163
+ }
164
+ });
156
165
157
166
JLabel nombreusu = new JLabel ("Estado Factura:" );
158
167
gbc .anchor = GridBagConstraints .WEST ;
@@ -162,14 +171,12 @@ public void actionPerformed(ActionEvent e) {
162
171
gbc .gridx = 0 ;
163
172
panel .add (nombreusu , gbc );
164
173
165
- status_choice = new Choice ();
166
- status_choice .add ("Todos" );
167
- status_choice .add ("Pagado" );
168
- status_choice .add ("Pendiente" );
169
- status_choice .add ("Sin enviar" );
174
+ status_choice = new JComboBox ();
175
+ status_choice .addItem ("Todos" );
176
+ status_choice .addItem ("Pagado" );
177
+ status_choice .addItem ("Pendiente" );
178
+ status_choice .addItem ("Sin enviar" );
170
179
status_choice .setFont (fuente2 );
171
- status_choice .setBackground (new Color (70 , 73 , 75 ));
172
- status_choice .setForeground (new Color (190 , 190 , 190 ));
173
180
gbc .gridx = 1 ;
174
181
gbc .fill = GridBagConstraints .HORIZONTAL ;
175
182
gbc .weightx = 0 ;
@@ -195,12 +202,10 @@ public void itemStateChanged(ItemEvent e) {
195
202
JPanel panelfecha = new JPanel (new GridLayout (1 , 2 ));
196
203
panelfecha .setOpaque (false );
197
204
198
- fecha_choice_mes = new Choice ();
205
+ fecha_choice_mes = new JComboBox ();
199
206
for (int i =0 ;i <meses .length ;i ++){
200
- fecha_choice_mes .add (meses [i ]);}
207
+ fecha_choice_mes .addItem (meses [i ]);}
201
208
fecha_choice_mes .setFont (fuente3 );
202
- fecha_choice_mes .setBackground (new Color (70 , 73 , 75 ));
203
- fecha_choice_mes .setForeground (new Color (190 , 190 , 190 ));
204
209
fecha_choice_mes .addItemListener (new ItemListener () {
205
210
@ Override
206
211
public void itemStateChanged (ItemEvent e ) {
@@ -211,15 +216,14 @@ public void itemStateChanged(ItemEvent e) {
211
216
});
212
217
213
218
214
- fecha_choice_year = new Choice ();
215
- fecha_choice_year .add ("Todos Años" );
216
- fecha_choice_year .add ("2025" );
217
- fecha_choice_year .add ("2024" );
218
- fecha_choice_year .add ("2023" );
219
- fecha_choice_year .add ("2022" );
220
- fecha_choice_year .setBackground (new Color (70 , 73 , 75 ));
221
- fecha_choice_year .setForeground (new Color (190 , 190 , 190 ));
222
- fecha_choice_year .setFont (fuente3 );fecha_choice_year .addItemListener (new ItemListener () {
219
+ fecha_choice_year = new JComboBox ();
220
+ fecha_choice_year .addItem ("Todos Años" );
221
+ fecha_choice_year .addItem ("2025" );
222
+ fecha_choice_year .addItem ("2024" );
223
+ fecha_choice_year .addItem ("2023" );
224
+ fecha_choice_year .addItem ("2022" );
225
+ fecha_choice_year .setFont (fuente3 );
226
+ fecha_choice_year .addItemListener (new ItemListener () {
223
227
@ Override
224
228
public void itemStateChanged (ItemEvent e ) {
225
229
if (e .getStateChange () == ItemEvent .SELECTED ) {
@@ -246,10 +250,9 @@ public void itemStateChanged(ItemEvent e) {
246
250
gbc .gridx = 0 ;
247
251
panel .add (nombrecompleto , gbc );
248
252
249
- factura_choice = new Choice ();
253
+ factura_choice = new JComboBox ();
250
254
factura_choice .setFont (fuente3 );
251
- factura_choice .setBackground (new Color (70 , 73 , 75 ));
252
- factura_choice .setForeground (new Color (190 ,190 ,190 ));
255
+ factura_choice .setEnabled (false );
253
256
gbc .gridx = 1 ;
254
257
gbc .fill = GridBagConstraints .HORIZONTAL ;
255
258
gbc .weightx = 0 ;
@@ -289,12 +292,12 @@ public void itemStateChanged(ItemEvent e) {
289
292
}
290
293
291
294
public void updateID_choice (String selectedName ) {
292
- ID_choice .removeAll ();
295
+ ID_choice .removeAllItems ();
293
296
try {
294
297
Connect c = new Connect ();
295
298
ResultSet rs = c .s .executeQuery ("SELECT ID FROM client WHERE NAME='" + selectedName + "' AND NIF='" +NIF +"'" );
296
299
while (rs .next ()) {
297
- ID_choice .add (rs .getString ("ID" ));
300
+ ID_choice .addItem (rs .getString ("ID" ));
298
301
selectedID = rs .getString ("ID" ); // Actualizar selectedID
299
302
}
300
303
rs .close ();
@@ -303,24 +306,26 @@ public void updateID_choice(String selectedName) {
303
306
ex .printStackTrace ();
304
307
}
305
308
if (ID_choice .getItemCount () == 1 ) {
306
- ID_choice .select (0 ); // Seleccionar el único ID
307
- selectedID = ID_choice .getSelectedItem ();
309
+ ID_choice .setSelectedIndex (0 );
310
+ selectedID =( String ) ID_choice .getSelectedItem ();
308
311
update_factura (selectedID );
312
+ ID_choice .setEnabled (false );
309
313
} else if (ID_choice .getItemCount () > 1 ) {
310
- ID_choice .select (0 );
311
- selectedID = ID_choice .getSelectedItem ();
314
+ ID_choice .setSelectedIndex (0 );
315
+ selectedID =( String ) ID_choice .getSelectedItem ();
312
316
update_factura (selectedID );
317
+ ID_choice .setEnabled (true );
313
318
}
314
319
}
315
320
public void update_factura (String selectedID ) {
316
- factura_choice .removeAll ();
321
+ factura_choice .removeAllItems ();
317
322
try {
318
323
Connect c = new Connect ();
319
- String estado =status_choice .getSelectedItem ();
324
+ String estado =( String ) status_choice .getSelectedItem ();
320
325
estado =estado .toLowerCase ().trim ();
321
- String mes_elegido =fecha_choice_mes .getSelectedItem ();
326
+ String mes_elegido =( String ) fecha_choice_mes .getSelectedItem ();
322
327
mes_elegido =mes_elegido .toLowerCase ().trim ();
323
- String year_elegido =fecha_choice_year .getSelectedItem ();
328
+ String year_elegido =( String ) fecha_choice_year .getSelectedItem ();
324
329
String query2 ="" ;
325
330
if (!estado .equals ("todos" )){
326
331
query2 =" AND STATUS='" +estado +"'" ;
@@ -352,22 +357,24 @@ public void update_factura(String selectedID) {
352
357
c .s .executeUpdate ("SET lc_time_names = 'es_ES'" );
353
358
ResultSet rs = c .s .executeQuery (query );
354
359
if (!rs .next ()){
355
- factura_choice .add ("Sin registros" );
360
+ factura_choice .addItem ("Sin registros" );
361
+ factura_choice .setEnabled (false );
356
362
}else
357
363
do {
358
364
String numberfactura = rs .getString ("NUMBER_FACTURA" );
359
365
String materialDate = rs .getString ("MES" );
360
366
String ano = rs .getString ("ANO" );
361
367
String state = rs .getString ("STATUS" );
362
- factura_choice .add ("Factura " + numberfactura +", " + materialDate + " de " + ano +", " +state );
368
+ factura_choice .addItem ("Factura " + numberfactura +", " + materialDate + " de " + ano +", " +state );
369
+ factura_choice .setEnabled (true );
363
370
364
371
} while (rs .next ());
365
372
rs .close ();
366
373
c .s .close ();
367
374
368
375
} catch (Exception ex ) {
369
376
ex .printStackTrace ();
370
- factura_choice .add ("Sin registros" );
377
+ factura_choice .addItem ("Sin registros" );
371
378
}
372
379
}
373
380
@@ -377,12 +384,13 @@ public void actionPerformed(ActionEvent ae){
377
384
return ;
378
385
}
379
386
String NAME =cajon_nombre .getText ();
380
- String ID_CLIENT =ID_choice .getSelectedItem ();
381
- String STATUS =status_choice .getSelectedItem ().toLowerCase ();
387
+ String ID_CLIENT =(String ) ID_choice .getSelectedItem ();
388
+ String STATUS =(String ) status_choice .getSelectedItem ();
389
+ STATUS = STATUS .toLowerCase ();
382
390
String ADDRESS = "" , HOUR = "" , DATE = "" , NUMBER_MATERIAL = "" , TOTAL_MATERIAL = "" , PARAMETROS = "" , TOTAL_BILL = "" ;
383
- String NUMBER_FACTURA =factura_choice .getSelectedItem ();
391
+ String NUMBER_FACTURA =( String ) factura_choice .getSelectedItem ();
384
392
NUMBER_FACTURA =NUMBER_FACTURA .substring (NUMBER_FACTURA .indexOf (" " )+1 , NUMBER_FACTURA .indexOf ("," ));
385
- String factura_sinregistro =factura_choice .getSelectedItem ();
393
+ String factura_sinregistro =( String ) factura_choice .getSelectedItem ();
386
394
387
395
if (!factura_sinregistro .equals ("Sin registros" )){
388
396
if (ae .getSource ()==buscar ){
0 commit comments