Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Make buttons work in a runnable applet

Posted on 2004-04-18
5
Medium Priority
?
842 Views
Last Modified: 2013-11-23
OK, it's been a long time since I did anything with java and I run into a stumper.  I have an applet (public class animate extends Applet implements Runnable  ) and in general terms it operates a counter within it that determines the behaviour of the applet.  Anyways, my problem is that I would like to load the applet and make it start based on a button but I can't figure out how.  In my init() I have a button (one button only)
      
                StartB.addActionListener(this);
      add(StartB);

Now the compiler complains as follows:  "Value for argument 1 cannot be converted from 'animate' in call to 'voidButton.addActionListener(ActionListener)"  This error refers to StartB.addActionListener(this);  I think the problem is that it implements Runnable instead of a ActionListener, but I think I had it working once (when I did more java) under runnable without implementing action listener.

OK, what am I missing and what is the simplest fastest solution to this problem?  Btw, I'm running Visual J++ on a win2k Virtual Machine.

Thanks
0
Comment
Question by:Kejtar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 92

Expert Comment

by:objects
ID: 10856243
your applet class needs to implement ActionListener

public class animate extends Applet implements Runnable. ActionListener

You also need to add an actionPerformed() method which will get called when the button is pressed.

public void actionPerformed(ActionEvent event)
{
   // do whatever required here
}
0
 
LVL 1

Author Comment

by:Kejtar
ID: 10856314
ok, but I need to implement Runnable as well, and IIRC java right it's one or the other: can't implement both Runnable and ActionListener at the same time, or can I?

Btw, I do have actionPerformed, but....  due to the button problems, I can't get to it :(
0
 
LVL 92

Accepted Solution

by:
objects earned 1000 total points
ID: 10856321
> can't implement both Runnable and ActionListener at the same time, or can I?

you can.

A little type in the code i posted above it should have been a comman and not a dot.

public class animate extends Applet implements Runnable, ActionListener
0
 
LVL 1

Author Comment

by:Kejtar
ID: 10856344
Thanks, that was it.  This also proves my theory that all problems in programming revolve around comma, period or semi colon :D
0
 
LVL 92

Expert Comment

by:objects
ID: 10856358
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question