Ecco un bel esempio:
codice:
import java.awt.*;
import java.util.*;
import javax.swing.*;
import com.toedter.calendar.JCalendar;
public class Prova {
public static void main(String[] args) {
Date d = JCalendarOptionPane.showDialog(null, "Scegli data");
if (d != null) {
System.out.println("La data selezionata è " + d);
} else {
System.out.println("Scelta annullata");
}
}
}
class JCalendarOptionPane {
private JCalendarOptionPane() {}
public static Date showDialog(Component parent, String title) {
JCalendar cal = new JCalendar();
int r = JOptionPane.showConfirmDialog(parent, cal, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (r == JOptionPane.OK_OPTION) {
return cal.getDate();
} else {
return null;
}
}
}