/
Feature9.java
59 lines (48 loc) · 1.91 KB
/
Feature9.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
package org.jdatepicker.features;
import org.jdatepicker.JDatePanel;
import org.jdatepicker.JDatePicker;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Calendar;
/**
* Disable a the widget.
*
* a. Disable the widget and colors should be updated appropriately.
* b. No values should be set when clicking on the component.
*/
public class Feature9 {
public static void main(final String[] args) {
// Create a frame
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.setSize(550, 300);
// Create a flow layout panel
final JPanel panel = new JPanel();
frame.getContentPane().add(panel);
// Create the JDatePanel
final JDatePanel datePanel = new JDatePanel();
datePanel.setEnabled(false);
panel.add(datePanel);
// Create the JDatePicker
final JDatePicker datePicker = new JDatePicker();
datePicker.setEnabled(false);
panel.add(datePicker);
// Add a button to print out date value
final JButton button = new JButton("Read Value");
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// The default model is UtilCalendarModel
Calendar c1 = (Calendar) datePanel.getModel().getValue();
System.out.println("JDatePanel: " + (c1 != null ? sdf.format(c1.getTime()) : null));
Calendar c2 = (Calendar) datePicker.getModel().getValue();
System.out.println("JDatePicker: " + (c2 != null ? sdf.format(c2.getTime()) : null));
}
});
panel.add(button);
// Make the frame visible
frame.setVisible(true);
}
}