-
Notifications
You must be signed in to change notification settings - Fork 0
/
Swing41.java
63 lines (51 loc) · 1.77 KB
/
Swing41.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
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class Swing41 extends JFrame implements ChangeListener{
JSpinner s1,s2,s3;
SpinnerModel day,month,year;
JLabel label;
String[] m = {"January","February","March","April","May","june","July",
"August","September","October","November","December"};
Swing41(){
setTitle("JSpinner Programe");
setSize(400,400);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(null);
setLocationRelativeTo(null);
String today = String.valueOf(java.time.Year.now());
int y = Integer.parseInt(today);
day = new SpinnerNumberModel(1,1,31,1);
month = new SpinnerListModel(m);
year = new SpinnerNumberModel(y,y-100,y,1 );
s1 = new JSpinner(day);
s2 = new JSpinner(month);
s3 = new JSpinner(year);
s1.setBounds(100,20,100,50);
s2.setBounds(100,100,100,50);
s3.setBounds(100,200,100,50);
add(s1);
add(s2);
add(s3);
s1.addChangeListener(this);
s2.addChangeListener(this);
s3.addChangeListener(this);
label = new JLabel();
label.setBounds(100,300,200,20);
setDOB();
add(label);
setVisible(true);
validate();
}
public void setDOB(){
int Date = (int) s1.getValue();
String Month = (String) s2.getValue();
int Year = (int) s3.getValue();
label.setText("Date of Birth is:"+Date+"-"+Month+"-"+Year);
}
public static void main(String[] args) { new Swing41(); }
@Override
public void stateChanged(ChangeEvent e) {
setDOB();
}
}