IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 Java Discussion :

[Swing] Calendrier en Java


Sujet :

Java

  1. #1
    Provisoirement toléré
    Homme Profil pro
    Développeur JAVA JEE / PHP
    Inscrit en
    Avril 2008
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur JAVA JEE / PHP
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 151
    Points : 72
    Points
    72
    Par défaut [Swing] Calendrier en Java
    Bonjour

    J'ai besoin de developper un CALENDRIER en java sous swing. s'il vous plait aider moi.

    Merci d'avance

  2. #2
    Invité
    Invité(e)
    Par défaut
    C'est un peu vague.... Quel(s) problème(s) as tu exactement ? As tu essayé quelque chose ? as tu fais des recherhes ?

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    429
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 429
    Points : 475
    Points
    475
    Par défaut
    Bonjour,

    Que veux-tu dire par "developper un CALENDRIER" ?

    Nicolas

  4. #4
    Provisoirement toléré
    Homme Profil pro
    Développeur JAVA JEE / PHP
    Inscrit en
    Avril 2008
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur JAVA JEE / PHP
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 151
    Points : 72
    Points
    72
    Par défaut
    je vouderai lancer un calendrier dans un fram, puis selectionner le jour souhaité. Est ce qu'il existe un composant Calendrier sous Swing.

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    429
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 429
    Points : 475
    Points
    475
    Par défaut
    C'est un exercice donné en cours ?
    Quelles idées as-tu ? Quelles classes penses-tu utiliser ?

  6. #6
    Provisoirement toléré
    Homme Profil pro
    Développeur JAVA JEE / PHP
    Inscrit en
    Avril 2008
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur JAVA JEE / PHP
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 151
    Points : 72
    Points
    72
    Par défaut
    Non, je travail sur un projet et je veux selectionner le jour et le mettre dans un champs texte

  7. #7
    Invité
    Invité(e)
    Par défaut
    Ben écoute avec les trois mots : swing java calendrier dans google j'ai trouvé plein de choses... Peut--être peux tu commencer par là et si tu as des problèmes d'utilisation d'une des solutions trouvées, revenir demander ici.
    Si tu veux le faire toi même, dis nous ce que tu as essayé et où tu bloques exactement, on ne va pas te donner une solution toute faite comme ca...

  8. #8
    Provisoirement toléré
    Homme Profil pro
    Développeur JAVA JEE / PHP
    Inscrit en
    Avril 2008
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur JAVA JEE / PHP
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 151
    Points : 72
    Points
    72
    Par défaut
    quel classe que je vais utiliser ? si vous avez un lien envoyer le moi

    Merci infiniment

  9. #9
    Membre chevronné Avatar de guigui5931
    Profil pro
    Chef de projet NTIC
    Inscrit en
    Avril 2006
    Messages
    1 667
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Chef de projet NTIC
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 667
    Points : 2 232
    Points
    2 232
    Par défaut
    Il n'y as pas de classe dans la bibliothèque standard. Par contre comme te dis George7 tu fais une recherche sur Google et tu trouvera plein de classe déjà développé qui affichent un calendrier en SWING. A toi de trouver celle qui se rapproche le plus de ce que tu veux.
    autant l'hiver éclate que l'hétéroclite
    le vrai geek c'est celui qui croit qu'il y a 1024 mètres dans un kilomètre

  10. #10
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par empire.dev Voir le message
    quel classe que je vais utiliser ?
    Bon écoute je veux bien faire des efforts mais tu devrais en faire aussi, tu as essayé de chercher avec les mots que j'ai dits ? Tu as essayé une des solutions proposées dans les résultats ?

  11. #11
    Provisoirement toléré
    Homme Profil pro
    Développeur JAVA JEE / PHP
    Inscrit en
    Avril 2008
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur JAVA JEE / PHP
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 151
    Points : 72
    Points
    72
    Par défaut
    Je cherche toujours sur google avant de lancer sur developper j'ai rien trouvé

  12. #12
    Invité
    Invité(e)
    Par défaut
    Citation Envoyé par empire.dev Voir le message
    Je cherche toujours sur google avant de lancer sur developper j'ai rien trouvé
    Permets moi de douter là. J'ai trouvé plein de classes et bibliothèques pour swing qui pourraient te convenir, par exemple, avec JCalendar...

  13. #13
    Provisoirement toléré
    Homme Profil pro
    Développeur JAVA JEE / PHP
    Inscrit en
    Avril 2008
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur JAVA JEE / PHP
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 151
    Points : 72
    Points
    72
    Par défaut
    Je cherche de ma part mais si vous trouverez un lien envoyer moi . Merci

  14. #14
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    429
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 429
    Points : 475
    Points
    475
    Par défaut
    Bonjour,

    JCalendar t'a déjà été proposé, et semble convenir à ton besoin.
    http://www.toedter.com/en/jcalendar/index.html

    Nicolas

  15. #15
    Provisoirement toléré
    Homme Profil pro
    Développeur JAVA JEE / PHP
    Inscrit en
    Avril 2008
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur JAVA JEE / PHP
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 151
    Points : 72
    Points
    72
    Par défaut
    Bonjour,

    Merci pour le lien mais j'ai déjà telechrger jCalendar, et je ne sais pas comme l'intégrer dans mon projet.

  16. #16
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    429
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 429
    Points : 475
    Points
    475
    Par défaut
    Un exemple simple :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    import com.toedter.calendar.*;
    import javax.swing.*;
    // http://www.toedter.com/en/jcalendar/index.html
     
     
    // appeler le fichier Exemple111_TestJCalendar.java
    // ne pas oublier d'ajouter le JAR de JCalendar dans le CLASSPATH
    // Nicolas_75
    // 26 août 2008
    // pour http://www.developpez.net/forums/d604992/java/interfaces-graphiques-java/debuter/swing-calendrier-java/#post3579134
     
    public class Exemple111_TestJCalendar {
     
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    JFrame frame = new JFrame("Test JCalendar");
                    JDateChooser dateChooser = new JDateChooser();
                    frame.add(dateChooser);
                    frame.pack();
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setLocationRelativeTo(null); // pour centrer
                    frame.setVisible(true);
                }
            });  
        }
    }

  17. #17
    Provisoirement toléré
    Homme Profil pro
    Développeur JAVA JEE / PHP
    Inscrit en
    Avril 2008
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur JAVA JEE / PHP
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 151
    Points : 72
    Points
    72
    Par défaut
    Bonjour

    Comment ajouter un botton pour copier la date dans un textfield dans un autre fram ?

    Merci

  18. #18
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    429
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2005
    Messages : 429
    Points : 475
    Points
    475
    Par défaut
    Cherche un peu, tente de le faire.
    Si cela ne fonctionne pas, poste un SSCCE que nous puissions corriger.

  19. #19
    Provisoirement toléré
    Homme Profil pro
    Développeur JAVA JEE / PHP
    Inscrit en
    Avril 2008
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur JAVA JEE / PHP
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 151
    Points : 72
    Points
    72
    Par défaut
    Bonjour

    Voici le code que je veux utiliser
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    /*
     *  JCalendar.java  - A bean for choosing a date
     *  Copyright (C) 2004 Kai Toedter
     *  kai@toedter.com
     *  www.toedter.com
     *
     *  This program is free software; you can redistribute it and/or
     *  modify it under the terms of the GNU Lesser General Public License
     *  as published by the Free Software Foundation; either version 2
     *  of the License, or (at your option) any later version.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU Lesser General Public License for more details.
     *
     *  You should have received a copy of the GNU Lesser General Public License
     *  along with this program; if not, write to the Free Software
     *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     */
     
    package ma.computime.easytime.traymonitor.core.toedter.calendar;
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Font;
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.Locale;
     
    import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
     
    /**
     * JCalendar is a bean for entering a date by choosing the year, month and day.
     * 
     * @author Kai Toedter
     * @version $LastChangedRevision: 95 $
     * @version $LastChangedDate: 2006-05-05 18:43:15 +0200 (Fr, 05 Mai 2006) $
     */
    public class JCalendar extends JPanel implements PropertyChangeListener {
    	private static final long serialVersionUID = 8913369762644440133L;
     
    	private Calendar calendar;
     
    	/** the day chooser */
    	protected static JDayChooser dayChooser;
    	private boolean initialized = false;
     
    	/** indicates if weeks of year shall be visible */
    	protected boolean weekOfYearVisible = true;
     
    	/** the locale */
    	protected Locale locale;
     
    	/** the month chooser */
    	protected JMonthChooser monthChooser;
     
    	private JPanel monthYearPanel;
     
    	/** the year chhoser */
    	protected JYearChooser yearChooser;
     
    	protected Date minSelectableDate;
     
    	protected Date maxSelectableDate;
     
    	/**
             * Default JCalendar constructor.
             */
    	public JCalendar() {
    		this(null, null, true, true);
    	}
     
    	/**
             * JCalendar constructor which allows the initial date to be set.
             * 
             * @param date
             *            the date
             */
    	public JCalendar(Date date) {
    		this(date, null, true, true);
    	}
     
    	/**
             * JCalendar constructor which allows the initial calendar to be set.
             * 
             * @param calendar
             *            the calendar
             */
    	public JCalendar(Calendar calendar) {
    		this(null, null, true, true);
    		setCalendar(calendar);
    	}
     
    	/**
             * JCalendar constructor allowing the initial locale to be set.
             * 
             * @param locale
             *            the new locale
             */
    	public JCalendar(Locale locale) {
    		this(null, locale, true, true);
    	}
     
    	/**
             * JCalendar constructor specifying both the initial date and locale.
             * 
             * @param date
             *            the date
             * @param locale
             *            the new locale
             */
    	public JCalendar(Date date, Locale locale) {
    		this(date, locale, true, true);
    	}
     
    	/**
             * JCalendar constructor specifying both the initial date and the month
             * spinner type.
             * 
             * @param date
             *            the date
             * @param monthSpinner
             *            false, if no month spinner should be used
             */
    	public JCalendar(Date date, boolean monthSpinner) {
    		this(date, null, monthSpinner, true);
    	}
     
    	/**
             * JCalendar constructor specifying both the locale and the month spinner.
             * 
             * @param locale
             *            the locale
             * @param monthSpinner
             *            false, if no month spinner should be used
             */
    	public JCalendar(Locale locale, boolean monthSpinner) {
    		this(null, locale, monthSpinner, true);
    	}
     
    	/**
             * JCalendar constructor specifying the month spinner type.
             * 
             * @param monthSpinner
             *            false, if no month spinner should be used
             */
    	public JCalendar(boolean monthSpinner) {
    		this(null, null, monthSpinner, true);
    	}
     
    	/**
             * JCalendar constructor with month spinner parameter.
             * 
             * @param date
             *            the date
             * @param locale
             *            the locale
             * @param monthSpinner
             *            false, if no month spinner should be used
             * @param weekOfYearVisible
             *            true, if weeks of year shall be visible
             */
    	public JCalendar(Date date, Locale locale, boolean monthSpinner, boolean weekOfYearVisible) {
     
    		setName("JCalendar");
     
    		// needed for setFont() etc.
    		dayChooser = null;
    		monthChooser = null;
    		yearChooser = null;
    		this.weekOfYearVisible = weekOfYearVisible;
     
    		this.locale = locale;
     
    		if (locale == null) {
    			this.locale = Locale.getDefault();
    		}
     
    		calendar = Calendar.getInstance();
     
    		setLayout(new BorderLayout());
     
    		monthYearPanel = new JPanel();
    		monthYearPanel.setLayout(new BorderLayout());
     
    		monthChooser = new JMonthChooser(monthSpinner);
    		yearChooser = new JYearChooser();
    		monthChooser.setYearChooser(yearChooser);
    		monthYearPanel.add(monthChooser, BorderLayout.WEST);
    		monthYearPanel.add(yearChooser, BorderLayout.CENTER);
    		monthYearPanel.setBorder(BorderFactory.createEmptyBorder());
     
    		dayChooser = new JDayChooser(weekOfYearVisible);
    		dayChooser.addPropertyChangeListener(this);
    		monthChooser.setDayChooser(dayChooser);
    		monthChooser.addPropertyChangeListener(this);
    		yearChooser.setDayChooser(dayChooser);
    		yearChooser.addPropertyChangeListener(this);
    		add(monthYearPanel, BorderLayout.NORTH);
    		add(dayChooser, BorderLayout.CENTER);
     
    		// Set the initialized flag before setting the calendar. This will
    		// cause the other components to be updated properly.
    		if (date != null) {
    			calendar.setTime(date);
    		}
     
    		initialized = true;
     
    		setCalendar(calendar);
    	}
     
    	/**
             * Creates a JFrame with a JCalendar inside and can be used for testing.
             * 
             * @param s
             *            The command line arguments
             */
    	public static void main(String[] s) {
    		JFrame frame = new JFrame("JCalendar");
     
    		JCalendar jcalendar = new JCalendar();
    		frame.getContentPane().add(jcalendar);
    		frame.pack();
    		frame.setVisible(true);
     
    	}
     
    	/**
             * Returns the calendar property.
             * 
             * @return the value of the calendar property.
             */
    	public Calendar getCalendar() {
    		return calendar;
    	}
     
    	/**
             * Gets the dayChooser attribute of the JCalendar object
             * 
             * @return the dayChooser value
             */
    	public JDayChooser getDayChooser() {
    		return dayChooser;
    	}
     
    	/**
             * Returns the locale.
             * 
             * @return the value of the locale property.
             * 
             * @see #setLocale
             */
    	public Locale getLocale() {
    		return locale;
    	}
     
    	/**
             * Gets the monthChooser attribute of the JCalendar object
             * 
             * @return the monthChooser value
             */
    	public JMonthChooser getMonthChooser() {
    		return monthChooser;
    	}
     
    	/**
             * Gets the yearChooser attribute of the JCalendar object
             * 
             * @return the yearChooser value
             */
    	public JYearChooser getYearChooser() {
    		return yearChooser;
    	}
     
    	/**
             * Indicates if the weeks of year are visible..
             * 
             * @return boolean true, if weeks of year are visible
             */
    	public boolean isWeekOfYearVisible() {
    		return dayChooser.isWeekOfYearVisible();
    	}
     
    	/**
             * JCalendar is a PropertyChangeListener, for its day, month and year
             * chooser.
             * 
             * @param evt
             *            the property change event
             */
    	public void propertyChange(PropertyChangeEvent evt) {
    		if (calendar != null) {
    			Calendar c = (Calendar) calendar.clone();
     
    			if (evt.getPropertyName().equals("day")) {
    				c.set(Calendar.DAY_OF_MONTH, ((Integer) evt.getNewValue()).intValue());
    				setCalendar(c, false);
    			} else if (evt.getPropertyName().equals("month")) {
    				c.set(Calendar.MONTH, ((Integer) evt.getNewValue()).intValue());
    				setCalendar(c, false);
    			} else if (evt.getPropertyName().equals("year")) {
    				c.set(Calendar.YEAR, ((Integer) evt.getNewValue()).intValue());
    				setCalendar(c, false);
    			} else if (evt.getPropertyName().equals("date")) {
    				c.setTime((Date) evt.getNewValue());
    				setCalendar(c, true);
    			}
    		}
    	}
     
    	/**
             * Sets the background color.
             * 
             * @param bg
             *            the new background
             */
    	public void setBackground(Color bg) {
    		super.setBackground(bg);
     
    		if (dayChooser != null) {
    			dayChooser.setBackground(bg);
    		}
    	}
     
    	/**
             * Sets the calendar property. This is a bound property.
             * 
             * @param c
             *            the new calendar
             * @throws NullPointerException -
             *             if c is null;
             * @see #getCalendar
             */
    	public void setCalendar(Calendar c) {
    		setCalendar(c, true);
    	}
     
    	/**
             * Sets the calendar attribute of the JCalendar object
             * 
             * @param c
             *            the new calendar value
             * @param update
             *            the new calendar value
             * @throws NullPointerException -
             *             if c is null;
             */
    	private void setCalendar(Calendar c, boolean update) {
    		if (c == null) {
    			setDate(null);
    		}
    		Calendar oldCalendar = calendar;
    		calendar = c;
     
    		if (update) {
    			// Thanks to Jeff Ulmer for correcting a bug in the sequence :)
    			yearChooser.setYear(c.get(Calendar.YEAR));
    			monthChooser.setMonth(c.get(Calendar.MONTH));
    			dayChooser.setDay(c.get(Calendar.DATE));
    		}
     
    		firePropertyChange("calendar", oldCalendar, calendar);
    	}
     
    	/**
             * Enable or disable the JCalendar.
             * 
             * @param enabled
             *            the new enabled value
             */
    	public void setEnabled(boolean enabled) {
    		super.setEnabled(enabled);
     
    		if (dayChooser != null) {
    			dayChooser.setEnabled(enabled);
    			monthChooser.setEnabled(enabled);
    			yearChooser.setEnabled(enabled);
    		}
    	}
     
    	/**
             * Returns true, if enabled.
             * 
             * @return true, if enabled.
             */
    	public boolean isEnabled() {
    		return super.isEnabled();
    	}
     
    	/**
             * Sets the font property.
             * 
             * @param font
             *            the new font
             */
    	public void setFont(Font font) {
    		super.setFont(font);
     
    		if (dayChooser != null) {
    			dayChooser.setFont(font);
    			monthChooser.setFont(font);
    			yearChooser.setFont(font);
    		}
    	}
     
    	/**
             * Sets the foreground color.
             * 
             * @param fg
             *            the new foreground
             */
    	public void setForeground(Color fg) {
    		super.setForeground(fg);
     
    		if (dayChooser != null) {
    			dayChooser.setForeground(fg);
    			monthChooser.setForeground(fg);
    			yearChooser.setForeground(fg);
    		}
    	}
     
    	/**
             * Sets the locale property. This is a bound property.
             * 
             * @param l
             *            the new locale value
             * 
             * @see #getLocale
             */
    	public void setLocale(Locale l) {
    		if (!initialized) {
    			super.setLocale(l);
    		} else {
    			Locale oldLocale = locale;
    			locale = l;
    			dayChooser.setLocale(locale);
    			monthChooser.setLocale(locale);
    			firePropertyChange("locale", oldLocale, locale);
    		}
    	}
     
    	/**
             * Sets the week of year visible.
             * 
             * @param weekOfYearVisible
             *            true, if weeks of year shall be visible
             */
    	public void setWeekOfYearVisible(boolean weekOfYearVisible) {
    		dayChooser.setWeekOfYearVisible(weekOfYearVisible);
    		setLocale(locale); // hack for doing complete new layout :)
    	}
     
    	/**
             * Gets the visibility of the decoration background.
             * 
             * @return true, if the decoration background is visible.
             */
    	public boolean isDecorationBackgroundVisible() {
    		return dayChooser.isDecorationBackgroundVisible();
    	}
     
    	/**
             * Sets the decoration background visible.
             * 
             * @param decorationBackgroundVisible
             *            true, if the decoration background should be visible.
             */
    	public void setDecorationBackgroundVisible(boolean decorationBackgroundVisible) {
    		dayChooser.setDecorationBackgroundVisible(decorationBackgroundVisible);
    		setLocale(locale); // hack for doing complete new layout :)
    	}
     
    	/**
             * Gets the visibility of the decoration border.
             * 
             * @return true, if the decoration border is visible.
             */
    	public boolean isDecorationBordersVisible() {
    		return dayChooser.isDecorationBordersVisible();
    	}
     
    	/**
             * Sets the decoration borders visible.
             * 
             * @param decorationBordersVisible
             *            true, if the decoration borders should be visible.
             */
    	public void setDecorationBordersVisible(boolean decorationBordersVisible) {
    		dayChooser.setDecorationBordersVisible(decorationBordersVisible);
    		setLocale(locale); // hack for doing complete new layout :)
    	}
     
    	/**
             * Returns the color of the decoration (day names and weeks).
             * 
             * @return the color of the decoration (day names and weeks).
             */
    	public Color getDecorationBackgroundColor() {
    		return dayChooser.getDecorationBackgroundColor();
    	}
     
    	/**
             * Sets the background of days and weeks of year buttons.
             * 
             * @param decorationBackgroundColor
             *            the background color
             */
    	public void setDecorationBackgroundColor(Color decorationBackgroundColor) {
    		dayChooser.setDecorationBackgroundColor(decorationBackgroundColor);
    	}
     
    	/**
             * Returns the Sunday foreground.
             * 
             * @return Color the Sunday foreground.
             */
    	public Color getSundayForeground() {
    		return dayChooser.getSundayForeground();
    	}
     
    	/**
             * Returns the weekday foreground.
             * 
             * @return Color the weekday foreground.
             */
    	public Color getWeekdayForeground() {
    		return dayChooser.getWeekdayForeground();
    	}
     
    	/**
             * Sets the Sunday foreground.
             * 
             * @param sundayForeground
             *            the sundayForeground to set
             */
    	public void setSundayForeground(Color sundayForeground) {
    		dayChooser.setSundayForeground(sundayForeground);
    	}
     
    	/**
             * Sets the weekday foreground.
             * 
             * @param weekdayForeground
             *            the weekdayForeground to set
             */
    	public void setWeekdayForeground(Color weekdayForeground) {
    		dayChooser.setWeekdayForeground(weekdayForeground);
    	}
     
    	/**
             * Returns a Date object.
             * 
             * @return a date object constructed from the calendar property.
             */
    	public Date getDate() {
    		return new Date(calendar.getTimeInMillis());
    	}
     
    	/**
             * Sets the date. Fires the property change "date".
             * 
             * @param date
             *            the new date.
             * @throws NullPointerException -
             *             if tha date is null
             */
    	public void setDate(Date date) {
    		Date oldDate = calendar.getTime();
    		calendar.setTime(date);
    		int year = calendar.get(Calendar.YEAR);
    		int month = calendar.get(Calendar.MONTH);
    		int day = calendar.get(Calendar.DAY_OF_MONTH);
     
    		yearChooser.setYear(year);
    		monthChooser.setMonth(month);
    		dayChooser.setCalendar(calendar);
    		dayChooser.setDay(day);
     
    		firePropertyChange("date", oldDate, date);
    	}
     
    	/**
             * Sets a valid date range for selectable dates. If max is before
             * min, the default range with no limitation is set.
             * 
             * @param min
             *            the minimum selectable date or null (then the minimum date is
             *            set to 01\01\0001)
             * @param max
             *            the maximum selectable date or null (then the maximum date is
             *            set to 01\01\9999)
             */
    	public void setSelectableDateRange(Date min, Date max) {
    		dayChooser.setSelectableDateRange(min, max);
    	};
     
    	/**
             * Gets the minimum selectable date.
             * 
             * @return the minimum selectable date
             */
    	public Date getMaxSelectableDate() {
    		return dayChooser.getMaxSelectableDate();
    	}
     
    	/**
             * Gets the maximum selectable date.
             * 
             * @return the maximum selectable date
             */
    	public Date getMinSelectableDate() {
    		return dayChooser.getMinSelectableDate();
    	}
     
    	/**
             * Sets the maximum selectable date.
             * 
             * @param max maximum selectable date
             */
    	public void setMaxSelectableDate(Date max) {
    		dayChooser.setMaxSelectableDate(max);
    	}
     
    	/**
             * Sets the minimum selectable date.
             * 
             * @param min minimum selectable date
             */
    	public void setMinSelectableDate(Date min) {
    		dayChooser.setMinSelectableDate(min);
    	}
     
    	/**
             * Gets the maximum number of characters of a day name or 0. If 0 is
             * returned, dateFormatSymbols.getShortWeekdays() will be used.
             * 
             * @return the maximum number of characters of a day name or 0.
             */
    	public int getMaxDayCharacters() {
    		return dayChooser.getMaxDayCharacters();
    	}
     
    	/**
             * Sets the maximum number of characters per day in the day bar. Valid
             * values are 0-4. If set to 0, dateFormatSymbols.getShortWeekdays() will be
             * used, otherwise theses strings will be reduced to the maximum number of
             * characters.
             * 
             * @param maxDayCharacters
             *            the maximum number of characters of a day name.
             */
    	public void setMaxDayCharacters(int maxDayCharacters) {
    		dayChooser.setMaxDayCharacters(maxDayCharacters);
    	}
    }

    je lance le calendrier a l'aide d'un botton comme suite :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
        private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
     
     
              JFrame frame = new JFrame("Test JCalendar");
              JCalendar dateChooser = new JCalendar();
              frame.add(dateChooser);
              frame.pack();
              //frame.add(jButton1);
              frame.setLocationRelativeTo(null); // pour centrer
              frame.setVisible(true);
     
     
        }
    Je vouderai enregistrer la date selectionner dans un JtextField ou dans un fichier. s'il vous plait aider moi

    Merci d'avance

  20. #20
    Provisoirement toléré
    Homme Profil pro
    Développeur JAVA JEE / PHP
    Inscrit en
    Avril 2008
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur JAVA JEE / PHP
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2008
    Messages : 151
    Points : 72
    Points
    72
    Par défaut
    J'ai essayer ça, mais le problème c'est que je récupère la date actuel,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
        private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
     
     
     
              /*
              JFrame frame = new JFrame("Test JCalendar");
              JCalendar dateChooser = new JCalendar();
              
              DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
           // System.out.println(df.format(dateChooser.getTime()));
              System.out.println();
              System.out.println(dateChooser.calendar.getTime());
              jTextField18.setText(dateChooser.calendar.getTime().toString());
              frame.add(dateChooser);
              frame.pack();
            //frame.add(jButton1);
              frame.setLocationRelativeTo(null); // pour centrer
              frame.setVisible(true);
    */
              JFrame frame = new JFrame("Test JCalendar");
              JCalendar dateChooser = new JCalendar();
     
              DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
              df.setCalendar(dateChooser.calendar);
     
           // System.out.println(df.format(dateChooser.getTime()));
              System.out.println();
     
     
              System.out.println(df.getCalendar().getTime());
     
              jTextField18.setText(df.getCalendar().getTime().toString());
     
              frame.add(dateChooser);
              frame.pack();
            //frame.add(jButton1);
              frame.setLocationRelativeTo(null); // pour centrer
              frame.setVisible(true);
     
     
     
     
        }

Discussions similaires

  1. [Jcalendar] construire un agenda /calendrier avec java.
    Par Battant dans le forum Composants
    Réponses: 3
    Dernier message: 08/06/2010, 11h57
  2. Calendrier graphique java
    Par projet16 dans le forum AWT/Swing
    Réponses: 1
    Dernier message: 22/11/2007, 11h27
  3. calendrier en java
    Par le_tigre_est_en_toi dans le forum Collection et Stream
    Réponses: 1
    Dernier message: 29/12/2006, 19h38
  4. Calendrier en Java
    Par r-o-m-z dans le forum Collection et Stream
    Réponses: 5
    Dernier message: 21/10/2006, 15h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo