Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

public class MonthYear { // constant values for the years public static final int JANUARY = 0; public static final int FEBRUARY = 1; public

public class MonthYear { // constant values for the years public static final int JANUARY = 0; public static final int FEBRUARY = 1; public static final int MARCH = 2; public static final int APRIL = 3; public static final int MAY = 4; public static final int JUNE = 5; public static final int JULY = 6; public static final int AUGUST = 7; public static final int SEPTEMBER = 8; public static final int OCTOBER = 9; public static final int NOVEMBER = 10; public static final int DECEMBER = 11; // constant values for the days of the week public static final int SUNDAY = 1; public static final int MONDAY = 2; public static final int TUESDAY = 3; public static final int WEDNESDAY = 4; public static final int THURSDAY = 5; public static final int FRIDAY = 6; public static final int SATURDAY = 7; private int month; private int year; // day of week the first day of the month lands on private int firstWeekDayOfMonth; public MonthYear() { Calendar now = Calendar.getInstance(); month = now.get(Calendar.MONTH); year = now.get(Calendar.YEAR); computeFirstWeekDay(); } public MonthYear(int theMonth, int theYear) { if (theMonth  DECEMBER) { month = DECEMBER; } else { month = theMonth; } year = (theYear = EPOCH_YEAR) { // add number of days in each year since 1970 to dayCount for (int y = EPOCH_YEAR; y = year; y--) { dayCount -= numDaysInYear(y); } } // add number of days in each previous month of the year for (int i = JANUARY; i  0) // if n mod m == 0, then return m, else return n mod m private static long mod(long n, long m) { long result = n % m; if (result  
package calendar; import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.layout.BorderPane; import javafx.scene.layout.GridPane; import javafx.scene.layout.StackPane; import javafx.scene.layout.HBox; import javafx.scene.layout.ColumnConstraints; import javafx.scene.layout.RowConstraints; import javafx.scene.text.Font; import javafx.scene.text.FontPosture; import javafx.scene.text.FontWeight; import javafx.scene.paint.Color; import java.util.Calendar; public class CalendarDisplay extends Application { private static final int WIDTH = 350; // initial window width private static final int HEIGHT = 320; // initial window height private static final int MAX_DAYS_IN_MONTH = 31; // max num days in month private static final int NUM_WEEK_ROWS = 6; // number of rows for weeks private static final int TOP_BAR_SPACING = 10; // spacing in top bar private static final String[] dayNames = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; private MonthYear calendar; private Calendar now; private Button prevMonthBtn; private Button nextMonthBtn; private Button prevYearBtn; private Button nextYearBtn; private Label monthLbl; private Label yearLbl; private StackPane[] dayNameCells = new StackPane[dayNames.length]; private Label[] dateLbls = new Label[MAX_DAYS_IN_MONTH]; private StackPane[] dateCells = new StackPane[dateLbls.length]; private GridPane datePane; @Override public void start(Stage stage) { calendar = new MonthYear(); now = Calendar.getInstance(); // get current date time BorderPane displayPane = new BorderPane(); Font headingFont = Font.font("sans-serif", FontWeight.BOLD, FontPosture.REGULAR, 16); // month button prevMonthBtn = new Button(" { calendar.previousMonth(); updateDisplay(); }); // next month button nextMonthBtn = new Button(">"); nextMonthBtn.setOnAction(e -> { calendar.nextMonth(); updateDisplay(); }); monthLbl = new Label(); setMonthLbl(); monthLbl.setFont(headingFont); StackPane monthPane = new StackPane(); monthPane.getChildren().add(monthLbl); HBox monthBox = new HBox(TOP_BAR_SPACING); monthBox.getChildren().addAll(prevMonthBtn, monthPane, nextMonthBtn); // previous year button prevYearBtn = new Button(" { calendar.previousYear(); updateDisplay(); }); // next year button nextYearBtn = new Button(">"); nextYearBtn.setOnAction(e -> { calendar.nextYear(); updateDisplay(); }); yearLbl = new Label(); setYearLbl(); yearLbl.setFont(headingFont); StackPane yearPane = new StackPane(); yearPane.getChildren().add(yearLbl); HBox yearBox = new HBox(TOP_BAR_SPACING); yearBox.getChildren().addAll(prevYearBtn, yearPane, nextYearBtn); BorderPane topBar = new BorderPane(); topBar.setLeft(monthBox); topBar.setRight(yearBox); datePane = new GridPane(); for (int i = 0; i  

image text in transcribed

Calendar TUE FRI SAT WED THU 2 3 4 5 23 | 26 27

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle9i Database Administrator Implementation And Administration

Authors: Carol McCullough-Dieter

1st Edition

0619159006, 978-0619159009

More Books

Students explore these related Databases questions