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.

Page 7 of 12 FirstFirst ... 56789 ... LastLast
Results 151 to 175 of 284

Thread: library or component for Hijra date chooser

  1. #151

    Default Re: library for Hijra date chooser

    i think you talk about this part of code
    numBtn.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent event) {
                                JButton source = (JButton) event.getSource();
                                if (source.getText().length() == 0) {
     
                                    numBtn.setForeground(dateFontColor);
     
                                    return;
                                }
                                dayColorUpdate(true);
                                numBtn.setBackground(palletTableColor);
                                numBtn.setForeground(dateFontColor);
                                source.setForeground(todayBackColor);
    Here it is specified which button the user has clicked on

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

    Default Re: library for Hijra date chooser

    Can the code keep a reference to the button that was changed to orange so that that button can later be changed to a different color?

    If the length == 0 the button has nothing in it.

    Does that code compile without errors? numBtn is a local variable in the enclosing method.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #153

    Default Re: library for Hijra date chooser

    in the original code for Gregory date picker before we edit and convert to hijra this code and colors work Properly

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

    Default Re: library for Hijra date chooser

    code for Gregory date picker before we edit and convert to hijra this code and colors work Properly
    Good, look at the logic in the working code and copy those techniques to your code.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #155

    Default Re: library for Hijra date chooser

    I did not touch that part of the code and did not edit it. There was the same problem in Hijri

    --- Update ---

    in 2 code just this part is changed
     
                                da = newDay;
     
                                setDate();
    and in original
    Calendar cal = getCalendar();
                                cal.set(Calendar.DAY_OF_MONTH, newDay);
                                setDate(cal.getTime());


    --- Update ---

    original code
    int actionCommandId = 0;
                for (int i = 0; i < 6; i++) {
                    for (int j = 0; j < 7; j++) {
                        JButton numBtn = new JButton();
                        numBtn.setBorder(null);
                        numBtn.setHorizontalAlignment(SwingConstants.CENTER);
                        numBtn.setActionCommand(String
                                .valueOf(actionCommandId));
                        numBtn.setBackground(palletTableColor);
                        numBtn.setForeground(dateFontColor);
                        numBtn.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent event) {
                                JButton source = (JButton) event.getSource();
                                if (source.getText().length() == 0) {
                                    return;
                                }
                                dayColorUpdate(true);
                                source.setForeground(todayBackColor);
                                int newDay = Integer.parseInt(source.getText());
                                Calendar cal = getCalendar();
                                cal.set(Calendar.DAY_OF_MONTH, newDay);
                                setDate(cal.getTime());
     
                                dateDialog.setVisible(false);
                            }
                        });
     
                        if (j == 0 || j == 6) {
    //                        if (j == 5) {
                            numBtn.setForeground(weekendFontColor);
                        } else {
                            numBtn.setForeground(dateFontColor);
                        }
                        daysButton[i][j] = numBtn;
                        panel.add(numBtn);
                        actionCommandId++;
                    }
                }
     
                return panel;
            }
    after edi
     private JPanel createWeekAndDayPanal() {
     
                JPanel panel = new JPanel();
                panel.setFont(new Font("Tahoma", Font.PLAIN, 10));
                panel.setLayout(new GridLayout(7, 7));
                panel.setBackground(Color.white);
     
                for (int i = 0; i < 7; i++) {
                    cell = new JLabel(colname[i]);
                    cell.setHorizontalAlignment(JLabel.CENTER);
                    if (i == 6) {
                        cell.setForeground(weekendFontColor);
                    } else {
                        cell.setForeground(weekFontColor);
                    }
                    panel.add(cell);
                }
     
                int actionCommandId = 0;
                for (int i = 0; i < 6; i++) {
     
                    for (int j = 0; j < 7; j++) {
                        JButton numBtn = new JButton();
                        numBtn.setBorder(null);
                        numBtn.setHorizontalAlignment(SwingConstants.CENTER);
                        numBtn.setActionCommand(String.valueOf(actionCommandId));
                        numBtn.setBackground(palletTableColor);
                        numBtn.setForeground(dateFontColor);
                        numBtn.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent event) {
                                JButton source = (JButton) event.getSource();
                                if (source.getText().length() == 0) {
     
                                    numBtn.setForeground(dateFontColor);
     
                                    return;
                                }
                                dayColorUpdate(true);
                                numBtn.setBackground(palletTableColor);
                                numBtn.setForeground(dateFontColor);
                                source.setForeground(todayBackColor);
     
                                int newDay = Integer.parseInt(source.getText());
                                da = newDay;
     
                                setDate();
     
                                dateDialog.setVisible(false);
                            }
                        });
     
                        daysButton[i][j] = numBtn;
                        panel.add(numBtn);
                        actionCommandId++;
                        if (j == 6) {
                            numBtn.setForeground(weekendFontColor);
                        } else {
                            numBtn.setForeground(dateFontColor);
                        }
                    }
                }
     
                return panel;
            }

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

    Default Re: library for Hijra date chooser

    Where is the statement in the Original code that changed the color from orange to black when a new button was clicked when another button had already been clicked?
    Add some print statements to the original code so you can see where the statement is.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #157

    Default Re: library for Hijra date chooser

    in original
    private void dayColorUpdate(boolean isOldDay) {
                Calendar cal = getCalendar();
                int day = cal.get(Calendar.DAY_OF_MONTH);
                cal.set(Calendar.DAY_OF_MONTH, 1);
                int actionCommandId = day - 2 + cal.get(Calendar.DAY_OF_WEEK);
     
                int i = actionCommandId / 7;
                int j = actionCommandId % 7;
                if (isOldDay) {
                    daysButton[i][j].setForeground(dateFontColor);
                } else {
                    daysButton[i][j].setForeground(todayBackColor);
                }
            }
    in my code
    private void dayColorUpdate(boolean isOldDay) {
     
                ye = (Integer) yearSpin.getValue();
                mo = (Integer) monthSpin.getValue();
                System.out.println("spinner ye " + ye);
                System.out.println("spinner mo " + mo);
                Locale ar = new Locale("ar");
                DateTimeFormatter dayOfMoonNum = DateTimeFormatter.ofPattern("d", ar);
                DateTimeFormatter dayOfweekNum = DateTimeFormatter.ofPattern("c", ar);
                HijrahDate hijrahDate = HijrahChronology.INSTANCE.date(ye, mo, da);
                String MoondayNum = hijrahDate.format(dayOfMoonNum);
                String WeekdayNum = hijrahDate.format(dayOfweekNum);
                int WeekdayNumb = Integer.parseInt(WeekdayNum);
                int moondayNumb = Integer.parseInt(MoondayNum);
                int moondaysnumber = hijrahDate.lengthOfMonth();
                System.out.println("hijrahDate= " + hijrahDate);
                System.out.println("Number day-of-month   " + MoondayNum);
                System.out.println("Number day-of-Week   " + WeekdayNum);
                System.out.println("Number of days of the month   " + moondaysnumber);
     
                int actionCommandId = moondayNumb + 3 + WeekdayNumb;
                int i = actionCommandId / 7;
                int j = actionCommandId % 7;
                if (isOldDay) {
                    daysButton[i][j].setForeground(dateFontColor);
                    daysButton[i][6].setForeground(weekendFontColor);
                } else {
                    daysButton[i][j].setForeground(dateFontColor);
                    daysButton[i][6].setForeground(weekendFontColor);
                    daysButton[i][j].setForeground(todayBackColor);
                }
            }

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

    Default Re: library for Hijra date chooser

    Did you test your code? Does it work correctly?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #159

    Default Re: library for Hijra date chooser

    Do you think I would ask a question if my code was correct? I even sent you a picture of my code problem

    --- Update ---

    this is all my code now
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Cursor;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.Font;
    import java.awt.Frame;
    import java.awt.GridLayout;
    import java.awt.Point;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.FocusAdapter;
    import java.awt.event.FocusEvent;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowFocusListener;
    import java.text.Format;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.time.LocalDate;
    import java.time.chrono.HijrahChronology;
    import java.time.chrono.HijrahDate;
    import java.time.format.DateTimeFormatter;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.Locale;
     
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JSpinner;
    import javax.swing.JTextField;
    import javax.swing.SpinnerNumberModel;
    import javax.swing.SwingConstants;
    import javax.swing.SwingUtilities;
    import javax.swing.border.LineBorder;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;
     
    public class Hijrah extends JTextField {
     
        int ye;
        int mo;
        int da;
     
        String[] moonNames = {"ٱلْمُحَرَّم‎", "صَفَر‎", "رَبِيع ٱلْأَوَّل‎", "رَبِيع ٱلثَّانِي", "جُمَادَىٰ ٱلْأُولَىٰ", "جُمَادَىٰ ٱلثَّانِيَة", "رَجَب‎", "شَعْبَان‎", "رَمَضَان", "شَوَّال", "ذُو ٱلْقَعْدَة", "ذُو ٱلْحِجَّة"};
        //String[] moonNames = {"al-Muḥarram", "Ṣafar", "Rabīʿ al-ʾAwwal", "Rabīʿ ath-Thānī", "Jumadā al-ʾŪlā", "Jumādā ath-Thāniyah", "Rajab", "Shaʿbān", "Ramaḍān", "Shawwāl", "Ḏū al-Qaʿdah", "Ḏū al-Ḥijjah"};
        String colname[] = {"سب", "اح", "ثن", "ثل", "ار", "خم", "جم"};
    //            String colname[] = {"Sa", "sun", "Mon", "Tu", "We", "Th", "Fr"};
        JLabel cell;
        JLabel monthNameLabel = new JLabel();  // get name from array
     
        private static String DEFAULT_DATE_FORMAT = "yyyy/MM/dd";
        private static final int DIALOG_WIDTH = 270;
        private static final int DIALOG_HEIGHT = 210;
     
        private SimpleDateFormat dateFormat;
        private DatePanel datePanel = null;
        private JDialog dateDialog = null;
     
        public void hdate() {
            HijrahDate hijrahDate = HijrahDate.now();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
            String formatted = formatter.format(hijrahDate); // 07/03/1439 
            ye = Integer.parseInt(formatted.substring(0, 4));
            mo = Integer.parseInt(formatted.substring(5, 7));
            da = Integer.parseInt(formatted.substring(8, 10));
        }
     
    //    public Hijrah() {
    //        this();
    //    }
        public Hijrah(String dateFormatPattern, Date date) {
            this();
            DEFAULT_DATE_FORMAT = dateFormatPattern;
        }
     
        public Hijrah() {
            hdate();
            setDate();
            setEditable(false);
            setCursor(new Cursor(Cursor.HAND_CURSOR));
            addListeners();
        }
     
        private void addListeners() {
            addMouseListener(new MouseAdapter() {
                public void mouseClicked(MouseEvent paramMouseEvent) {
                    if (datePanel == null) {
                        datePanel = new DatePanel();
                    }
                    Point point = getLocationOnScreen();
                    point.y = point.y + 30;
                    showDateDialog(datePanel, point);
     
                }
            });
        }
     
        private void showDateDialog(DatePanel dateChooser, Point position) {
     
            Frame owner = (Frame) SwingUtilities
                    .getWindowAncestor(Hijrah.this);
            if (dateDialog == null || dateDialog.getOwner() != owner) {
                dateDialog = createDateDialog(owner, dateChooser);
            }
            dateDialog.setLocation(getAppropriateLocation(owner, position));
            dateDialog.setVisible(true);
     
        }
     
        private JDialog createDateDialog(Frame owner, JPanel contentPanel) {
     
            JDialog dialog = new JDialog(owner, "Date Selected", false);// Non-modal
    //        JDialog dialog = new JDialog(owner, "Date Selected", true);
            dialog.setUndecorated(true);
            dialog.getContentPane().add(contentPanel, BorderLayout.CENTER);
            dialog.pack();
            dialog.setSize(DIALOG_WIDTH, DIALOG_HEIGHT);
     
            dialog.addWindowFocusListener(new WindowFocusListener() {
                public void windowLostFocus(WindowEvent e) {
                    dialog.setVisible(false);
                }
     
                public void windowGainedFocus(WindowEvent e) {
                }
            });
     
            return dialog;
     
        }
     
        private Point getAppropriateLocation(Frame owner, Point position) {
            Point result = new Point(position);
            Point p = owner.getLocation();
            int offsetX = (position.x + DIALOG_WIDTH) - (p.x + owner.getWidth());
            int offsetY = (position.y + DIALOG_HEIGHT) - (p.y + owner.getHeight());
     
            if (offsetX > 0) {
                result.x -= offsetX;
            }
     
            if (offsetY > 0) {
                result.y -= offsetY;
            }
     
            return result;
        }
     
        private SimpleDateFormat getDefaultDateFormat() {
            if (dateFormat == null) {
                dateFormat = new SimpleDateFormat(DEFAULT_DATE_FORMAT);
            }
            return dateFormat;
        }
     
        public void setText() {
            setDate();
        }
     
        public void setDate() {
            super.setText(testMethod());   //<<<<< Changed
        }
     
        public Date getDate() {
     
            try {
                return getDefaultDateFormat().parse(getText());
            } catch (ParseException e) {
                return new Date();
            }
        }
     
        private class DatePanel extends JPanel implements ChangeListener {
     
            int startYear = 1;
            int lastYear = 99999;
     
            Color backGroundColor = Color.gray;
            Color palletTableColor = Color.white;
            Color todayBackColor = Color.orange;
            Color weekFontColor = Color.blue;
            Color dateFontColor = Color.black;
            Color weekendFontColor = Color.red;
     
            Color controlLineColor = Color.GREEN;
            Color controlTextColor = new java.awt.Color(153, 0, 153);
            Color controlMoonnameTextColor = Color.BLUE;
     
            JSpinner yearSpin;
            JSpinner monthSpin;
            JButton[][] daysButton = new JButton[8][7];
     
            DatePanel() {
     
                setLayout(new BorderLayout());
                setBorder(new LineBorder(backGroundColor, 2));
                setBackground(backGroundColor);
     
                JPanel topYearAndMonth = createYearAndMonthPanal();
                add(topYearAndMonth, BorderLayout.NORTH);
                JPanel centerWeekAndDay = createWeekAndDayPanal();
                add(centerWeekAndDay, BorderLayout.CENTER);
     
                reflushWeekAndDay();
            }
     
            private JPanel createYearAndMonthPanal() {
                Font font = new Font("Tahoma", Font.BOLD, 10);
                Calendar cal = getCalendar();
                int currentYear = cal.get(Calendar.YEAR);
                int currentMonth = cal.get(Calendar.MONTH) + 1;
                JPanel panel = new JPanel();
                panel.setLayout(new FlowLayout());
                panel.setBackground(controlLineColor);
                JLabel yearLabel = new JLabel("السنة");
                yearLabel.setForeground(controlTextColor);
                yearLabel.setHorizontalAlignment(SwingConstants.CENTER);
                yearLabel.setVerticalAlignment(SwingConstants.CENTER);
                yearLabel.setFont(font);
     
                panel.add(yearLabel);
                yearSpin = new JSpinner(new SpinnerNumberModel(currentYear,
                        startYear, lastYear, 1));
     
                yearSpin.setPreferredSize(new Dimension(60, 30));
                yearSpin.setName("Month");
                yearSpin.setEditor(new JSpinner.NumberEditor(yearSpin, "####"));
                yearSpin.addChangeListener(this);
                panel.add(yearSpin);
                monthSpin = new JSpinner(new SpinnerNumberModel(currentMonth, 1,
                        12, 1));
     
                monthSpin.setPreferredSize(new Dimension(45, 30));
                monthSpin.setName("Year");
                monthSpin.addChangeListener(this);
                monthNameLabel.setPreferredSize(new Dimension(65, 20));
                monthNameLabel.setForeground(controlTextColor);
                monthNameLabel.setHorizontalAlignment(SwingConstants.CENTER);
                monthNameLabel.setVerticalAlignment(SwingConstants.CENTER);
                monthNameLabel.setFont(font);
                monthNameLabel.setText(moonNames[(Integer) monthSpin.getValue() - 1]);  // get name from array
                panel.add(monthNameLabel);
     
                panel.add(monthSpin);
     
                JLabel monthLabel = new JLabel("الشهر");
                monthLabel.setForeground(controlTextColor);
                monthLabel.setHorizontalAlignment(SwingConstants.CENTER);
                monthLabel.setVerticalAlignment(SwingConstants.CENTER);
                monthLabel.setFont(font);
                panel.add(monthLabel);
     
                return panel;
            }
     
            private JPanel createWeekAndDayPanal() {
     
                JPanel panel = new JPanel();
                panel.setFont(new Font("Tahoma", Font.PLAIN, 10));
                panel.setLayout(new GridLayout(7, 7));
                panel.setBackground(Color.white);
     
                for (int i = 0; i < 7; i++) {
                    cell = new JLabel(colname[i]);
                    cell.setHorizontalAlignment(JLabel.CENTER);
                    if (i == 6) {
                        cell.setForeground(weekendFontColor);
                    } else {
                        cell.setForeground(weekFontColor);
                    }
                    panel.add(cell);
                }
     
                int actionCommandId = 0;
                for (int i = 0; i < 6; i++) {
     
                    for (int j = 0; j < 7; j++) {
                        JButton numBtn = new JButton();
                        numBtn.setBorder(null);
                        numBtn.setHorizontalAlignment(SwingConstants.CENTER);
                        numBtn.setActionCommand(String.valueOf(actionCommandId));
                        numBtn.setBackground(palletTableColor);
                        numBtn.setForeground(dateFontColor);
                        numBtn.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent event) {
                                JButton source = (JButton) event.getSource();
                                if (source.getText().length() == 0) {
     
                                    numBtn.setForeground(dateFontColor);
     
                                    return;
                                }
                                dayColorUpdate(true);
                                numBtn.setBackground(palletTableColor);
                                numBtn.setForeground(dateFontColor);
                                source.setForeground(todayBackColor);
     
                                int newDay = Integer.parseInt(source.getText());
                                da = newDay;
     
                                setDate();
     
                                dateDialog.setVisible(false);
                            }
                        });
     
                        daysButton[i][j] = numBtn;
                        panel.add(numBtn);
                        actionCommandId++;
                        if (j == 6) {
                            numBtn.setForeground(weekendFontColor);
                        } else {
                            numBtn.setForeground(dateFontColor);
                        }
                    }
                }
     
                return panel;
            }
     
            private Calendar getCalendar() {
     
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(getDate());
                return calendar;
            }
     
            private int getSelectedYear() {
                return ((Integer) yearSpin.getValue()).intValue();
            }
     
            private int getSelectedMonth() {
                return ((Integer) monthSpin.getValue()).intValue();
            }
     
            private void dayColorUpdate(boolean isOldDay) {
     
                ye = (Integer) yearSpin.getValue();
                mo = (Integer) monthSpin.getValue();
                System.out.println("spinner ye " + ye);
                System.out.println("spinner mo " + mo);
                Locale ar = new Locale("ar");
                DateTimeFormatter dayOfMoonNum = DateTimeFormatter.ofPattern("d", ar);
                DateTimeFormatter dayOfweekNum = DateTimeFormatter.ofPattern("c", ar);
                HijrahDate hijrahDate = HijrahChronology.INSTANCE.date(ye, mo, da);
                String MoondayNum = hijrahDate.format(dayOfMoonNum);
                String WeekdayNum = hijrahDate.format(dayOfweekNum);
                int WeekdayNumb = Integer.parseInt(WeekdayNum);
                int moondayNumb = Integer.parseInt(MoondayNum);
                int moondaysnumber = hijrahDate.lengthOfMonth();
                System.out.println("hijrahDate= " + hijrahDate);
                System.out.println("Number day-of-month   " + MoondayNum);
                System.out.println("Number day-of-Week   " + WeekdayNum);
                System.out.println("Number of days of the month   " + moondaysnumber);
     
                int actionCommandId = moondayNumb + 3 + WeekdayNumb;
                int i = actionCommandId / 7;
                int j = actionCommandId % 7;
                if (isOldDay) {
                    daysButton[i][j].setForeground(dateFontColor);
                    daysButton[i][6].setForeground(weekendFontColor);
                } else {
                    daysButton[i][j].setForeground(dateFontColor);
                    daysButton[i][6].setForeground(weekendFontColor);
                    daysButton[i][j].setForeground(todayBackColor);
                }
            }
     
            private void reflushWeekAndDay() {
     
                ye = (Integer) yearSpin.getValue();
                mo = (Integer) monthSpin.getValue();
                System.out.println("spinner ye " + ye);
                System.out.println("spinner mo " + mo);
     
                Locale ar = new Locale("ar");
                DateTimeFormatter dayOfMoonNum = DateTimeFormatter.ofPattern("d", ar);
                DateTimeFormatter dayOfweekNum = DateTimeFormatter.ofPattern("c", ar);
                HijrahDate hijrahDate = HijrahChronology.INSTANCE.date(ye, mo, da);
                HijrahChronology crono = hijrahDate.getChronology();
                HijrahDate date = crono.date(ye, mo, da);
                System.out.println("crono date= " + date);
                String MoondayNum = hijrahDate.format(dayOfMoonNum);
                String WeekdayNum = hijrahDate.format(dayOfweekNum);
                int WeekdayNumb = Integer.parseInt(WeekdayNum);
                int moondayNumb = Integer.parseInt(MoondayNum);
                int moondaysnumber = hijrahDate.lengthOfMonth();
                System.out.println("hijrahDate= " + hijrahDate);
                System.out.println("Number day-of-month   " + moondayNumb);
                System.out.println("Number day-of-Week   " + WeekdayNumb);
                System.out.println("Number of days of the month   " + moondaysnumber);
                int maxDayNo = moondaysnumber;
                System.out.println("Number of days of the month   " + moondaysnumber);
                int dayNo = -3 - WeekdayNumb;
    //            int dayNo = 0;
                System.out.println("dayNo   " + dayNo);
                for (int i = 0; i < 6; i++) {
                    for (int j = 0; j < 7; j++) {
                        String s = "";
                        if (dayNo >= 1 && dayNo <= maxDayNo) {
                            s = String.valueOf(dayNo);
                        }
                        daysButton[i][j].setText(s);
                        dayNo++;
                        if (daysButton[i][j].getText().equals("")) {
                            daysButton[i][j].setVisible(false);
                        } else {
                            daysButton[i][j].setVisible(true);
                        }
     
                    }
     
                }
                dayColorUpdate(false);
            }
     
            public void stateChanged(ChangeEvent e) {
                dayColorUpdate(true);
                JSpinner source = (JSpinner) e.getSource();
                Calendar cal = getCalendar();
                if (source.getName().equals("Year")) {
                    cal.set(Calendar.YEAR, getSelectedYear());
                } else {
                    cal.set(Calendar.MONTH, getSelectedMonth() - 1);
                }
                setDate();
                reflushWeekAndDay();
                mothnam();
            }
     
        }
     
        public void mothnam() {
            monthNameLabel.setText(moonNames[mo - 1]);
        }
     
        String testMethod() {                  //  ADDED
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
            HijrahDate today = HijrahChronology.INSTANCE.date(ye, mo, da);
            String formatted = formatter.format(today); // 07/03/1439
    //        System.out.println("hijrahDate " + formatted);
            return formatted.toString(); //<<<<<< ADDED
        }
     
    }

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

    Default Re: library for Hijra date chooser

    It looks like the same kind of problem where the extra blank line of buttons was added at the top of the calendar. Some arithmetic is needed to compute the correct i,j values.

    You need to look at how the old code computed where to change the color and use that technique in your code to find the place where the orange button is located so its color can be changed to black.


    It is better to always test the code after each change is made to it. Making more than one change at a time without testing leads to more complexity.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: library for Hijra date chooser

    Some things to consider:
    choose a date to be changed: Note its day of month and day of week

    At the location in the code where the change is to be done:
    print out all the values that can be used to compute the row and column for the location of the button to change
    For example: mo and da. And what ever can be extracted from the HijrahDate object.

    Given those values you should be able to compute the row,column of the button to be changed.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #162

    Default Re: library for Hijra date chooser

    I did not notice in the original class Calendar.DAY_OF_WEEK What does it do?
    That is why I do not know how much of the Hijri calendar I should devote to it

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

    Default Re: library for Hijra date chooser

    Read the API doc for the Calendar class for a description of what it is and how to use it.
    http://docs.oracle.com/javase/8/docs/api/index.html

    Also write a small test program that prints out the value returned by the get method.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #164

    Default Re: library for Hijra date chooser

    The getValue() method of java.time.DayOfWeek is an in-built function in Java which return the integer value assigned to the 7 days of the week, i.e, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday
    but When I set this value as well, the color shapes still do not work

    private void dayColorUpdate(boolean isOldDay) {
     
                ye = (Integer) yearSpin.getValue();
                mo = (Integer) monthSpin.getValue();
                System.out.println("spinner ye " + ye);
                System.out.println("spinner mo " + mo);
                Locale ar = new Locale("ar");
                DateTimeFormatter dayOfMoonNum = DateTimeFormatter.ofPattern("d", ar);
                DateTimeFormatter weekNumOfMonth = DateTimeFormatter.ofPattern("e", ar);
     
                HijrahDate hijrahDate = HijrahChronology.INSTANCE.date(ye, mo, da);
                String MoondayNum = hijrahDate.format(dayOfMoonNum);
                String dayofweek = hijrahDate.format(weekNumOfMonth);
                System.out.println("localized day-of-week= "+dayofweek);
                int daysofweek = Integer.parseInt(dayofweek);
                int moondayNumb = Integer.parseInt(MoondayNum);
                int moondaysnumber = hijrahDate.lengthOfMonth();
                System.out.println("hijrahDate= " + hijrahDate);
                System.out.println("Number day-of-month   " + MoondayNum);
     
                System.out.println("Number of days of the month   " + moondaysnumber);
                System.out.println("The day it was last clicked= "+moondayNumb);
                int actionCommandId = moondayNumb + 3 + daysofweek;
     
                int i = actionCommandId / 7;
                System.out.println("i= "+i);
                int j = actionCommandId % 7;
                System.out.println("i= "+i);
                if (isOldDay) {
                    daysButton[i][j].setForeground(dateFontColor);
                    daysButton[i][6].setForeground(weekendFontColor);
                } else {
                    daysButton[i][j].setForeground(dateFontColor);
                    daysButton[i][6].setForeground(weekendFontColor);
                    daysButton[i][j].setForeground(todayBackColor);
                }
            }


    --- Update ---

    original
     private void dayColorUpdate(boolean isOldDay) {
                Calendar cal = getCalendar();
                int day = cal.get(Calendar.DAY_OF_MONTH);
     
                cal.set(Calendar.DAY_OF_MONTH, 1);
                int actionCommandId = day - 2 + cal.get(Calendar.DAY_OF_WEEK);
                int i = actionCommandId / 7;
                System.out.println("i= " + i);
                int j = actionCommandId % 7;
                System.out.println("i= " + i);
                if (isOldDay) {
                    daysButton[i][j].setForeground(dateFontColor);
                } else {
                    daysButton[i][j].setForeground(todayBackColor);
                }
            }


    --- Update ---

    this is my all code now
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Cursor;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.Font;
    import java.awt.Frame;
    import java.awt.GridLayout;
    import java.awt.Point;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.FocusAdapter;
    import java.awt.event.FocusEvent;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowFocusListener;
    import java.text.Format;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.time.LocalDate;
    import java.time.chrono.HijrahChronology;
    import java.time.chrono.HijrahDate;
    import java.time.format.DateTimeFormatter;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.Locale;
     
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JSpinner;
    import javax.swing.JTextField;
    import javax.swing.SpinnerNumberModel;
    import javax.swing.SwingConstants;
    import javax.swing.SwingUtilities;
    import javax.swing.border.LineBorder;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;
     
    public class Hijrah extends JTextField {
     
        int ye;
        int mo;
        int da;
     
        String[] moonNames = {"ٱلْمُحَرَّم‎", "صَفَر‎", "رَبِيع ٱلْأَوَّل‎", "رَبِيع ٱلثَّانِي", "جُمَادَىٰ ٱلْأُولَىٰ", "جُمَادَىٰ ٱلثَّانِيَة", "رَجَب‎", "شَعْبَان‎", "رَمَضَان", "شَوَّال", "ذُو ٱلْقَعْدَة", "ذُو ٱلْحِجَّة"};
        //String[] moonNames = {"al-Muḥarram", "Ṣafar", "Rabīʿ al-ʾAwwal", "Rabīʿ ath-Thānī", "Jumadā al-ʾŪlā", "Jumādā ath-Thāniyah", "Rajab", "Shaʿbān", "Ramaḍān", "Shawwāl", "Ḏū al-Qaʿdah", "Ḏū al-Ḥijjah"};
        String colname[] = {"سب", "اح", "ثن", "ثل", "ار", "خم", "جم"};
    //            String colname[] = {"Sa", "sun", "Mon", "Tu", "We", "Th", "Fr"};
        JLabel cell;
        JLabel monthNameLabel = new JLabel();  // get name from array
     
        private static String DEFAULT_DATE_FORMAT = "yyyy/MM/dd";
        private static final int DIALOG_WIDTH = 270;
        private static final int DIALOG_HEIGHT = 210;
     
        private SimpleDateFormat dateFormat;
        private DatePanel datePanel = null;
        private JDialog dateDialog = null;
     
        public void hdate() {
            HijrahDate hijrahDate = HijrahDate.now();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
            String formatted = formatter.format(hijrahDate); // 07/03/1439 
            ye = Integer.parseInt(formatted.substring(0, 4));
            mo = Integer.parseInt(formatted.substring(5, 7));
            da = Integer.parseInt(formatted.substring(8, 10));
        }
     
    //    public Hijrah() {
    //        this();
    //    }
        public Hijrah(String dateFormatPattern, Date date) {
            this();
            DEFAULT_DATE_FORMAT = dateFormatPattern;
        }
     
        public Hijrah() {
            hdate();
            setDate();
            setEditable(false);
            setCursor(new Cursor(Cursor.HAND_CURSOR));
            addListeners();
        }
     
        private void addListeners() {
            addMouseListener(new MouseAdapter() {
                public void mouseClicked(MouseEvent paramMouseEvent) {
                    if (datePanel == null) {
                        datePanel = new DatePanel();
                    }
                    Point point = getLocationOnScreen();
                    point.y = point.y + 30;
                    showDateDialog(datePanel, point);
     
                }
            });
        }
     
        private void showDateDialog(DatePanel dateChooser, Point position) {
     
            Frame owner = (Frame) SwingUtilities
                    .getWindowAncestor(Hijrah.this);
            if (dateDialog == null || dateDialog.getOwner() != owner) {
                dateDialog = createDateDialog(owner, dateChooser);
            }
            dateDialog.setLocation(getAppropriateLocation(owner, position));
            dateDialog.setVisible(true);
     
        }
     
        private JDialog createDateDialog(Frame owner, JPanel contentPanel) {
     
            JDialog dialog = new JDialog(owner, "Date Selected", false);// Non-modal
    //        JDialog dialog = new JDialog(owner, "Date Selected", true);
            dialog.setUndecorated(true);
            dialog.getContentPane().add(contentPanel, BorderLayout.CENTER);
            dialog.pack();
            dialog.setSize(DIALOG_WIDTH, DIALOG_HEIGHT);
     
            dialog.addWindowFocusListener(new WindowFocusListener() {
                public void windowLostFocus(WindowEvent e) {
                    dialog.setVisible(false);
                }
     
                public void windowGainedFocus(WindowEvent e) {
                }
            });
     
            return dialog;
     
        }
     
        private Point getAppropriateLocation(Frame owner, Point position) {
            Point result = new Point(position);
            Point p = owner.getLocation();
            int offsetX = (position.x + DIALOG_WIDTH) - (p.x + owner.getWidth());
            int offsetY = (position.y + DIALOG_HEIGHT) - (p.y + owner.getHeight());
     
            if (offsetX > 0) {
                result.x -= offsetX;
            }
     
            if (offsetY > 0) {
                result.y -= offsetY;
            }
     
            return result;
        }
     
        private SimpleDateFormat getDefaultDateFormat() {
            if (dateFormat == null) {
                dateFormat = new SimpleDateFormat(DEFAULT_DATE_FORMAT);
            }
            return dateFormat;
        }
     
        public void setText() {
            setDate();
        }
     
        public void setDate() {
            super.setText(testMethod());   //<<<<< Changed
        }
     
        public Date getDate() {
     
            try {
                return getDefaultDateFormat().parse(getText());
            } catch (ParseException e) {
                return new Date();
            }
        }
     
        private class DatePanel extends JPanel implements ChangeListener {
     
            int startYear = 1;
            int lastYear = 99999;
     
            Color backGroundColor = Color.gray;
            Color palletTableColor = Color.white;
            Color todayBackColor = Color.orange;
            Color weekFontColor = Color.blue;
            Color dateFontColor = Color.black;
            Color weekendFontColor = Color.red;
     
            Color controlLineColor = Color.GREEN;
            Color controlTextColor = new java.awt.Color(153, 0, 153);
            Color controlMoonnameTextColor = Color.BLUE;
     
            JSpinner yearSpin;
            JSpinner monthSpin;
            JButton[][] daysButton = new JButton[8][7];
     
            DatePanel() {
     
                setLayout(new BorderLayout());
                setBorder(new LineBorder(backGroundColor, 2));
                setBackground(backGroundColor);
     
                JPanel topYearAndMonth = createYearAndMonthPanal();
                add(topYearAndMonth, BorderLayout.NORTH);
                JPanel centerWeekAndDay = createWeekAndDayPanal();
                add(centerWeekAndDay, BorderLayout.CENTER);
     
                reflushWeekAndDay();
            }
     
            private JPanel createYearAndMonthPanal() {
                Font font = new Font("Tahoma", Font.BOLD, 10);
                Calendar cal = getCalendar();
                int currentYear = cal.get(Calendar.YEAR);
                int currentMonth = cal.get(Calendar.MONTH) + 1;
                JPanel panel = new JPanel();
                panel.setLayout(new FlowLayout());
                panel.setBackground(controlLineColor);
                JLabel yearLabel = new JLabel("السنة");
                yearLabel.setForeground(controlTextColor);
                yearLabel.setHorizontalAlignment(SwingConstants.CENTER);
                yearLabel.setVerticalAlignment(SwingConstants.CENTER);
                yearLabel.setFont(font);
     
                panel.add(yearLabel);
                yearSpin = new JSpinner(new SpinnerNumberModel(currentYear,
                        startYear, lastYear, 1));
     
                yearSpin.setPreferredSize(new Dimension(60, 30));
                yearSpin.setName("Month");
                yearSpin.setEditor(new JSpinner.NumberEditor(yearSpin, "####"));
                yearSpin.addChangeListener(this);
                panel.add(yearSpin);
                monthSpin = new JSpinner(new SpinnerNumberModel(currentMonth, 1,
                        12, 1));
     
                monthSpin.setPreferredSize(new Dimension(45, 30));
                monthSpin.setName("Year");
                monthSpin.addChangeListener(this);
                monthNameLabel.setPreferredSize(new Dimension(65, 20));
                monthNameLabel.setForeground(controlTextColor);
                monthNameLabel.setHorizontalAlignment(SwingConstants.CENTER);
                monthNameLabel.setVerticalAlignment(SwingConstants.CENTER);
                monthNameLabel.setFont(font);
                monthNameLabel.setText(moonNames[(Integer) monthSpin.getValue() - 1]);  // get name from array
                panel.add(monthNameLabel);
     
                panel.add(monthSpin);
     
                JLabel monthLabel = new JLabel("الشهر");
                monthLabel.setForeground(controlTextColor);
                monthLabel.setHorizontalAlignment(SwingConstants.CENTER);
                monthLabel.setVerticalAlignment(SwingConstants.CENTER);
                monthLabel.setFont(font);
                panel.add(monthLabel);
     
                return panel;
            }
     
            private JPanel createWeekAndDayPanal() {
     
                JPanel panel = new JPanel();
                panel.setFont(new Font("Tahoma", Font.PLAIN, 10));
                panel.setLayout(new GridLayout(7, 7));
                panel.setBackground(Color.white);
     
                for (int i = 0; i < 7; i++) {
                    cell = new JLabel(colname[i]);
                    cell.setHorizontalAlignment(JLabel.CENTER);
                    if (i == 6) {
                        cell.setForeground(weekendFontColor);
                    } else {
                        cell.setForeground(weekFontColor);
                    }
                    panel.add(cell);
                }
     
                int actionCommandId = 0;
                for (int i = 0; i < 6; i++) {
     
                    for (int j = 0; j < 7; j++) {
                        JButton numBtn = new JButton();
                        numBtn.setBorder(null);
                        numBtn.setHorizontalAlignment(SwingConstants.CENTER);
                        numBtn.setActionCommand(String.valueOf(actionCommandId));
                        numBtn.setBackground(palletTableColor);
                        numBtn.setForeground(dateFontColor);
                        numBtn.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent event) {
                                JButton source = (JButton) event.getSource();
                                if (source.getText().length() == 0) {
     
                                    numBtn.setForeground(dateFontColor);
     
                                    return;
                                }
                                dayColorUpdate(true);
                                numBtn.setBackground(palletTableColor);
                                numBtn.setForeground(dateFontColor);
                                source.setForeground(todayBackColor);
     
                                int newDay = Integer.parseInt(source.getText());
                                da = newDay;
     
                                setDate();
     
                                dateDialog.setVisible(false);
                            }
                        });
     
                        daysButton[i][j] = numBtn;
                        panel.add(numBtn);
                        actionCommandId++;
                        if (j == 6) {
                            numBtn.setForeground(weekendFontColor);
                        } else {
                            numBtn.setForeground(dateFontColor);
                        }
                    }
                }
     
                return panel;
            }
     
            private Calendar getCalendar() {
     
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(getDate());
                return calendar;
            }
     
            private int getSelectedYear() {
                return ((Integer) yearSpin.getValue()).intValue();
            }
     
            private int getSelectedMonth() {
                return ((Integer) monthSpin.getValue()).intValue();
            }
     
            private void dayColorUpdate(boolean isOldDay) {
     
                ye = (Integer) yearSpin.getValue();
                mo = (Integer) monthSpin.getValue();
                System.out.println("spinner ye " + ye);
                System.out.println("spinner mo " + mo);
                Locale ar = new Locale("ar");
                DateTimeFormatter dayOfMoonNum = DateTimeFormatter.ofPattern("d", ar);
                DateTimeFormatter dayOfweekNum = DateTimeFormatter.ofPattern("c", ar);
                HijrahDate hijrahDate = HijrahChronology.INSTANCE.date(ye, mo, da);
                String MoondayNum = hijrahDate.format(dayOfMoonNum);
                String WeekdayNum = hijrahDate.format(dayOfweekNum);
                int WeekdayNumb = Integer.parseInt(WeekdayNum);
                int moondayNumb = Integer.parseInt(MoondayNum);
                int moondaysnumber = hijrahDate.lengthOfMonth();
                System.out.println("hijrahDate= " + hijrahDate);
                System.out.println("Number day-of-month   " + MoondayNum);
                System.out.println("Number day-of-Week   " + WeekdayNum);
                System.out.println("Number of days of the month   " + moondaysnumber);
     
                int actionCommandId = moondayNumb + 2 + WeekdayNumb;
                int i = actionCommandId / 7;
                int j = actionCommandId % 7;
                if (isOldDay) {
                    daysButton[i][j].setForeground(dateFontColor);
                    daysButton[i][6].setForeground(weekendFontColor);
                } else {
                    daysButton[i][j].setForeground(dateFontColor);
                    daysButton[i][6].setForeground(weekendFontColor);
                    daysButton[i][j].setForeground(todayBackColor);
                }
            }
     
            private void reflushWeekAndDay() {
     
                ye = (Integer) yearSpin.getValue();
                mo = (Integer) monthSpin.getValue();
                System.out.println("spinner ye " + ye);
                System.out.println("spinner mo " + mo);
     
                Locale ar = new Locale("ar");
                DateTimeFormatter dayOfMoonNum = DateTimeFormatter.ofPattern("d", ar);
                DateTimeFormatter dayOfweekNum = DateTimeFormatter.ofPattern("c", ar);
                HijrahDate hijrahDate = HijrahChronology.INSTANCE.date(ye, mo, da);
                HijrahChronology crono = hijrahDate.getChronology();
                HijrahDate date = crono.date(ye, mo, da);
                System.out.println("crono date= " + date);
                String MoondayNum = hijrahDate.format(dayOfMoonNum);
                String WeekdayNum = hijrahDate.format(dayOfweekNum);
                int WeekdayNumb = Integer.parseInt(WeekdayNum);
                int moondayNumb = Integer.parseInt(MoondayNum);
                int moondaysnumber = hijrahDate.lengthOfMonth();
                System.out.println("hijrahDate= " + hijrahDate);
                System.out.println("Number day-of-month   " + moondayNumb);
                System.out.println("Number day-of-Week   " + WeekdayNumb);
                System.out.println("Number of days of the month   " + moondaysnumber);
                int maxDayNo = moondaysnumber;
                System.out.println("Number of days of the month   " + moondaysnumber);
                int dayNo = -2 - WeekdayNumb;
    //            int dayNo = 0;
                System.out.println("dayNo   " + dayNo);
                for (int i = 0; i < 6; i++) {
                    for (int j = 0; j < 7; j++) {
                        String s = "";
                        if (dayNo >= 1 && dayNo <= maxDayNo) {
                            s = String.valueOf(dayNo);
                        }
                        daysButton[i][j].setText(s);
                        dayNo++;
                        if (daysButton[i][j].getText().equals("")) {
                            daysButton[i][j].setVisible(false);
                        } else {
                            daysButton[i][j].setVisible(true);
     
                        }
     
                    }
     
                }
                dayColorUpdate(false);
            }
     
            public void stateChanged(ChangeEvent e) {
                dayColorUpdate(true);
                JSpinner source = (JSpinner) e.getSource();
                Calendar cal = getCalendar();
                if (source.getName().equals("Year")) {
                    cal.set(Calendar.YEAR, getSelectedYear());
                } else {
                    cal.set(Calendar.MONTH, getSelectedMonth() - 1);
                }
                setDate();
                reflushWeekAndDay();
                mothnam();
            }
     
        }
     
        public void mothnam() {
            monthNameLabel.setText(moonNames[mo - 1]);
        }
     
        String testMethod() {                  //  ADDED
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
            HijrahDate today = HijrahChronology.INSTANCE.date(ye, mo, da);
            String formatted = formatter.format(today); // 07/03/1439
    //        System.out.println("hijrahDate " + formatted);
            return formatted.toString(); //<<<<<< ADDED
        }
     
    }

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

    Default Re: library for Hijra date chooser

    Did you see this:
    Some things to consider:
    choose a date to be changed: Note its day of month and day of week

    At the location in the code where the change is to be done:
    print out all the values that can be used to compute the row and column for the location of the button to change
    For example: mo and da. And what ever can be extracted from the HijrahDate object.

    Given those values you should be able to compute the row,column of the button to be changed.
    You are writing code before you have a solution.

    Select a date: For example 1442/09/17
    then write down the row, column for that date: third row and sixth column
    Next Write down
    what values you have to help in the computation to get those values
    how you are going to use those values to get the row,column for a given date.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #166

    Default Re: library for Hijra date chooser

    Why is the output of the buttons in my code different from the original code?
    in the my code when i click on buten text
    numBtn.getText();10spinner ye 1442
    in the original code
    numBtn.getText();10i= 1

    --- Update ---

    I'm totally confused I do not know where to start now and what to do

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

    Default Re: library for Hijra date chooser

    Where is the code with this: numBtn.getText();

    I do not see it in the code from post#164
    If you don't understand my answer, don't ignore it, ask a question.

  18. #168

    Default Re: library for Hijra date chooser

    Select a date: For example 1442/09/17
    then write down the row, column for that date: third row and sixth column --> it is Fourth row and sixth column
    There is a first row, but we have hidden buttons

    --- Update ---

    i now add print in createWeekAndDayPanal() after
     return;
                                }
    System.out.println("numBtn.getText();" + numBtn.getText());
    I'm totally confused I do not know where to start now and what to do

    --- Update ---

    Since I'm working on unresolved code with trial and error, I backed up, and another reason I always post code here is because you know what I did and a backup of Stay here

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

    Default Re: library for Hijra date chooser

    What values do you have that you can use to compute the row, column values of Fourth row and sixth column?

    A problem is with the "it is not a problem" code that allows the first row to be all blanks.


    I always post code here is because you know what I did
    The problem with the posted code is that there has been no discussion of the techniques that are needed to solve a problem and the code doesn't have any comments saying what has changed and what it is trying to do.
    If you don't understand my answer, don't ignore it, ask a question.

  20. #170

    Default Re: library for Hijra date chooser

    When we click on the baton, receive the value written on the baton and this button color turn to orang , and if another baton's is not equal to this baton, their color will change by default
    For example, when button number 2 is clicked, its color turns orange by default, and we write a for loop so that the other buttons have the same color as before. in this part of code create this solution
    public void actionPerformed(ActionEvent event)
    Do you think this is more logical?

    --- Update ---

    i change this part of code and fixed problem now just i must set today color to orange when dialogbox is first time loaded you think is this solution true?
    private void dayColorUpdate(boolean isOldDay) {
     
                ye = (Integer) yearSpin.getValue();
                mo = (Integer) monthSpin.getValue();
                System.out.println("spinner ye " + ye);
                System.out.println("spinner mo " + mo);
                Locale ar = new Locale("ar");
                DateTimeFormatter dayOfMoonNum = DateTimeFormatter.ofPattern("d", ar);
                DateTimeFormatter dayOfweekNum = DateTimeFormatter.ofPattern("c", ar);
                HijrahDate hijrahDate = HijrahChronology.INSTANCE.date(ye, mo, da);
                String MoondayNum = hijrahDate.format(dayOfMoonNum);
                String WeekdayNum = hijrahDate.format(dayOfweekNum);
                int WeekdayNumb = Integer.parseInt(WeekdayNum);
                int moondayNumb = Integer.parseInt(MoondayNum);
                int moondaysnumber = hijrahDate.lengthOfMonth();
                System.out.println("hijrahDate= " + hijrahDate);
                System.out.println("Number day-of-month   " + MoondayNum);
                System.out.println("Number day-of-Week   " + WeekdayNum);
                System.out.println("Number of days of the month   " + moondaysnumber);
     
                int actionCommandId = moondayNumb + 2 + WeekdayNumb;
               int i = actionCommandId / 7;
               int j = actionCommandId % 7;
                if (isOldDay) {
                    daysButton[i][j].setForeground(dateFontColor);
                    daysButton[i][6].setForeground(weekendFontColor);
                } else {
                    daysButton[i][j].setForeground(dateFontColor);
                  daysButton[i][6].setForeground(weekendFontColor);
                    daysButton[i][j].setForeground(todayBackColor);
                }
     
            }
    Last edited by cnmeysam; April 29th, 2021 at 04:39 PM.

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

    Default Re: library for Hijra date chooser

    is this solution true?
    Does it work when you test it?
    If you don't understand my answer, don't ignore it, ask a question.

  22. #172

    Default Re: library for Hijra date chooser

    90% is work now but now show 2 day's get orange
    replace with this
     private void dayColorUpdate(boolean isOldDay) {
     
                String s = String.valueOf(da);
     
                for (int a = 0; a < 6; a++) {
                    for (int b = 0; b < 7; b++) {
                        daysButton[a][b].setForeground(dateFontColor);
                        daysButton[a][6].setForeground(weekendFontColor);
                        if (daysButton[a][b].getText().equals(s)) {
                            daysButton[a][b].setForeground(todayBackColor);
                        }
                    }
                }
            }
    i don't know now what is problem

    --- Update ---

    The baton that was orange and the baton that I just clicked and the same cycle continues, the last 2 batons always turn orange

    --- Update ---

    I do not understand where the logic of this code is wrong

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

    Default Re: library for Hijra date chooser

    That code would be better if the statement that doesn't use b were not inside the for(b) loop:
                for (int a = 0; a < 6; a++) {
                   for (int b = 0; b < 7; b++) {
                        daysButton[a][b].setForeground(dateFontColor);
                         if (daysButton[a][b].getText().equals(s)) {
                            daysButton[a][b].setForeground(todayBackColor);
                         }
                    }
                 daysButton[a][6].setForeground(weekendFontColor);
    If you don't understand my answer, don't ignore it, ask a question.

  24. #174

    Default Re: library for Hijra date chooser

    this part is for weekend turn red
    daysButton[a][6].setForeground(weekendFontColor);

    --- Update ---

    The baton that was orange and the baton that I just clicked and the same cycle continues, the last 2 batons always turn orange

    I do not understand where the logic of this code is wrong

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

    Default Re: library for Hijra date chooser

    I do not understand where the logic of this code is wrong
    Add some print statements that print out all the values for when the color is set to orange.
    If you don't understand my answer, don't ignore it, ask a question.

Page 7 of 12 FirstFirst ... 56789 ... LastLast

Similar Threads

  1. Splitting date string by date and time and assigning it to 2 variables
    By KaranSaxena in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 17th, 2014, 05:58 AM
  2. Start Date should be exactly 1 week before to End Date
    By bhanuchandar in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 26th, 2013, 08:07 AM
  3. Java Date Format in Date Object
    By Ashr Raza in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 13th, 2012, 10:47 AM
  4. Replies: 1
    Last Post: July 22nd, 2011, 07:08 AM