-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGestordeTareasApp.java
854 lines (646 loc) · 40.3 KB
/
GestordeTareasApp.java
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
import java.awt.Color;
import java.awt.FileDialog;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Calendar;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author abel
*/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JFrame;
import javax.swing.JPanel;
import loquendo.tts.engine.TTSException;
import loquendo.tts.engine.TTSReader;
import loquendo.tts.engine.TTSSession;
public class GestordeTareasApp extends javax.swing.JFrame {
/**
* Creates new form GestordeTareasApp
*/
CalendarioEfemerides CE;
ArrayList tareas=new ArrayList();
Timer boca,timer;
TimerTask habla,actualiza;
public TTSSession hSession = null;
public TTSReader hReader = null;
public GestordeTareasApp() {
initComponents();
setLocationRelativeTo(null);
try { hSession = new TTSSession();
hReader = new TTSReader(hSession);
hReader.setAudio("LTTS7AudioBoard", null, 32000, "linear", 2);
hReader.loadPersona("Carmen",null,null);
} catch (Exception e) {e.printStackTrace();}
CE=new CalendarioEfemerides();
try{
String name="C:/tareas";
ObjectInputStream op=new ObjectInputStream( new FileInputStream(name));
tareas=(ArrayList)op.readObject();
}catch(Exception e){javax.swing.JOptionPane.showMessageDialog
(null,"No se encuentra el archivo tareas"
,"Error",javax.swing.JOptionPane.OK_OPTION); }
jPanel1.add(CE,new org.netbeans.lib.awtextra.AbsoluteConstraints(0,0, 450, 450));
jPanel1.repaint();
jPanel1.validate();
nunca.setSelected(true);
timer=new Timer();
boca=new Timer();
actualiza=new TimerTask() {public void run() {actualizaTareas();}};
habla=new TimerTask() {public void run() {habla();}};
actualizaTareas();
timer.scheduleAtFixedRate(actualiza,0,10000);
boca.scheduleAtFixedRate(habla,0,5000);
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
hora = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
min = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
seg = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jEditorPane1 = new javax.swing.JEditorPane();
jLabel6 = new javax.swing.JLabel();
nunca = new javax.swing.JRadioButton();
siempre = new javax.swing.JRadioButton();
semanal = new javax.swing.JRadioButton();
mensual = new javax.swing.JRadioButton();
anual = new javax.swing.JRadioButton();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jScrollPane3 = new javax.swing.JScrollPane();
jPanel5 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setMinimumSize(new java.awt.Dimension(960, 680));
setPreferredSize(new java.awt.Dimension(960, 680));
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jPanel1.setPreferredSize(new java.awt.Dimension(450, 450));
jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 270, 450, 450));
jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jLabel1.setText("Nombre:");
jPanel2.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 4, 50, 20));
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jPanel2.add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 0, 190, -1));
jLabel2.setText("Hora:");
jPanel2.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 0, -1, 20));
hora.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
horaActionPerformed(evt);
}
});
jPanel2.add(hora, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 0, 30, 30));
jLabel3.setText(" Min:");
jPanel2.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 0, 30, 20));
min.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
minActionPerformed(evt);
}
});
jPanel2.add(min, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 0, 30, 30));
jLabel4.setText("Seg:");
jPanel2.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 0, 30, 20));
jPanel2.add(seg, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 0, 30, 30));
jLabel5.setText("Descripción:");
jPanel2.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 30, 90, 20));
jScrollPane1.setViewportView(jEditorPane1);
jPanel2.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 50, 460, 140));
jLabel6.setText("Repetir:");
jPanel2.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 190, 60, 20));
nunca.setText("Nunca");
nunca.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nuncaActionPerformed(evt);
}
});
jPanel2.add(nunca, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 210, -1, -1));
siempre.setText("Siempre");
siempre.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
siempreActionPerformed(evt);
}
});
jPanel2.add(siempre, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 210, -1, -1));
semanal.setText("Semanal");
semanal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
semanalActionPerformed(evt);
}
});
jPanel2.add(semanal, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 210, -1, -1));
mensual.setText("Mensual");
mensual.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mensualActionPerformed(evt);
}
});
jPanel2.add(mensual, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 210, -1, -1));
anual.setText("Anual");
anual.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
anualActionPerformed(evt);
}
});
jPanel2.add(anual, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 210, -1, -1));
jButton1.setText("Guardar Tarea");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel2.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 240, -1, -1));
jButton2.setText("Borrar Tarea");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jPanel2.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 240, 110, -1));
getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 460, 270));
jScrollPane3.setPreferredSize(new java.awt.Dimension(500, 610));
jPanel5.setLayout(new java.awt.GridLayout(1, 0));
jScrollPane3.setViewportView(jPanel5);
getContentPane().add(jScrollPane3, new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 0, 470, 610));
pack();
}// </editor-fold>//GEN-END:initComponents
int posicion=0;
void habla(){ try{ ArrayList tareasdeldia=new ArrayList();
Calendar hoy=Calendar.getInstance();
int hora=hoy.get(Calendar.HOUR_OF_DAY);
int min=hoy.get(Calendar.MINUTE);
int seg=hoy.get(Calendar.SECOND);
if (CE.getEfemeride()!=null)
{ Efemeride ef=CE.getEfemeride();
Calendar ca=Calendar.getInstance();
ca.set(Calendar.HOUR_OF_DAY,7);
ca.set(Calendar.MINUTE, 45);
ca.set(Calendar.SECOND,0);
ca.set(Calendar.YEAR,hoy.get(Calendar.YEAR));
Tarea t=new Tarea("efemeride",ca,ef.efem);
tareasdeldia.add(t);
}
for(int i=0;i<tareas.size();i++)
{Tarea aux=(Tarea)tareas.get(i);
if (aux.dia.get(Calendar.YEAR)==Integer.parseInt(CE.getCalendario().jTextField1.getText())&&
aux.dia.get(Calendar.MONTH)==Integer.parseInt(CE.getCalendario().jTextField2.getText())-1&&
aux.dia.get(Calendar.DAY_OF_MONTH)==Integer.parseInt(CE.getCalendario().label2.getText())
) { if (!tareasdeldia.contains(aux)) tareasdeldia.add(aux);
}
}
for(int i=0;i<tareasdeldia.size();i++)
{ Tarea t1=(Tarea)tareasdeldia.get(i);
posicion=jScrollPane3.getVerticalScrollBar().getValue();
if (t1.dia.get(Calendar.HOUR_OF_DAY)==hora
&&
t1.dia.get(Calendar.MINUTE)==min
&&
Math.abs(t1.dia.get(Calendar.SECOND)-seg )<10
){
posicion=i*(jScrollPane3.getVerticalScrollBar().getMaximum()/tareasdeldia.size());
jScrollPane3.getVerticalScrollBar().setValue(posicion);
jScrollPane3.repaint();
String h=hora+":"+min+":"+"\n";
String aux=h;
aux+="Es la hora de"+"\n";
aux+=t1.nombre+"\n";
aux+=t1.Descripcion+"\n";
System.out.println(aux);
hReader.read(aux, false, false);
java.awt.Component []comp=jPanel5.getComponents();
for(int p=0;p<comp.length;p++)
{ Tarea t=((TareaPanel)comp[p]).tarea;
if (t.equals(t1)) ((TareaPanel)comp[p]).setBackground(Color.red);
else ((TareaPanel)comp[p]).setBackground(Color.white);
}
}
}
}catch(Exception e){e.printStackTrace();}
}
void actualizaTareas(){
try{ ArrayList tareasdeldia=new ArrayList();
Calendar hoy=Calendar.getInstance();
int hora=hoy.get(Calendar.HOUR_OF_DAY);
int min=hoy.get(Calendar.MINUTE);
int seg=hoy.get(Calendar.SECOND);
if (CE.getEfemeride()!=null)
{ Efemeride ef=CE.getEfemeride();
Calendar ca=Calendar.getInstance();
ca.set(Calendar.HOUR_OF_DAY,7);
ca.set(Calendar.MINUTE, 45);
ca.set(Calendar.SECOND,0);
ca.set(Calendar.YEAR,hoy.get(Calendar.YEAR));
Tarea t=new Tarea("efemeride",ca,ef.efem);
tareasdeldia.add(t);
}
for(int i=0;i<tareas.size();i++)
{Tarea aux=(Tarea)tareas.get(i);
if (aux.dia.get(Calendar.YEAR)==Integer.parseInt(CE.getCalendario().jTextField1.getText())&&
aux.dia.get(Calendar.MONTH)==Integer.parseInt(CE.getCalendario().jTextField2.getText())-1&&
aux.dia.get(Calendar.DAY_OF_MONTH)==Integer.parseInt(CE.getCalendario().label2.getText())
) { if (!tareasdeldia.contains(aux)) tareasdeldia.add(aux);
}
}
Object[]ob=tareasdeldia.toArray();
Arrays.sort(ob);
tareasdeldia=new ArrayList();
for(int i=0;i<ob.length;i++) tareasdeldia.add(ob[i]);
jPanel5.setLayout(new java.awt.GridLayout(tareasdeldia.size(), 1));
jPanel5.removeAll();
jPanel5.setSize(440,120*tareasdeldia.size());
for(int i=0;i<tareasdeldia.size();i++)
{ Tarea t1=(Tarea)tareasdeldia.get(i);
TareaPanel tp=new TareaPanel(t1,this);
if (t1.dia.get(Calendar.HOUR_OF_DAY)==hora
&&
t1.dia.get(Calendar.MINUTE)==min
&&
Math.abs(t1.dia.get(Calendar.SECOND)-seg )<10
) tp.setBackground(Color.red);
jPanel5.add(tp);
}
jScrollPane3.getVerticalScrollBar().setValue(posicion);
jScrollPane3.repaint();
}catch(Exception e){e.printStackTrace();}
}
private void horaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_horaActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_horaActionPerformed
private void minActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_minActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_minActionPerformed
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextField1ActionPerformed
private void nuncaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nuncaActionPerformed
nunca.setSelected(true);
siempre.setSelected(false);
semanal.setSelected(false);
mensual.setSelected(false);
anual.setSelected(false);
// TODO add your handling code here:
}//GEN-LAST:event_nuncaActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
int hra=0,minuto=0,segundo=0;
try{ hra=Integer.parseInt(hora.getText());
if (hra<0||hra>23) throw new Exception();
}
catch(Exception e){javax.swing.JOptionPane.showMessageDialog
(null,"formato de la hora incorrecto"
,"No se pudo guardar la tarea",javax.swing.JOptionPane.OK_OPTION);
return;
}
try{ minuto=Integer.parseInt(min.getText());
if (minuto<0||minuto>59) throw new Exception();
}
catch(Exception e){javax.swing.JOptionPane.showMessageDialog
(null,"formato de los minutos incorrecto"
,"No se pudo guardar la tarea",javax.swing.JOptionPane.OK_OPTION);
return;
}
try{ segundo=Integer.parseInt(seg.getText());
if (segundo<0||segundo>59) throw new Exception();
}
catch(Exception e){javax.swing.JOptionPane.showMessageDialog
(null,"formato de de los segundos incorrecto"
,"No se pudo guardar la tarea",javax.swing.JOptionPane.OK_OPTION);
return;
}
int año=1900,mes=1,dia=1;
try{
año=Integer.parseInt(CE.getCalendario().jTextField1.getText());
mes=Integer.parseInt(CE.getCalendario().jTextField2.getText())-1;
dia=Integer.parseInt(CE.getCalendario().label2.getText());
}catch(Exception e){javax.swing.JOptionPane.showMessageDialog
(null,"formato de de la Fecha"
,"No se pudo guardar la tarea",javax.swing.JOptionPane.OK_OPTION);
return;
}
if (nunca.isSelected()){
Calendar aux=Calendar.getInstance();
aux.set(año, mes, dia, hra, minuto, segundo);
Tarea tarea=new Tarea(jTextField1.getText(),aux,jEditorPane1.getText());
tareas.add(tarea);
}
else if (siempre.isSelected()){
for(int i=0;i<CE.getCalendario().dias.size();i++)
{Calendar aux=(Calendar)CE.getCalendario().dias.get(i);
if ( aux.get(Calendar.YEAR)==año)
{ Calendar x=Calendar.getInstance();
x.set(Calendar.YEAR,año);
x.set(Calendar.MONTH,aux.get(Calendar.MONTH));
x.set(Calendar.DAY_OF_MONTH,aux.get(Calendar.DAY_OF_MONTH));
x.set(Calendar.HOUR_OF_DAY,hra);
x.set(Calendar.MINUTE,minuto);
x.set(Calendar.SECOND,segundo);
Tarea tarea=new Tarea(jTextField1.getText(),x,jEditorPane1.getText());
tareas.add(tarea);
}
}
}
else if (semanal.isSelected()){ Calendar x=Calendar.getInstance();
x.set(año,mes, dia, hra, minuto, segundo);
for(int i=0;i<CE.getCalendario().dias.size();i++)
{Calendar aux=(Calendar)CE.getCalendario().dias.get(i);
if (aux.get(Calendar.YEAR)==año&&
aux.get(Calendar.DAY_OF_WEEK)==x.get(Calendar.DAY_OF_WEEK))
{ Calendar y=Calendar.getInstance();
y.set(Calendar.YEAR,año);
y.set(Calendar.MONTH,aux.get(Calendar.MONTH));
y.set(Calendar.DAY_OF_MONTH,aux.get(Calendar.DAY_OF_MONTH));
y.set(Calendar.HOUR_OF_DAY,hra);
y.set(Calendar.MINUTE,minuto);
y.set(Calendar.SECOND,segundo);
Tarea tarea=new Tarea(jTextField1.getText(),y,jEditorPane1.getText());
tareas.add(tarea);
}
}
}
else if (mensual.isSelected()){
for(int i=0;i<CE.getCalendario().dias.size();i++)
{Calendar aux=(Calendar)CE.getCalendario().dias.get(i);
if (aux.get(Calendar.DAY_OF_MONTH)==dia
&&
aux.get(Calendar.YEAR)==año)
{ Calendar x=Calendar.getInstance();
x.set(Calendar.YEAR,año);
x.set(Calendar.MONTH,aux.get(Calendar.MONTH));
x.set(Calendar.DAY_OF_MONTH,aux.get(Calendar.DAY_OF_MONTH));
x.set(Calendar.HOUR_OF_DAY,hra);
x.set(Calendar.MINUTE,minuto);
x.set(Calendar.SECOND,segundo);
Tarea tarea=new Tarea(jTextField1.getText(),x,jEditorPane1.getText());
tareas.add(tarea);
}
}
}
else if (anual.isSelected()) {
for(int i=0;i<CE.getCalendario().dias.size();i++)
{Calendar aux=(Calendar)CE.getCalendario().dias.get(i);
if (aux.get(Calendar.DAY_OF_MONTH)==dia&&
aux.get(Calendar.MONTH)==mes)
{ Calendar x=Calendar.getInstance();
x.set(Calendar.YEAR,año);
x.set(Calendar.MONTH,aux.get(Calendar.MONTH));
x.set(Calendar.DAY_OF_MONTH,aux.get(Calendar.DAY_OF_MONTH));
x.set(Calendar.HOUR_OF_DAY,hra);
x.set(Calendar.MINUTE,minuto);
x.set(Calendar.SECOND,segundo);
Tarea tarea=new Tarea(jTextField1.getText(),x,jEditorPane1.getText());
tareas.add(tarea);
}
}
}
try{
String name="C:/tareas";
ObjectOutputStream op=new ObjectOutputStream(new FileOutputStream(name));
op.writeObject(tareas);
}catch(Exception e){e.printStackTrace();
javax.swing.JOptionPane.showMessageDialog
(null,"No se pudo guardar los cambios"
,"Error",javax.swing.JOptionPane.OK_OPTION); }
actualizaTareas();
// TODO add your handling code here:
}//GEN-LAST:event_jButton1ActionPerformed
private void siempreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_siempreActionPerformed
nunca.setSelected(false);
siempre.setSelected(true);
semanal.setSelected(false);
mensual.setSelected(false);
anual.setSelected(false);
// TODO add your handling code here:
}//GEN-LAST:event_siempreActionPerformed
private void semanalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_semanalActionPerformed
nunca.setSelected(false);
siempre.setSelected(false);
semanal.setSelected(true);
mensual.setSelected(false);
anual.setSelected(false);
// TODO add your handling code here:
}//GEN-LAST:event_semanalActionPerformed
private void mensualActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mensualActionPerformed
nunca.setSelected(false);
siempre.setSelected(false);
semanal.setSelected(false);
mensual.setSelected(true);
anual.setSelected(false);
// TODO add your handling code here:
}//GEN-LAST:event_mensualActionPerformed
private void anualActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_anualActionPerformed
nunca.setSelected(false);
siempre.setSelected(false);
semanal.setSelected(false);
mensual.setSelected(false);
anual.setSelected(true);
// TODO add your handling code here:
}//GEN-LAST:event_anualActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
ArrayList copia=new ArrayList();
for(int i=0;i<tareas.size();i++)
copia.add(((Tarea)tareas.get(i)).clone());
int hra=0,minuto=0,segundo=0;
try{ hra=Integer.parseInt(hora.getText());
if (hra<0||hra>23) throw new Exception();
}
catch(Exception e){javax.swing.JOptionPane.showMessageDialog
(null,"formato de la hora incorrecto"
,"No se pudo guardar la tarea",javax.swing.JOptionPane.OK_OPTION);
return;
}
try{ minuto=Integer.parseInt(min.getText());
if (minuto<0||minuto>59) throw new Exception();
}
catch(Exception e){javax.swing.JOptionPane.showMessageDialog
(null,"formato de los minutos incorrecto"
,"No se pudo guardar la tarea",javax.swing.JOptionPane.OK_OPTION);
return;
}
try{ segundo=Integer.parseInt(seg.getText());
if (segundo<0||segundo>59) throw new Exception();
}
catch(Exception e){javax.swing.JOptionPane.showMessageDialog
(null,"formato de de los segundos incorrecto"
,"No se pudo guardar la tarea",javax.swing.JOptionPane.OK_OPTION);
return;
}
int año=1900,mes=1,dia=1;
for(int j=0;j<tareas.size();j++)
{Tarea Taux=(Tarea)tareas.get(j);
if (Taux.nombre.equals(jTextField1.getText())&&
Taux.Descripcion.equals(jEditorPane1.getText()) )
{ try{
año=Integer.parseInt(CE.getCalendario().jTextField1.getText());
mes=Integer.parseInt(CE.getCalendario().jTextField2.getText())-1;
dia=Integer.parseInt(CE.getCalendario().label2.getText());
}catch(Exception e){javax.swing.JOptionPane.showMessageDialog
(null,"formato de de la Fecha"
,"No se pudo guardar la tarea",javax.swing.JOptionPane.OK_OPTION);
return;
}
if (nunca.isSelected()){
Calendar aux=Calendar.getInstance();
aux.set(año, mes, dia, hra, minuto, segundo);
Tarea tarea=new Tarea(jTextField1.getText(),aux,jEditorPane1.getText());
copia.remove(tarea);
}
else if (siempre.isSelected()){
for(int i=0;i<CE.getCalendario().dias.size();i++)
{Calendar aux=(Calendar)CE.getCalendario().dias.get(i);
if ( aux.get(Calendar.YEAR)==año)
{ Calendar x=Calendar.getInstance();
x.set(Calendar.YEAR,año);
x.set(Calendar.MONTH,aux.get(Calendar.MONTH));
x.set(Calendar.DAY_OF_MONTH,aux.get(Calendar.DAY_OF_MONTH));
x.set(Calendar.HOUR_OF_DAY,hra);
x.set(Calendar.MINUTE,minuto);
x.set(Calendar.SECOND,segundo);
Tarea tarea=new Tarea(jTextField1.getText(),x,jEditorPane1.getText());
copia.remove(tarea);
}
}
}
else if (semanal.isSelected()){ Calendar x=Calendar.getInstance();
x.set(año,mes, dia, hra, minuto, segundo);
for(int i=0;i<CE.getCalendario().dias.size();i++)
{Calendar aux=(Calendar)CE.getCalendario().dias.get(i);
if (aux.get(Calendar.YEAR)==año&&
aux.get(Calendar.DAY_OF_WEEK)==x.get(Calendar.DAY_OF_WEEK))
{ Calendar y=Calendar.getInstance();
y.set(Calendar.YEAR,año);
y.set(Calendar.MONTH,aux.get(Calendar.MONTH));
y.set(Calendar.DAY_OF_MONTH,aux.get(Calendar.DAY_OF_MONTH));
y.set(Calendar.HOUR_OF_DAY,hra);
y.set(Calendar.MINUTE,minuto);
y.set(Calendar.SECOND,segundo);
Tarea tarea=new Tarea(jTextField1.getText(),y,jEditorPane1.getText());
copia.remove(tarea);
}
}
}
else if (mensual.isSelected()){
for(int i=0;i<CE.getCalendario().dias.size();i++)
{Calendar aux=(Calendar)CE.getCalendario().dias.get(i);
if (aux.get(Calendar.DAY_OF_MONTH)==dia
&&
aux.get(Calendar.YEAR)==año)
{ Calendar x=Calendar.getInstance();
x.set(Calendar.YEAR,año);
x.set(Calendar.MONTH,aux.get(Calendar.MONTH));
x.set(Calendar.DAY_OF_MONTH,aux.get(Calendar.DAY_OF_MONTH));
x.set(Calendar.HOUR_OF_DAY,hra);
x.set(Calendar.MINUTE,minuto);
x.set(Calendar.SECOND,segundo);
Tarea tarea=new Tarea(jTextField1.getText(),x,jEditorPane1.getText());
copia.remove(tarea);
}
}
}
else if (anual.isSelected()) {
for(int i=0;i<CE.getCalendario().dias.size();i++)
{Calendar aux=(Calendar)CE.getCalendario().dias.get(i);
if (aux.get(Calendar.DAY_OF_MONTH)==dia&&
aux.get(Calendar.MONTH)==mes)
{ Calendar x=Calendar.getInstance();
x.set(Calendar.YEAR,año);
x.set(Calendar.MONTH,aux.get(Calendar.MONTH));
x.set(Calendar.DAY_OF_MONTH,aux.get(Calendar.DAY_OF_MONTH));
x.set(Calendar.HOUR_OF_DAY,hra);
x.set(Calendar.MINUTE,minuto);
x.set(Calendar.SECOND,segundo);
Tarea tarea=new Tarea(jTextField1.getText(),x,jEditorPane1.getText());
copia.remove(tarea);
}
}
}
}
}
tareas=copia;
try{
String name="C:/tareas";
ObjectOutputStream op=new ObjectOutputStream(new FileOutputStream(name));
op.writeObject(tareas);
}catch(Exception e){e.printStackTrace();
javax.swing.JOptionPane.showMessageDialog
(null,"No se pudo guardar los cambios"
,"Error",javax.swing.JOptionPane.OK_OPTION); }
actualizaTareas();
// TODO add your handling code here:
}//GEN-LAST:event_jButton2ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(GestordeTareasApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(GestordeTareasApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(GestordeTareasApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(GestordeTareasApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new GestordeTareasApp().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JRadioButton anual;
public javax.swing.JTextField hora;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
public javax.swing.JEditorPane jEditorPane1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel5;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane3;
public javax.swing.JTextField jTextField1;
private javax.swing.JRadioButton mensual;
public javax.swing.JTextField min;
private javax.swing.JRadioButton nunca;
public javax.swing.JTextField seg;
private javax.swing.JRadioButton semanal;
private javax.swing.JRadioButton siempre;
// End of variables declaration//GEN-END:variables
}