Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-17-2003, 11:14 AM   PM User | #1
Aymen++
Regular Coder

 
Join Date: Nov 2002
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Aymen++ is an unknown quantity at this point
problem in java

i have the following code:
Code:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;

public class Revolve extends Applet {
     String[] pageTitle = new String[6];
     URL[] pageLink = new URL[6];
     int current = 0;
     Thread runner;

     public void init() {
         Color background = new Color(255, 255, 204);
         setBackground(background);
         Button goButton = new Button("Go");
         goButton.addActionListener(this);
         add(goButton);
      }
 }
but when i excute it in JCreator the following error appears:
addActionListener(java.awt.event.ActionListener) in java.awt.Button cannot be applied to (Revolve)
why?
Aymen++ is offline   Reply With Quote
Old 03-17-2003, 05:14 PM   PM User | #2
Josh Campbell
New Coder

 
Join Date: Jun 2002
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Josh Campbell is an unknown quantity at this point
The object that listens for action must implement ActionListerner, your applet does not.
Josh Campbell is offline   Reply With Quote
Old 03-17-2003, 05:25 PM   PM User | #3
Aymen++
Regular Coder

 
Join Date: Nov 2002
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Aymen++ is an unknown quantity at this point
how can i solve it?
Aymen++ is offline   Reply With Quote
Old 03-17-2003, 07:19 PM   PM User | #4
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
As Josh just said if you want to use the addActionListener method you need to implement the ActionListener class.


public class Revolve extends Applet implements ActionListener {




}
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 03-17-2003, 08:52 PM   PM User | #5
Josh Campbell
New Coder

 
Join Date: Jun 2002
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Josh Campbell is an unknown quantity at this point
And you must define all the methods in the ActionListener interface. I think theres only one (I could be wrong) but its:

public void actionPerformed(ActionEvent evt);

if I'm not mistaken.
Josh Campbell is offline   Reply With Quote
Old 03-17-2003, 09:32 PM   PM User | #6
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
Yes you must also define that method. Something like this for example:

PHP Code:

    
public void actionPerformed(ActionEvent event){
      
String menuItemName event.getActionCommand();

        if(
menuItemName.equals("Quit")){
            
System.exit(0);
        }

        else if(
menuItemName.equals("Circle")){
            
whichShape 0;
        }
        else if(
menuItemName.equals("Square")){
            
whichShape 1;
        }
        else if(
menuItemName.equals("Rectangle")){
            
whichShape 2;
        }
        else if(
menuItemName.equals("Arc")){
            
whichShape 3;
        }
    } 
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 03-17-2003, 09:53 PM   PM User | #7
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,220
Thanks: 4
Thanked 80 Times in 79 Posts
Spookster will become famous soon enough
Or in your case since you have a button you could define it like so:

PHP Code:
public void actionPerformed(ActionEvent event){
        if(
event.getSource() instanceof Button){
            
Button clickedButton = (Buttonevent.getSource();
            if(
clickedButton == goButton){
                
//Action to perform when go button clicked
            
}
         }

__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:59 PM.


Advertisement
Log in to turn off these ads.