Créer et modifier une date à l’aide de JSpinner

Author:

 date, set, java, swing, awt, JFrame
{filelink=3469}

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.util.*;

public class TestSpinner extends JFrame {

  public MonthSpinner( ) {
    super("Month Spinner");
    setSize(200,100);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container c = getContentPane( );
    c.setLayout(new FlowLayout(FlowLayout.LEFT, 4,4));

    c.add(new JLabel("Date d'expiration:"));
    Date today = new Date( );

    JSpinner s = new JSpinner(new SpinnerDateModel(today, 
                 null, null, Calendar.MONTH));
                 
    // définir le model de JSpinner
    JSpinner.DateEditor de = new JSpinner.DateEditor(s, "dd/MM/yy");

    s.setEditor(de);
    c.add(s);
    c.add(new JTextField("Test JSpinner"));

    setVisible(true);
  }

  public static void main(String args[]) {
    new TestSpinner( );
  }
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *