Results 1 to 3 of 3
  1. #1
    kevzspeare is offline Member
    Join Date
    Nov 2008
    Posts
    30
    Rep Power
    0

    Default Event handling... help?

    I'm trying to add events in my program. Here is my code:

    Java Code:
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class MainProgram
    {
    	String name0x1;
    	TravellingPackage prog[] = new TravellingPackage[10];
    	Frame phi;
    	Button beta;
    	Choice tau;
    	TextField alpha1, alpha2, alpha3, nu, chi;
    	Label lambda, lambda2, theta1, theta2, theta3,
    	theta3a, theta3b, theta3c, theta4;
    	Panel header, pi, pi2, pi3, pi3a, pi4, pi5, footer;
    	public static void main (String args[]) throws IOException
    	{
    		MainProgram main = new MainProgram();
    		main.addComponents();
    	}
    	public void addComponents()
    	{
    		File data = new File ("report.txt");
    		int q = 0;
    		phi = new Frame("MKDL Travel Agency System Ver. I");
    		phi.setLayout(null);
    		phi.setSize(500,500);
    		phi.setResizable(false);
    		phi.setLocation(100,100);
    		phi.setBackground(Color.gray);
    		header = new Panel();
    		pi = new Panel();
    		pi2 = new Panel();
    		pi3 = new Panel();
    		pi3a = new Panel();
    		pi4 = new Panel();
    		pi5 = new Panel();
    		footer = new Panel();
    		header.setSize(400,50);
    		header.setLocation(50,50);
    		header.setBackground(Color.orange);
    		pi.setSize(400,50);
    		pi.setLocation(50,100);
    		pi.setBackground(Color.blue);
    		pi2.setSize(400,50);
    		pi2.setLocation(50,150);
    		pi2.setBackground(Color.red);
    		pi3.setSize(400,50);
    		pi3.setLocation(50,200);
    		pi3.setBackground(Color.yellow);
    		pi3a.setSize(400,50);
    		pi3a.setLocation(50,250);
    		pi3a.setBackground(Color.yellow);
    		pi4.setSize(400,50);
    		pi4.setLocation(50,300);
    		pi4.setBackground(Color.magenta);
    		pi5.setSize(400,50);
    		pi5.setLocation(50,350);
    		pi5.setBackground(Color.green);
    		footer.setSize(400,50);
    		footer.setLocation(50,400);
    		footer.setBackground(Color.pink);
    		beta = new Button("Calculate Fare");
    		tau = new Choice();
    		lambda = new Label("MKDL Travel Agency System Ver. I");
    		lambda2 = new Label("(C) 2009 MKDL Studios. All rights reserved.");
    		alpha1 = new TextField("",2);
    		alpha2 = new TextField("",2);
    		alpha3 = new TextField("",2);
    		theta1 = new Label("Agent's Name");
    		theta2 = new Label("Travelling Method");
    		theta3 = new Label("Number of Tourists");
    		theta3a = new Label("Age Below 2");
    		theta3b = new Label("Age 2-16");
    		theta3c = new Label("Age Above 16");
    		theta4 = new Label("Total Fare:");
    		nu = new TextField("",30);
    		chi = new TextField("",20);
    		tau.add("Bus");
    		tau.add("Cruise");
    		tau.add("Airplane");
    		beta = new Button("Calculate Fare");
    		header.add(lambda);
    		pi.add(theta1);
    		pi.add(nu);
    		pi2.add(theta2);
    		pi2.add(tau);
    		pi3.add(theta3);
    		pi3a.add(theta3a);
    		pi3a.add(alpha1);
    		pi3a.add(theta3b);
    		pi3a.add(alpha2);
    		pi3a.add(theta3c);
    		pi3a.add(alpha3);
    		pi4.add(beta);
    		pi5.add(theta4);
    		pi5.add(chi);
    		footer.add(lambda2);
    		phi.add(header);
    		phi.add(pi);
    		phi.add(pi2);
    		phi.add(pi3);
    		phi.add(pi3a);
    		phi.add(pi4);
    		phi.add(pi5);
    		phi.add(footer);
    		phi.setVisible(true);
    	}
    	
    }
    But if I add "implements ActionListener" at the end of the class name like this:

    Java Code:
    public class MainProgram implements ActionListener
    an error message is displayed:

    Java Code:
    --------------------Configuration: <Default>--------------------
    E:\mkdl\archive1\jp219\MainProgram.java:5: MainProgram is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
    public class MainProgram implements ActionListener
           ^
    1 error
    
    Process completed.
    What should I do??

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    The tutorials will tell you that if a class implements in interface, then it must actually implement the methods of the interface, something your class is not doing. Reading the links that Darryl has generously provided for you will tell you how to do this and why it's important.

Similar Threads

  1. Event handling in JSF
    By java08 in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 03-24-2009, 06:42 AM
  2. rmi and event handling
    By darkhorse in forum Advanced Java
    Replies: 0
    Last Post: 03-15-2009, 08:20 AM
  3. SWT Event Handling
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-30-2007, 12:21 PM
  4. problem with event handling!!!
    By ahdus in forum Java Applets
    Replies: 1
    Last Post: 11-17-2007, 06:24 PM
  5. Event Handling
    By luisarca in forum Sun Java Wireless Toolkit
    Replies: 5
    Last Post: 05-07-2007, 06:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •