I'm having trouble figuring out how make my program calculate the day of the week based on user input for month, day, year. Such as in this picture below. I have no clue on how to make it connect with the JTextField and the JComboBoxes. I truly appreciate anyones help with this. I know is I'm supposed to use:
Calendar xmas = new GregorianCalendar(1998, Calendar.DECEMBER, 25); int dayOfWeek = xmas.get(Calendar.DAY_OF_WEEK); // 6=Friday

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JTextField;
import javax.swing.JTextArea;
public class DayOfWeek extends JFrame
{
private JPanel contentPane;
private JTextField yearField;
private JLabel dayOfW;
/**
* Launch the application.
*/
public static void main(String[] args)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
try
{
DayOfWeek frame = new DayOfWeek();
frame.setVisible(true);
} catch (Exception e)
{
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public DayOfWeek()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 230);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel monthL = new JLabel("Month:");
monthL.setBounds(10, 11, 46, 14);
contentPane.add(monthL);
JComboBox monthBox = new JComboBox();
monthBox.setModel(new DefaultComboBoxModel(new String[] {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}));
monthBox.setBounds(53, 8, 109, 20);
contentPane.add(monthBox);
JLabel dayL = new JLabel("Day: ");
dayL.setBounds(172, 11, 31, 14);
contentPane.add(dayL);
JComboBox dayBox = new JComboBox();
dayBox.setModel(new DefaultComboBoxModel(new String[] {"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"}));
dayBox.setBounds(203, 8, 53, 20);
contentPane.add(dayBox);
JLabel yearL = new JLabel("Year: ");
yearL.setBounds(266, 11, 37, 14);
contentPane.add(yearL);
yearField = new JTextField();
yearField.setBounds(301, 8, 86, 20);
contentPane.add(yearField);
yearField.setColumns(10);
JLabel dayOfW;
dayOfW = new JLabel("The day of the week is");
dayOfW.setBounds(10, 153, 126, 14);
contentPane.add(dayOfW);
JTextArea textArea = new JTextArea();
textArea.setBounds(172, 148, 160, 19);
contentPane.add(textArea);
Calendar xmas = new GregorianCalendar(1998, Calendar.DECEMBER, 25);
int dayOfWeek = xmas.get(Calendar.DAY_OF_WEEK); // 6=Friday
yearField.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
}
});
}
}
Thank you very much