Welcome to the Java Programming Forums


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


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


>> REGISTER NOW TO START POSTING


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

Results 1 to 4 of 4

Thread: NoSuchMethod error while running and deprecation warning messages while comilation of Date program

  1. #1
    Junior Member
    Join Date
    Apr 2009
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default NoSuchMethod error while running and deprecation warning messages while comilation of Date program

    We were given the following code and asked to create a class named Date, a boolean method called isBirthday and a method called getZociacSign. All of my code is commented out at the bottom. I've also commented some statements in the given code. When I compile this I get deprecation warning messages from the Date calls. When I try to run it i get a NoSuchMethod error. Also will the Date class I create conflict with the Date class in the java.util package? I really want to get this to work so I can test my code. Thanks for the help.

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.text.*;
    import java.lang.*;
     
    public class DateApplication extends JFrame 
    {
     
      private JButton birthdayButton,zodiacButton,chineseButton;
      private JTextField monthField, dayField, yearField;
      private JLabel inputPrompt;
      private JPanel panel;
     
       public static void main() 
       {
          DateApplication frame = new DateApplication();
          frame.setSize(350,300);
          frame.createGUI();
          frame.setTitle("Fun with Dates");
          frame.setVisible(true);
        }
     
        private void createGUI() 
        {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            Container window = getContentPane();
            window.setLayout(new FlowLayout());
     
            panel = new JPanel();
            panel.setPreferredSize(new Dimension(300,200));
            panel.setBackground(Color.white);
     
            birthdayButton = new JButton("Check Birthday");
            birthdayButton.addActionListener(new BirthdayDrawAction());
            zodiacButton = new JButton("Zodiac");
            zodiacButton.addActionListener(new ZodiacDrawAction());
            chineseButton = new JButton("Chinese Year");
            chineseButton.addActionListener(new ChineseDrawAction());
     
            inputPrompt = new JLabel("Enter your bithday mm-dd-yyyy: ");
            monthField = new JTextField(2);
            dayField = new JTextField(2);
            yearField = new JTextField(4);
     
            window.add(inputPrompt);
            window.add(monthField);
            window.add(dayField);
            window.add(yearField);
            window.add(birthdayButton);
            window.add(zodiacButton);
            window.add(chineseButton);
            window.add(panel);
        }
     
        private class BirthdayDrawAction implements ActionListener {
            public void actionPerformed(ActionEvent event)
            {   
                int month, day, year;
                String inputMonth = monthField.getText();
                month = Integer.parseInt(inputMonth);
                String inputDay = dayField.getText();
                day = Integer.parseInt(inputDay);
                String inputYear = yearField.getText();
                year = Integer.parseInt(inputYear);
     
                Date theDate = new Date(month,day,year);
     
                Graphics g = panel.getGraphics();
                g.setColor(Color.white);
                g.fillRect(0,0,300,200);
                g.setColor(Color.red);  
                Font myFont = new Font("SansSerif", Font.BOLD, 24);
                g.setFont(myFont);
    //            if (theDate.isBirthday()) {
    //                g.drawString("Happy Birthday",20,100);
    //            }
    //            else {
                    g.drawString("It's not your Birthday",20,100);
    //            }
           }
        }
     
         private class ZodiacDrawAction implements ActionListener {
            public void actionPerformed(ActionEvent event)
            {   
                int month, day, year;
                String inputMonth = monthField.getText();
                month = Integer.parseInt(inputMonth);
                String inputDay = dayField.getText();
                day = Integer.parseInt(inputDay);
                String inputYear = yearField.getText();
                year = Integer.parseInt(inputYear);
     
                Graphics g = panel.getGraphics();
                panel.removeAll();
     
                Date theDate = new Date(month,day,year);
     
                Icon zodiacIcon =  null;
                // zodiacIcon = theDate.getZodiacSign();
     
                JLabel label = new JLabel(zodiacIcon);
                panel.add(label);
                panel.revalidate();
                panel.repaint();
           }
        }
     
     
        private class ChineseDrawAction implements ActionListener {
            public void actionPerformed(ActionEvent event)
            {    
                int month, day, year;
                String inputMonth = monthField.getText();
                month = Integer.parseInt(inputMonth);
                String inputDay = dayField.getText();
                day = Integer.parseInt(inputDay);
                String inputYear = yearField.getText();
                year = Integer.parseInt(inputYear);
     
                Icon ChineseIcon = null;
                Graphics g = panel.getGraphics();  
                panel.removeAll();
     
                Date theDate = new Date(month,day,year);
     
                Icon chineseIcon = null;
                // chineseIcon = theDate.getChineseYear();        
     
                JLabel label = new JLabel(chineseIcon);
                panel.add(label);
                panel.revalidate();
                panel.repaint();
           }
        }
    /**    
        private class Date //(int month, int day, int year)
        {
     
    //        int month, day, year, currentMonth, currentDay, currentYear;
    //        String currentMonthString, currentDayString, currentYearString, theDate;
     
            Calendar todaysDate = Calendar.getInstance();
     
            SimpleDateFormat monthFormat = new SimpleDateFormat("MM");
            String currentMonthString = monthFormat.format(todaysDate.getTime());
            int currentMonth = Integer.parseInt(currentMonthString);
     
            SimpleDateFormat dayFormat =  new SimpleDateFormat("dd");
            String currentDayString = dayFormat.format(todaysDate.getTime());
            int currentDay = Integer.parseInt(currentDayString);
     
            SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy");
            String currentYearString = yearFormat.format(todaysDate.getTime());
            int currentYear = Integer.parseInt(currentYearString);
     
            String theDate = currentMonthString + currentDayString + currentYearString;
     
     
     
     
        public boolean inBirthday (int month, int day, int year)
            {    
                if (month == currentMonth && day == currentDay)
                {
                    return true;
                }
                    else return false;
     
            }
     
        public Icon getZodiacSign (int month, int day)
            {
                if ((month == 1 && day >= 20) || (month == 2 && day <= 18))
                {
                    ImageIcon zodaicIcon =  new ImageIcon("Aquarius.jpg");
                }
     
                if ((month == 2 && day >= 19) || (month == 3 && day <= 20))
                {
                    ImageIcon zodaicIcon =  new ImageIcon("Pisces.jpg");
                }
     
                if ((month == 3 && day >= 21) || (month == 4 && day <= 19))
                {
                    ImageIcon zodaicIcon =  new ImageIcon("Aries.jpg");
                }
     
                if ((month == 4 && day >= 20) || (month == 5 && day <= 20))
                {
                    ImageIcon zodaicIcon =  new ImageIcon("Taurus.jpg");
                }
     
                if ((month == 5 && day >= 21) || (month == 6 && day <= 20))
                {
                    ImageIcon zodaicIcon =  new ImageIcon("Gemini.jpg");
                }
     
                if ((month == 6 && day >= 21) || (month == 7 && day <= 22))
                {
                    ImageIcon zodaicIcon =  new ImageIcon("Cancer.jpg");
                }
     
                if ((month == 7 && day >= 23) || (month == 8 && day <= 22))
                {
                    ImageIcon zodaicIcon =  new ImageIcon("Leo.jpg");
                }
     
                if ((month == 8 && day >= 23) || (month == 9 && day <= 22))
                {
                    ImageIcon zodaicIcon =  new ImageIcon("Virgo.jpg");
                }
     
                if ((month == 9 && day >= 23) || (month == 10 && day <= 22))
                {
                    ImageIcon zodaicIcon =  new ImageIcon("Libra.jpg");
                }
     
                if ((month == 10 && day >= 23) || (month == 11 && day <= 21))
                {
                    ImageIcon zodaicIcon =  new ImageIcon("Scorpio.jpg");
                }
     
                if ((month == 11 && day >= 22) || (month == 12 && day <= 21))
                {
                    ImageIcon zodaicIcon =  new ImageIcon("Sagittarius.jpg");
                }
     
                if ((month == 12 && day >= 22) || (month == 1 && day <= 19))
                {
                    ImageIcon zodaicIcon =  new ImageIcon("Capricorn.jpg");
                }
                return zodiacIcon;
            }
        }            
    */
    }


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Date class conflict?

    Morning LiquidMetal,

    When I compile this code nothing happens? What do I need to do to get this error myself?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

  3. #3
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Location
    Wales, Bangor & England, Warwickshire
    Posts
    820
    My Mood
    Cynical
    Thanks
    7
    Thanked 104 Times in 90 Posts

    Default Re: Date class conflict?

    Try using
    this.Date
    to access the date class

    Regards,
    Chris

  4. #4
    Junior Member
    Join Date
    Apr 2009
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Date class conflict?

    Thank you both again. I played around with it some more and added (String arg[]) peramaters to main which got rid of the no such method error. When I actually implemented my Date class the Date warnings went away, so I guess I found out that a class in the program will take precedence over a library class. Thanks again.

Similar Threads

  1. Replies: 1
    Last Post: May 19th, 2009, 10:19 AM
  2. Updation of webpage to the last modified date
    By Revathy G in forum Java Programming Tutorials
    Replies: 1
    Last Post: May 6th, 2009, 05:47 AM
  3. Replies: 1
    Last Post: February 28th, 2009, 10:05 PM
  4. How to Get the current date and time
    By JavaPF in forum Java Programming Tutorials
    Replies: 2
    Last Post: December 2nd, 2008, 01:55 PM