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 3 of 12 FirstFirst 12345 ... LastLast
Results 51 to 75 of 284

Thread: library or component for Hijra date chooser

  1. #51
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: library for Hijra date chooser

    I think that the computing of where to put the day numbers is all simple arithmetic that you will need to work out.

    I'm done for tonight. I'll be back tomorrow.
    If you don't understand my answer, don't ignore it, ask a question.

  2. The Following User Says Thank You to Norm For This Useful Post:

    cnmeysam (April 26th, 2021)

  3. #52

    Default Re: library for Hijra date chooser

    now how i can say when user click on JSpinner moon or year jdialog buttons update? and when user click on buttons text field update?

  4. #53
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: library for Hijra date chooser

    The code in the inner class DatePanel in the NewClass class handled clicks on the Spinners.

    This repeated code:
                if ((Integer) monthSpin.getValue() == 1) {
     
                    JLabel monthNameLabel = new JLabel("????");
                    monthNameLabel.setForeground(controlMoonnameTextColor);
                    panel.add(monthNameLabel);
                } else if ((Integer) monthSpin.getValue() == 2) {
     
                    JLabel monthNameLabel = new JLabel("???");
                    monthNameLabel.setForeground(controlMoonnameTextColor);
                    panel.add(monthNameLabel);
                } else if ((Integer) monthSpin.getValue() == 3) {
     
                    JLabel monthNameLabel = new JLabel("????*?????");
                    monthNameLabel.setForeground(controlMoonnameTextColor);
                    panel.add(monthNameLabel);
    should use an array:
    String[] moonNames = {....
    ....
      JLabel monthNameLabel = new JLabel(moonNames[ monthSpin.getValue()]);  // get name from array
    If you don't understand my answer, don't ignore it, ask a question.

  5. #54

    Default Re: library for Hijra date chooser

    i fix this part like this
     String[] moonNames = {"Moharram", "Safar", "Rabi'al avval", "Rabi'al Sani", "Jmadi'al avval", "Jamadi'al Sani", "Rajab", "Shaban", "Ramadan", "Shavval", "Zolgha'de", "Zol'Hajje"};
                JLabel monthNameLabel = new JLabel(moonNames[(Integer) monthSpin.getValue()-1]);  // get name from array
                panel.add(monthNameLabel);
    now how i must use spinner for change jbox values when i change moon spinner or year sppiner?

  6. #55
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: library for Hijra date chooser

    The code in the inner class DatePanel in the NewClass class handled clicks on the Spinners.

    Look at that code and see what you changed that needs to be fixed.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #56

    Default Re: library for Hijra date chooser

    i think this part must be change but i don't know how
    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(cal.getTime());
                reflushWeekAndDay();
            }

  8. #57
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: library for Hijra date chooser

    Look at the working code in NewClass. It moves the day numbers in the calendar with changes in year and month.
    What did you change from that to make the Hijrah class? The technique from the NewClass class needs to be copied to the Hijrah class.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #58

    Default Re: library for Hijra date chooser

    I'm for call hijri date use this method
    HijrahDate hijrahDate = HijrahDate.now();
    System.out.println("hijrahDate   " + hijrahDate);
    but i don't know how i must set YEAR or MONTH for it
    and with this i can find moon number and year number
    Locale ar = new Locale("ar");
                DateTimeFormatter YearNum = DateTimeFormatter.ofPattern("u", ar);
                DateTimeFormatter dayOfMoonNum = DateTimeFormatter.ofPattern("M", ar);
                HijrahDate hijrahDate = HijrahDate.now();
                String HijriYearNum = hijrahDate.format(YearNum);
                System.out.println("YearNum   " + HijriYearNum);
                String MoonOfYear = hijrahDate.format(dayOfMoonNum);
                System.out.println("month-of-year   " + MoonOfYear);

  10. #59
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: library for Hijra date chooser

    Look at the API doc for the HijrahDate class. Is what you need there?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #60

    Default Re: library for Hijra date chooser

    i use like that but jbox not updates
     public void stateChanged(ChangeEvent e) {
                dayColorUpdate(true);
     
                JSpinner source = (JSpinner) e.getSource();
                Locale ar = new Locale("ar");
                DateTimeFormatter YearNum = DateTimeFormatter.ofPattern("u", ar);
                DateTimeFormatter numOfMoonNum = DateTimeFormatter.ofPattern("M", ar);
                DateTimeFormatter dayOfMoonNum = DateTimeFormatter.ofPattern("d", ar);
                HijrahDate hijrahDate = HijrahDate.now();
                HijrahChronology crono = hijrahDate.getChronology();
                String HijriYearNum = hijrahDate.format(YearNum);
                System.out.println("YearNum   " + HijriYearNum);
                String MoonOfYear = hijrahDate.format(numOfMoonNum);
                System.out.println("month-of-year   " + MoonOfYear);
                System.out.println("crono   " + crono);
                String dayOfMoonNums = hijrahDate.format(dayOfMoonNum);
                int moondayNumb = Integer.parseInt(dayOfMoonNums);
                System.out.println("crono   " + crono);
                HijrahDate date;
                int HijriMoonOfYearb = Integer.parseInt(MoonOfYear);
     
                if (source.getName().equals("Year")) {
     
                    date = crono.date(getSelectedYear(), HijriMoonOfYearb, moondayNumb);               
                    hijrahDate=date;
                    System.out.println("date Year  " + date);
                } else {
                    date = crono.date(getSelectedYear(), getSelectedMonth(), moondayNumb);
                    hijrahDate=date;
                    System.out.println("date MONTH  " + date);
                }
                   hijrahDate=date;
                    reflushWeekAndDay();
            }

  12. #61
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: library for Hijra date chooser

    Is it working now? I did not see a question in the last post.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #62

    Default Re: library for Hijra date chooser

    in system pint show correctly but jdialog not updated it is all my code now when jsppiner for year or moonth change jdialog not update and when jsppiner moonth change moonNames not updatet
     
    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.LocalDateTime;
    import java.time.chrono.HijrahDate;
    import java.time.format.DateTimeFormatter;
    import java.util.Calendar;
    import java.util.Date;
     
    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;
    import java.time.chrono.HijrahChronology;
    import java.util.Locale;
     
    public class Hijrah extends JTextField {
     
        String testMethod() {                  //  ADDED
            HijrahDate hijrahDate = HijrahDate.now();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
            String formatted = formatter.format(hijrahDate); // 07/03/1439
            System.out.println("hijrahDate " + formatted);
            return formatted.toString(); //<<<<<< ADDED
        }
        private static String DEFAULT_DATE_FORMAT = "yyyy/MM/dd";
        private static final int DIALOG_WIDTH = 250;
        private static final int DIALOG_HEIGHT = 210;
     
        private SimpleDateFormat dateFormat;
        private DatePanel datePanel = null;
        private JDialog dateDialog = null;
     
        public Hijrah() {
            this(new Date());
        }
     
        public Hijrah(String dateFormatPattern, Date date) {
            this(date);
            DEFAULT_DATE_FORMAT = dateFormatPattern;
        }
     
        public Hijrah(Date date) {
            setDate(date);
            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(Date date) {
            setDate(date);
     
        }
     
        public void setDate(Date date) {
    //        super.setText(getDefaultDateFormat().format(date) + " " + testMethod());   //<<<<< Changed
            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 = 1380;
            int lastYear = 3050;
     
            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 = Color.white;
            Color controlMoonnameTextColor = Color.BLUE;
     
            JSpinner yearSpin;
            JSpinner monthSpin;
     
            JButton[][] daysButton = new JButton[6][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() {
     
                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("Year");
                yearLabel.setForeground(controlTextColor);
                panel.add(yearLabel);
     
                yearSpin = new JSpinner(new SpinnerNumberModel(currentYear,
                        startYear, lastYear, 1));
                yearSpin.setPreferredSize(new Dimension(60, 30));
                yearSpin.setName("Year");
                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("Month");
                monthSpin.addChangeListener(this);
     
    //            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"};
                JLabel monthNameLabel = new JLabel(moonNames[(Integer) monthSpin.getValue() - 1]);  // get name from array
                panel.add(monthNameLabel);
     
                panel.add(monthSpin);
     
                JLabel monthLabel = new JLabel("Month");
                monthLabel.setForeground(controlTextColor);
                panel.add(monthLabel);
     
                return panel;
            }
     
            private JPanel createWeekAndDayPanal() {
                String colname[] = {"Sa", "sun", "Mon", "Tu", "We", "Th", "Fr"};
                JPanel panel = new JPanel();
                panel.setFont(new Font("Arial", Font.PLAIN, 10));
                panel.setLayout(new GridLayout(7, 7));
                panel.setBackground(Color.white);
     
                for (int i = 0; i < 7; i++) {
                    JLabel cell = new JLabel(colname[i]);
                    cell.setHorizontalAlignment(JLabel.CENTER);
    //                if (i == 0 || i == 6) {
                    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) {
                                    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 == 6) {
                            numBtn.setForeground(weekendFontColor);
                        } else {
                            numBtn.setForeground(dateFontColor);
                        }
                        daysButton[i][j] = numBtn;
                        panel.add(numBtn);
                        actionCommandId++;
                    }
                }
     
                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) {
     
                Locale ar = new Locale("ar");
                DateTimeFormatter dayOfMoonNum = DateTimeFormatter.ofPattern("d", ar);
                DateTimeFormatter dayOfweekNum = DateTimeFormatter.ofPattern("c", ar);
                HijrahDate hijrahDate = HijrahDate.now();
                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);
                } else {
                    daysButton[i][j].setForeground(todayBackColor);
                }
     
            }
     
            private void reflushWeekAndDay() {
                Locale ar = new Locale("ar");
                DateTimeFormatter dayOfMoonNum = DateTimeFormatter.ofPattern("d", ar);
                DateTimeFormatter dayOfweekNum = DateTimeFormatter.ofPattern("c", ar);
                HijrahDate hijrahDate = HijrahDate.now();
                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 dayNo = 2 - WeekdayNumb;
                for (int i = 0; i < 6; i++) {
                    for (int j = 0; j < 7; j++) {
                        String s = "";
                        if (dayNo >= 1 && dayNo <= moondaysnumber) {
                            s = String.valueOf(dayNo);
                        }
                        daysButton[i][j].setText(s);
                        dayNo++;
                    }
                }
                dayColorUpdate(false);
            }
     
            public void stateChanged(ChangeEvent e) {
                dayColorUpdate(true);
     
                JSpinner source = (JSpinner) e.getSource();
                Locale ar = new Locale("ar");
                DateTimeFormatter YearNum = DateTimeFormatter.ofPattern("u", ar);
                DateTimeFormatter numOfMoonNum = DateTimeFormatter.ofPattern("M", ar);
                DateTimeFormatter dayOfMoonNum = DateTimeFormatter.ofPattern("d", ar);
                HijrahDate hijrahDate = HijrahDate.now();
                HijrahChronology crono = hijrahDate.getChronology();
                String HijriYearNum = hijrahDate.format(YearNum);
                System.out.println("YearNum   " + HijriYearNum);
                String MoonOfYear = hijrahDate.format(numOfMoonNum);
                System.out.println("month-of-year   " + MoonOfYear);
                System.out.println("crono   " + crono);
                String dayOfMoonNums = hijrahDate.format(dayOfMoonNum);
                int moondayNumb = Integer.parseInt(dayOfMoonNums);
                System.out.println("crono   " + crono);
                HijrahDate date;
                int HijriMoonOfYearb = Integer.parseInt(MoonOfYear);
     
                if (source.getName().equals("Year")) {
     
                    date = crono.date(getSelectedYear(), HijriMoonOfYearb, moondayNumb);               
                    hijrahDate=date;
                    System.out.println("date Year  " + date);
                } else {
                    date = crono.date(getSelectedYear(), getSelectedMonth(), moondayNumb);
                    hijrahDate=date;
                    System.out.println("date MONTH  " + date);
                }
                   hijrahDate=date;
                    reflushWeekAndDay();
            }
     
        }
     
    }

  14. #63
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: library for Hijra date chooser

    How did the NewClass class update the day numbers in the JDialog? Look at how that code worked.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #64

    Default Re: library for Hijra date chooser

    I think it's here but I do not know how to do it
    private JPanel createWeekAndDayPanal() {
    //            String colname[] = {"بس", "اح", "ثن", "ثل", "ار", "خم", "جم"};
                String colname[] = {"Sa", "sun", "Mon", "Tu", "We", "Th", "Fr"};
                JPanel panel = new JPanel();
                panel.setFont(new Font("Arial", Font.PLAIN, 10));
                panel.setLayout(new GridLayout(7, 7));
                panel.setBackground(Color.white);
     
                for (int i = 0; i < 7; i++) {
                    JLabel cell = new JLabel(colname[i]);
                    cell.setHorizontalAlignment(JLabel.CENTER);
    //                if (i == 0 || i == 6) {
                    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) {
                                    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());
    //hijrahDate=date
                                dateDialog.setVisible(false);
                            }
                        });
                        if (j == 6) {
                            numBtn.setForeground(weekendFontColor);
                        } else {
                            numBtn.setForeground(dateFontColor);
                        }
                        daysButton[i][j] = numBtn;
                        panel.add(numBtn);
                        actionCommandId++;
                    }
                }
     
                return panel;
            }

  16. #65
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: library for Hijra date chooser

    I think it's here
    Why do you think the problem it is in that code? What does that code do?

    You need to trace through the working code to see how the values are saved and used.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #66

    Default Re: library for Hijra date chooser

    Because in this part is not used in the Hijri calendar
    setDate(cal.getTime());

  18. #67
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: library for Hijra date chooser

    Look at what the setDate method does? Is the results of what that method does needed for the rest of the code to work as desired?
    Look at the getDate() method.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #68

    Default Re: library for Hijra date chooser

    My brain is no longer working. I no longer know what to do

  20. #69
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: library for Hijra date chooser

    My brain is no longer working. I no longer know what to do
    Take a break and let your brain refresh.

    When it is rested, you need to study how the NewClass class works and then use those techniques in your program.
    If you don't understand my answer, don't ignore it, ask a question.

  21. #70

    Default Re: library for Hijra date chooser

    Unfortunately I did not understand which part of the class I should edit and what code I should write
    setDate take the gregorian system time but i need set date take hijri date
    and getdate get date from Text but i need user can text leave empty
     public Date getDate() {
            try {
                return getDefaultDateFormat().parse(getText());
            } catch (ParseException e) {
                return new Date();
            }
        }
    Last edited by cnmeysam; April 27th, 2021 at 01:43 PM.

  22. #71
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: library for Hijra date chooser

    Before writing any code you need to design what the program is supposed to do. Where is the date's value stored? How is it updated?
    The NewClass class stores the date as a String in the text field. I think it would be better to store the date in a special class.
    I think a class to hold the Hijrah date with all the needed methods for accessing (get and set) the date's values would be useful.
    For example some of the methods from the Calendar class and some of the methods from the Date class should be included.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #72

    Default Re: library for Hijra date chooser

    the date's value stored in testMethod() but i need Work without using text Because I want the user to be able to leave it blank or user can change DateTimeFormatter Also, the user can not enter the date incorrectly
    and i create this for save hijri date
    Object hijri(){
            HijrahDate hijrahDate = HijrahDate.now();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
            String formattedhijri = formatter.format(hijrahDate); // 07/03/1439
            System.out.println("hijrahDate " + formattedhijri);
            return formattedhijri;
     
        }
        }
    but i don't know it is true or not
    Last edited by cnmeysam; April 27th, 2021 at 02:20 PM.

  24. #73
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: library for Hijra date chooser

    What problem are you working on now?
    I thought you wanted the user's interactions with the dialog window to set year, month or day of the date and then have that selected date display in the textfield.

    Its better to only work on one problem at a time.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #74

    Default Re: library for Hijra date chooser

    i need after change jspinner year or month jbox is updated
    yes i wanted the user's interactions with the dialog window to set year, month or day of the date and then have that selected date display in the textfield But after clicking on the day in the box.

  26. #75
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: library for Hijra date chooser

    To enable those things to happen, you need to design and implement a class to hold the Hijrah date with all the necessary methods for using and updating that date.
    If you don't understand my answer, don't ignore it, ask a question.

Page 3 of 12 FirstFirst 12345 ... 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