RSS Forums RSS

Lost with how to start

Please support our Java advertiser: Programming Forums
Reply
Posts: 4
Reputation: littlebean21289 is an unknown quantity at this point 
Solved Threads: 0
littlebean21289 littlebean21289 is offline Offline
Newbie Poster

Lost with how to start

  #1  
Dec 2nd, 2008
I have had to miss my last classes due to having to go to my doctor in order to prep me for surgery. My professor has placed the final assignment online and i have no where to begin. I'll take any help and would like to add that while i can understand programs when reading them, I am a complete lost when asked to write them. Heres the program:Implement a class named Date that
Has three instance variables (month & day & year) of type int
Has a constructor that accepts three input parametes
Has a boolean method called isBirthday
Has a method called getZodiacSign that returns the appropriate icon
Use the DateApplication class (given) as the main program

This is the code i have been given and also pictures for the zodiac symbols
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

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();
       }
    }
}
there is an extra credit assignment for including the chinesenewyear but im not concerned with that.
AddThis Social Bookmark Button
Reply With Quote  
Posts: 1,036
Reputation: BestJewSinceJC is a glorious beacon of light BestJewSinceJC is a glorious beacon of light BestJewSinceJC is a glorious beacon of light BestJewSinceJC is a glorious beacon of light BestJewSinceJC is a glorious beacon of light 
Solved Threads: 120
BestJewSinceJC BestJewSinceJC is offline Offline
Veteran Poster

Re: Lost with how to start

  #2  
Dec 3rd, 2008
Your professor already gave you basic steps on how to begin. Try those and when you get stuck, tell us what you don't understand. We won't do your assignment for you.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the Java Forum
Views: 478 | Replies: 1 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:03 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC