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 11 of 12 FirstFirst ... 9101112 LastLast
Results 251 to 275 of 284

Thread: library or component for Hijra date chooser

  1. #251

    Default Re: library for Hijra date chooser

    when after 12AM go to new day or i change it manually

  2. #252
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: library for Hijra date chooser

    Interesting problem. I have never stayed up that late at night for testing a java program.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #253

    Default Re: library for Hijra date chooser

    Unlike you, I always work at night and sleep during the day. I am always talking to you from 10 pm to 3:45 am.
    Because I concentrate better in silence now here is 2:02 AM
    The interesting thing is that this problem is reset every week and each number is put in its place, and with each passing day, the number of numbers increases again. and If we turn the calendar back, it goes back one step at a time

    --- Update ---

    WHAT IS MEAN
    Calendar cal = getCalendar();
     cal.get(Calendar.DAY_OF_WEEK)
    cal.set(Calendar.DAY_OF_MONTH, 1);
    Last edited by Norm; May 3rd, 2021 at 05:44 AM. Reason: Added ] to ending code tag

  4. #254
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: library for Hijra date chooser

      Calendar cal = getCalendar();          // get an instance of the Calendar into cal
      int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);  // get day of week for cal object
      cal.set(Calendar.DAY_OF_MONTH, 1);     // set the day of the cal object to first day of month
    If you don't understand my answer, don't ignore it, ask a question.

  5. #255

    Default Re: library for Hijra date chooser

    Quote Originally Posted by cnmeysam View Post
    Unlike you, I always work at night and sleep during the day. I am always talking to you from 10 pm to 3:45 am.
    Because I concentrate better in silence now here is 2:02 AM
    The interesting thing is that this problem is reset every week and each number is put in its place, and with each passing day, the number of numbers increases again. and If we turn the calendar back, it goes back one step at a time
    it's fixed i jut must change this part of code I should have written 1 instead of da
    HijrahDate hijrahDate = HijrahChronology.INSTANCE.date(ye, mo, 1);
    for set first day of month
    private void reflushWeekAndDay() {
     
                ye = (Integer) yearSpin.getValue();
                mo = (Integer) monthSpin.getValue();
     
                Locale ar = new Locale("ar");
     
                DateTimeFormatter dayOfweekNum = DateTimeFormatter.ofPattern("c", ar);
                HijrahDate hijrahDate = HijrahChronology.INSTANCE.date(ye, mo, 1);
     
                String WeekdayNum = hijrahDate.format(dayOfweekNum);
                DateTimeFormatter dayOfMonth = DateTimeFormatter.ofPattern("d", ar);
                String MonthdayNum = hijrahDate.format(dayOfMonth);
                System.out.println("MonthdayNum "+MonthdayNum);
                int WeekdayNumb = Integer.parseInt(WeekdayNum);
     
                int moondaysnumber = hijrahDate.lengthOfMonth();
                System.out.println("int MonthdayNum "+moondaysnumber);
     
                int maxDayNo = moondaysnumber;
     
                int dayNo = 2 - WeekdayNumb;//set days in are in place
     
                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);
            }
    i tested and work's for now
    now how we must set date in new form for hijri date? post #229 and #235

    --- Update ---

    i think if get string work's for me

    --- Update ---

    do you have any solution for this?

  6. #256
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: library for Hijra date chooser

    Sorry, I don't know what the problem is. Can you explain in more detail and give an example?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #257

    Default Re: library for Hijra date chooser

    when use hijridate class as component in other form i see a hijri date chooser some times i need set a date in the hijri date chooser text like when i load date from database and when use hijri.settext() or hijri.setdate() it is dont't happened and i see this error for set text( hijri.setText("1442/09/21") )
    method setText in class HijrahextendsJPanel cannot be applied to given types;
      required: no arguments
      found: String
      reason: actual and formal argument lists differ in length
    and this for set date
    method setDate in class HijrahextendsJPanel cannot be applied to given types;
      required: no arguments
      found: Date
      reason: actual and formal argument lists differ in length
    and when use set method in the form create this in hijri class
    void setText(String string) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    now i don't know what i must write there

    --- Update ---

    this is my all class code
    package GHDate;
     
    /*
     * Many thanks to Norm from the www.javaprogrammingforums.com that knew more than me.put more time and energy to create this component 
     * Maysam Soleymani Qorabaee www.programsfuture.com  * 
     */
    /**
     *
     * @author Admin
     */
    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.GridBagLayout;
    import java.awt.GridLayout;
    import java.awt.Image;
    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.io.IOException;
    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.Date;
    import java.util.Locale;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
     
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFormattedTextField;
    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 javax.swing.JPanel;
    import javax.swing.SpringLayout;
     
    public class HijrahextendsJPanel extends JPanel {
     
        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
     
        Image img;
     
        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 HijrahextendsJPanel.DatePanel datePanel = null;
        private JDialog dateDialog = null;
     
        private JButton choosdate = new JButton();
        private JFormattedTextField datetext = new JFormattedTextField();
     
        private JPanel datePanels = new JPanel();
        String formatted;
     
        //Build a block to give a value to the year and month and day when the class loads
        public void hdate() {
            HijrahDate hijrahDate = HijrahDate.now();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT);
            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 HijrahextendsJPanel(String dateFormatPattern, Date date) {
            this();
            DEFAULT_DATE_FORMAT = dateFormatPattern;
        }
     
        public HijrahextendsJPanel() {
     
            hdate();
     
            try {
                datetext.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("####/##/##")));
            } catch (java.text.ParseException ex) {
                ex.printStackTrace();
            }
     
            javax.swing.GroupLayout datePanelsLayout = new javax.swing.GroupLayout(datePanels);
            datePanels.setLayout(datePanelsLayout);
            datePanelsLayout.setHorizontalGroup(
                    datePanelsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(datePanelsLayout.createSequentialGroup()
                            .addComponent(datetext, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, 0)
                            .addComponent(choosdate, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, Short.MAX_VALUE))
            );
            datePanelsLayout.setVerticalGroup(
                    datePanelsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(datePanelsLayout.createSequentialGroup()
                            .addGroup(datePanelsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(datetext, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(choosdate, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(0, 0, Short.MAX_VALUE))
            );
     
            add(datePanels);
     
            try {
                img = ImageIO.read(getClass().getResource("cleander.png"));
                choosdate.setIcon(new ImageIcon(img));
            } catch (IOException ex) {
            }
     
            setDate();
            choosdate.setCursor(new Cursor(Cursor.HAND_CURSOR));
            datePanels.add(datetext);
            datePanels.add(choosdate);
            choosdate.setVisible(true);
            choosdate.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    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(HijrahextendsJPanel.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() {
            datetext.setText(getHDateString());   //<<<<< Changed
     
        }
     
        public Date getDate() {
     
            try {
                return getDefaultDateFormat().parse(formatted);
            } 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];
     
            // Fill the days of the month in the buttons on the desired day
            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();
            }
     
            //Build a panel for daylight months and sppiners and labels
            private JPanel createYearAndMonthPanal() {
                Font font = new Font("Tahoma", Font.BOLD, 10);
     
                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(ye,
                        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(mo, 1,
                        12, 1));
     
                monthSpin.setPreferredSize(new Dimension(45, 30));
                monthSpin.setName("Month");
                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;
            }
     
            //Fill the days of the month in the buttons on the desired day
            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;
                                }
     
                                numBtn.setBackground(palletTableColor);
                                numBtn.setForeground(dateFontColor);
                                source.setForeground(todayBackColor);
     
                                int newDay = Integer.parseInt(source.getText());
                                da = newDay;
     
                                setDate();
                                dayColorUpdate(true);
                                dateDialog.setVisible(false);
                            }
                        });
     
                        daysButton[i][j] = numBtn;
                        panel.add(numBtn);
                        actionCommandId++;
                        if (j == 6) {
                            numBtn.setForeground(weekendFontColor);
                        } else {
                            numBtn.setForeground(dateFontColor);
                        }
                    }
                }
     
                return panel;
            }
     
            private HijrahDate getCalendar() {
     
                HijrahDate today = HijrahChronology.INSTANCE.date(ye, mo, da);
     
                return today;
            }
     
            private int getSelectedYear() {
                return ((Integer) yearSpin.getValue()).intValue();
            }
     
            private int getSelectedMonth() {
                return ((Integer) monthSpin.getValue()).intValue();
            }
     
            // Paint the days of the week and today
            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);
     
                        }
                    }
                }
            }
    // Specify the number of days of a cat and start on what day and end on what day
     
            private void reflushWeekAndDay() {
     
                ye = (Integer) yearSpin.getValue();
                mo = (Integer) monthSpin.getValue();
     
                Locale ar = new Locale("ar");
     
                DateTimeFormatter dayOfweekNum = DateTimeFormatter.ofPattern("c", ar);
                HijrahDate hijrahDate = HijrahChronology.INSTANCE.date(ye, mo, 1);
     
                String WeekdayNum = hijrahDate.format(dayOfweekNum);
                DateTimeFormatter dayOfMonth = DateTimeFormatter.ofPattern("d", ar);
                String MonthdayNum = hijrahDate.format(dayOfMonth);
                System.out.println("MonthdayNum "+MonthdayNum);
                int WeekdayNumb = Integer.parseInt(WeekdayNum);
     
                int moondaysnumber = hijrahDate.lengthOfMonth();
                System.out.println("int MonthdayNum "+moondaysnumber);
     
                int maxDayNo = moondaysnumber;
     
                int dayNo = 2 - WeekdayNumb;//set days in are in place
     
                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);
            }
     
            // set year when click on jdialog button's and spinner and textfild
            public void stateChanged(ChangeEvent e) {
                dayColorUpdate(true);
                JSpinner source = (JSpinner) e.getSource();
                if (source.getName().equals("Year")) {
                    ye = (getSelectedYear());
                } else {
                    mo = (getSelectedMonth());
                }
                getCalendar();
                reflushWeekAndDay();
                setDate();
                mothnam();
            }
     
        }
     
        // set month when click on jdialog button's and spinner and textfild
        public void mothnam() {
            monthNameLabel.setText(moonNames[mo - 1]);
        }
     
        //set date for jtext and jdialog....
        String getHDateString() {                  //  ADDED
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT);
            HijrahDate today = HijrahChronology.INSTANCE.date(ye, mo, da);
            String formatted = formatter.format(today); // 07/03/1439
     
            return formatted.toString(); //<<<<<< ADDED
        }
    }


    --- Update ---

    i think i must use datetext.setText(); but how?
    Last edited by cnmeysam; May 3rd, 2021 at 03:44 PM.

  8. #258
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: library for Hijra date chooser

    i see this error for set text( hijri.setText("1442/09/21") )
    method setText in class HijrahextendsJPanel cannot be applied to given types;
    required: no arguments
    found: String
    reason: actual and formal argument lists differ in length
    That error says the setText method is declared to have no arguments, but the calling call tried to pass it a String.
    If you want to pass a String to the setText method it needs to be defined to take a String as its argument.

    now i don't know what i must write there
    Why are you calling the method if you don't know what it is supposed to do?

    use datetext.setText(); but how?
    Put that code inside of the setText method.
    If you don't understand my answer, don't ignore it, ask a question.

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

    cnmeysam (May 3rd, 2021)

  10. #259

    Default Re: library for Hijra date chooser

    method setText in class JTextComponent cannot be applied to given types;
    required: String
    found: no arguments
    reason: actual and formal argument lists differ in length

    now how i can fixe it?

    --- Update ---

     void setText(String string) {
            datetext.setText(string);
     
        }

  11. #260
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: library for Hijra date chooser

    Did that work?
    If you don't understand my answer, don't ignore it, ask a question.

  12. #261

    Default Re: library for Hijra date chooser

    ok perfectly i add string and date now i can use both of them

    --- Update ---

    now how i must fix get text when i user hijri.getText();
    boolean getText() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

  13. #262
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: library for Hijra date chooser

    What is getText supposed to return? Where is the data that can be used to create the desired value to return?
    If you don't understand my answer, don't ignore it, ask a question.

  14. #263

    Default Re: library for Hijra date chooser

    Any text written inside the text box is of date type like 1442/10/21
    and getDate print hijri year and Gregorian month and day

    --- Update ---

    System.out.println(hijrahextendsJPanel1.getDate());


    --- Update ---

    Sat Sep 22 00:00:00 IRST 1442

    --- Update ---

    and always show time 00:00:00

    --- Update ---

    and always show current hijri year
    Last edited by cnmeysam; May 3rd, 2021 at 04:41 PM.

  15. #264
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: library for Hijra date chooser

    text written inside the text box
    Look at how the setText method worked. Copy that idea for getText.
    If you don't understand my answer, don't ignore it, ask a question.

  16. #265

    Default Re: library for Hijra date chooser

    void getText(String string) {
            datetext.getText(string);
        }
    no suitable method found for getText(String)
    method JTextComponent.getText(int,int) is not applicable
    (actual and formal argument lists differ in length)
    method JTextComponent.getText() is not applicable
    (actual and formal argument lists differ in length)

    --- Update ---

    What should I do now?

  17. #266
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: library for Hijra date chooser

    A get method normally does not pass any arguments. It returns a value - it is not declared as void.

    What should getText return? Where is the value to be returned?
    If you don't understand my answer, don't ignore it, ask a question.

  18. #267

    Default Re: library for Hijra date chooser

    i need value inside datetext.getText();

    --- Update ---

    cannot find symbol
    symbol: method getText()
    location: variable hijrahextendsJPanel1 of type HijrahextendsJPanel

    --- Update ---

    String getText() {
            datetext.getText();
            return datetext.getText();
        }


    --- Update ---

    now how fix getDate? It is used in this way in the class and should be changed to the Hijri calendar and again i don't know how?!
    public Date getDate() {
     
            try {
                return getDefaultDateFormat().parse(formatted);
            } catch (ParseException e) {
                return new Date();
            }
        }

  19. #268
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: library for Hijra date chooser

    Yes, that looks like it pairs with the setText method.
    The extra call: datetext.getText(); is not needed.

    What data type/class is the getDate method supposed to return?
    If you don't understand my answer, don't ignore it, ask a question.

  20. #269

    Default Re: library for Hijra date chooser

    Quote Originally Posted by Norm View Post

    What data type/class is the getDate method supposed to return?
    hijridate

    --- Update ---


    DEFAULT_DATE_FORMAT = "yyyy/MM/dd"
    something like this
    String getHDateString() {                  //  ADDED
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT);
            HijrahDate today = HijrahChronology.INSTANCE.date(ye, mo, da);
            String formatted = formatter.format(today); // 1442/10/20
     
            return formatted.toString(); //<<<<<< ADDED
        }


    --- Update ---

    or like this
    public void hdate() {
            HijrahDate hijrahDate = HijrahDate.now();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT);
            formatted = formatter.format(hijrahDate);   // 1442/10/20
            ye = Integer.parseInt(formatted.substring(0, 4));
            mo = Integer.parseInt(formatted.substring(5, 7));
            da = Integer.parseInt(formatted.substring(8, 10));
        }
    Last edited by cnmeysam; May 3rd, 2021 at 05:45 PM.

  21. #270
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: library for Hijra date chooser

    Is this the class: HijrahDate
    Spelling is important. hijridate is not the class name.

    Look at the constructor for the HijrahDate class and see how to build an instance of that class with the desired values.
    If you don't understand my answer, don't ignore it, ask a question.

  22. #271

    Default Re: library for Hijra date chooser

    I have tried to create it before but could not create it
    this is spell: HijrahDate
    HijrahDate hijrahDate = HijrahDate.now();
    HijrahDate today = HijrahChronology.INSTANCE.date(1442, 10, 15);
    Can you help me create it?

    --- Update ---

    like this
     
    public Date getDate() {
     
            try {
                return getDefaultDateFormat().parse(formatted);
            } catch (ParseException e) {
                return new Date();
            }
        }

  23. #272
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: library for Hijra date chooser

    What is the problem with that code?
    What values are supposed to be in the HijrahDate object that is returned?
    How can the object with those values be created?
    Look at the API doc for the class.
    like this

    public Date getDate() {
    I thought the getDate method was supposed to return a HijrahDate object, not a Date object.
    If you don't understand my answer, don't ignore it, ask a question.

  24. #273

    Default Re: library for Hijra date chooser

    i think return new Date(); return new date in gregorian date
    but i don't know return getDefaultDateFormat().parse(formatted); return what?! if i know maybe i can fix this problem

  25. #274
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: library for Hijra date chooser

    how fix getDate?
    Is this the problem you are working on now?
    If you don't understand my answer, don't ignore it, ask a question.

  26. #275

    Default Re: library for Hijra date chooser

    yes and i think after that just i have one problem and finish this god damn project

    --- Update ---

    It took me a lot of time and energy to get a free component and publish it and make it available to the public

    --- Update ---

    i think this part must change

    private SimpleDateFormat dateFormat;
    private SimpleDateFormat getDefaultDateFormat() {
            if (dateFormat == null) {
     
                dateFormat = new SimpleDateFormat(DEFAULT_DATE_FORMAT);//DEFAULT_DATE_FORMAT = "yyyy/MM/dd"
            }
            return dateFormat;
        }
    for fix this part
    public HijrahDate getDate() {
                try {
                return getDefaultDateFormat().parse(formatted);// here not working (incompatible types: Date cannot be converted to HijrahDate)
                }catch (ParseException e) {
                return HijrahDate.now();//i don't must use this code because don't get text date always show just today date
                }
        }
    HijrahDate getDate() replace this part
    public Date getDate() {
            try {
                return getDefaultDateFormat().parse(formatted);
            } catch (ParseException e) {
                return new Date();
            }
        }
    for hijri date format we use this code
            HijrahDate hijrahDate = HijrahDate.now();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT);//DEFAULT_DATE_FORMAT = "yyyy/MM/dd"
            formatted = formatter.format(hijrahDate); // 1442/10/14
    Last edited by cnmeysam; May 4th, 2021 at 12:01 PM.

Page 11 of 12 FirstFirst ... 9101112 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