-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDayOfWeek_project.java
More file actions
57 lines (51 loc) · 1.41 KB
/
DayOfWeek_project.java
File metadata and controls
57 lines (51 loc) · 1.41 KB
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
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.util.*;
import java.text.*;
public class DayOfTheWeekService
{
JLabel outputLabel;
JComboBox month;
JTextField day;
JTextField year;
public JPanel getGuiPanel()
{
JPanel panel = new JPanel();
JButton button = new JButton("Let's do it!");
button.addActionListener(new DoItListener());
outputLabel = new JLabel("Date appears here");
DateFormatSymbols dateStuff = new DateFormatSymbols();
month = new JComboBox(dateStuff.getMonths());
day = new JTextField(8);
year = new JTextField(8);
JPanel inputPanel = new JPanel(new GridLayout(3,2));
inputPanel.add(new JLabel("Month"));
inputPanel.add(month);
inputPanel.add(new JLabel("Day"));
inputPanel.add(day);
inputPanel.add(new JLabel("Year"));
inputPanel.add(year);
panel.add(inputPanel);
panel.add(button);
panel.add(outputLabel);
return panel;
}
public class DoItListener implements ActionListener
{
public void actionPerformed(ActionEvent ev)
{
int monthNum = month.getSelectedIndex();
int dayNum = Integer.parseInt(day.getText());
int yearNum = Integer.parseInt(year.getText());
Calendar c = Calendar.getInstance();
c.set(Calendar.MONTH, monthNum);
c.set(Calendar.DAY_OF_MONTH, dayNum);
c.set(Calendar.YEAR, yearNum);
Date date = c.getTime();
String dayOfWeek = (new SimpleDateFormat(“EEEE”)).format(date);
outputLabel.setText(dayOfWeek);
}
}
}