Hi,

New to Java & hoping you can help me with an error message I am getting.


The compiler says "Cannot find symbol - variable evt" for the first line of the below code.

if (evt.target==calc)
            
      {
                clickedCalc();
                
                return true;
      }
                else
                
                return super.action(evt,obj);
            
        
        for(int i=0;i<12;i++)
            result[i].setText(" "); // clear last calculations
        result[3].setText("You input "+nd3);

The full code is below. I am writing a program where which will ask for a date and give you three options: Leap Year; Calculate Days and Day of the Week.

When you choose "Calculate Days" it brings up a second set of text files for completion and a new Button called "Calculate". This bit works OK. I now want it to acknowledge that the "Calculate" button has been pressed. All I want at the moment is a line which says "You have entered" and then the new dates but evt.target isn't doing what I was hoping.

Any suggestions really appreciated.


Full Code:

/**
 * The two import statements enable classes in these two packages
 * to be used without 
 */
import java.awt.*;
import java.applet.*;


/**
 * The extends keyword enables all of the basic applet methods
 * (and those from the applets superclasses)to be used within
 * this class
 */
public class EmmaDateApplet extends Applet
{
/**
 * The program uses three components from the awt package to be
 * used within the class - Label, TextField; Button
 */
    private Label label1;
    private Label label2;
    private TextField dayEntry;
    private TextField monthEntry;
    private TextField yearEntry;
    private TextField dayEntry2;
    private TextField monthEntry2;
    private TextField yearEntry2;
    private Button leap;
    private Button dayCount;
    private Button dayOfWeek;
    private Button calc;
    

    Label result[]=new Label[12];      //creates text fields
    
    /** 
     * 
     *Array of labels - label objects
     * 
     */

    public void init()
    {

        setLayout(null);            //create own layout rather than accept Java default layouts
        
        
        setFont(new Font("Courier",Font.PLAIN,12));                     //Java dictionary - bluej - click on "HELP" in BlueJ window - Java class libraries - Font
/** 
 * Set the size of the applet in pixels. This will be overridden if the
 * size of the applet is defined within the html code calling the applet.
 */
        resize(500,500);                //width, height
/**
 * All components are defined in three steps:
 *      1.instantiate the object  (ie, create)
 *      2.add the component to the container (applet)
 *      3.set the size and position within the container.
 * (the reshape method is also deprecated)
 */
        label1=new Label("Please enter a date (dd mm yyyy)");
        add(label1);
        label1.setBounds(50,200,300,25);                                  // instead of setBounds you can use reshape(135,20,115,25). Where they are in the window relevant to the top left of the window.
        
                                                                           //135 = position across, 20 = position down, 115 = width, 25 = height
        dayEntry=new TextField(2);
        add(dayEntry);
        dayEntry.reshape(255,320,50,25);
        
        monthEntry=new TextField(2);
        add(monthEntry);
        monthEntry.reshape(340,320,50,25);
        
        yearEntry=new TextField(4);
        add(yearEntry);
        yearEntry.reshape(425,320,50,25);

        for(int i=0;i<12;i++)                                           //i just declared in the for loop
        {
            result[i]=new Label(" ");
            add (result[i]);
            result[i].setBounds(155,55+18*i,190,18);                        
        }
        leap=new Button("Leap");
        add(leap);
        leap.reshape(50,100,120,30);
        
        dayCount=new Button("Day Count");
        add(dayCount);
        dayCount.reshape(50,140,120,30);
        
        dayOfWeek=new Button("Day Of Week");
        add(dayOfWeek);
        dayOfWeek.reshape(50,180,120,30);
 
        super.init();
    }
/**
 * The action method is inherited (via Applet, Panel, Container) from the 
 * Component superclass. It's use is now deprecated - replaced by more 
 * up-to-date methods but is still valuable.
 */
    public boolean action(Event evt,Object obj)
    {
/**
 * If the Compute button has been clicked, run the method clickedCompute
 * If neither has been clicked, run all of the default event-handling routines.
 */
        if (evt.target==leap)
        {
            clickedLeap();
            return true;
        }

        else if (evt.target==dayCount)
        {
            clickedDayCount();
            return true;
        }
        else if(evt.target==dayOfWeek)
        {
            clickedDayOfWeek();
            return true;
        }
        else
        return super.action(evt,obj);
    }
    public void clickedLeap()
    {
        int day;
        int month;
        int year;
        
        
        day=new Integer(dayEntry.getText()).intValue();                                       //number added into a text field are not integers. This is why we are using Integer with a capital I (number class)

        month=new Integer(monthEntry.getText()).intValue();
        
        year=new Integer(yearEntry.getText()).intValue();
        
        EmmaDate nd1=new EmmaDate (day,month,year);  //ndl = nd[one] not l
                                                        //EmmaDate should match what you have called it in your Class
                                                        
        EmmaDate nd2=new EmmaDate (day,month,year);
/**
 * Clear the last calculations and show all non-zero values on the applet
 */
        for(int i=0;i<12;i++)
            result[i].setText(" "); // clear last calculations
        result[0].setText("You input "+nd1);
        result[1].setText("The year "+year);
               if(nd1.leapYear())
            result[2].setText ("is a leap year");
        else
            result[2].setText ("is not a leap year");
        
   }
 
  
 
