Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Assisstance

  1. #1
    Junior Member
    Join Date
    Aug 2020
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Assisstance

    Hey everyone,

    I have an assignment that I am totally lost on...

    I am in 2nd year of Systems Development...
    Please assist me on what I am missing or doing wrong
    I have to have a GUI that will select a date and time...
    Basically, I need Monday - Saturday with working hours and Sunday needs different working hours.

    My code so far works for everyday, but I am struggling with Sunday.

    I have to use JXDatePicker (unless there is something else I can use...)

    If I select the day and it's out of operating hours, it needs to throw an error.
    If I select a valid day and time, it needs to go to my list box.

    My time is selected from a combobox and my date is selected from JXDatePicker.

    MY CODE THAT WORKS FOR EVERYDAY:

    try

    {
    SimpleDateFormat parser = new SimpleDateFormat("HH:mm");
    Date opening = parser.parse("09:00");
    Date closing = parser.parse("22:00");

    Date userDate = parser.parse((String) txtTime.getSelectedItem());
    if (userDate.after(opening) && userDate.before(closing))
    {
    JOptionPane.showMessageDialog(null,"Success");
    dlmList.addElement(txtTime.getSelectedItem().toStr ing());

    }

    else
    {


    JOptionPane.showMessageDialog(null, "Invalid Time");

    }


    } catch (ParseException ex) {
    Logger.getLogger(Customer.class.getName()).log(Lev el.SEVERE, null, ex);

    }

    -NOT SURE IF I NEED TO ADD THE BELOW CODE FOR THE DATE...
    BUT WHEN I CHANGE THE DATE FORMAT AS BELOW, IT WRITES; DAY DATE YEAR TIME AND TIMEZONE INSTEAD OF JUST DAY AND DATE TO MY LIST...
    I do think it is the settings of JXDatepicker, and it doesn't allow me to remove the timezone.


    try
    {

    Date Date = new Date();

    SimpleDateFormat SimpleDateformat = new SimpleDateFormat("EEEE"); // the day of the week spelled out completely
    Object dayOfWeek = null;



    if(dayOfWeek == "Sunday")
    {
    String opening = "08:00";
    String closing = "21:00";
    }

    else
    {
    String opening = "09:00";
    String closing = "22:00";
    }

    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Assisstance

    Can you post the output from the program that shows what you are talking about? Add some comments where the output is not what you want.

    One problem I see in the code is using == to compare String objects. You need to use the equals() method to compare the contents of objects.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.