    public void clickedDayCount()

    {
        int day;
        int month;
        int year;
        
        
        
        
        day=new Integer(dayEntry.getText()).intValue();                                       //number added into a text field are not integers. This is why we are using Integer with a capital I (number class)

        month=new Integer(monthEntry.getText()).intValue();
        
        year=new Integer(yearEntry.getText()).intValue();
        
        EmmaDate nd1=new EmmaDate (day,month,year);  //ndl = nd[one] not l
                                                        //EmmaDate should match what you have called it in your Class
                                                        
        EmmaDate nd2=new EmmaDate (day,month,year);
        
        EmmaDate nd3=new EmmaDate (day,month,year);
        
   label2=new Label("Please enter second date (dd mm yyyy)");
        add(label2);
        label2.setBounds(50,400,300,25);                                  // instead of setBounds you can use reshape(135,20,115,25). Where they are in the window relevant to the top left of the window.
        
                                                                           //135 = position across, 20 = position down, 115 = width, 25 = height
       
        calc=new Button("Calculate");
        add(calc);
        calc.reshape(50,450,120,30);
        
        dayEntry2=new TextField(3);
        add(dayEntry2);
        dayEntry2.reshape(255,350,50,25);
        
        monthEntry2=new TextField(3);
        add(monthEntry2);
        monthEntry2.reshape(340,350,50,25);
        
        yearEntry2=new TextField(3);
        add(yearEntry2);
        yearEntry2.reshape(425,350,50,25);
        
        
    
    {day=new Integer(dayEntry2.getText()).intValue();                                       //number added into a text field are not integers. This is why we are using Integer with a capital I (number class)

        month=new Integer(monthEntry2.getText()).intValue();
        
        year=new Integer(yearEntry2.getText()).intValue();
        
          
        {
        calc=new Button("Calculate");
        add(calc);
        calc.reshape(50,450,120,30);
        }
        
        super.init();
        
    }
    
    
        

      if (evt.target==calc)
            
      {
                clickedCalc();
                
                return true;
      }
                else
                
                return super.action(evt,obj);
            
        
        for(int i=0;i<12;i++)
            result[i].setText(" "); // clear last calculations
        result[3].setText("You input "+nd3);
        
         
    }
 
 public void clickedDayOfWeek()
    {
        int day;
        int month;
        int year;
        
        
        day=new Integer(dayEntry.getText()).intValue();                                       //number added into a text field are not integers. This is why we are using Integer with a capital I (number class)

        month=new Integer(monthEntry.getText()).intValue();
        
        year=new Integer(yearEntry.getText()).intValue();
        
        EmmaDate nd1=new EmmaDate (day,month,year);  //ndl = nd[one] not l
                                                        //EmmaDate should match what you have called it in your Class
                                                        
        //EmmaDate nd2=new EmmaDate (day,month,year);
        
    }
}

Proper place for lines L228-L242 is
public boolean action(Event evt,Object obj)
method

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.