Solved

Make buttons work in a runnable applet

Posted on 2004-04-18
5
836 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 250 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Should localization be done inside spring controller 5 37
Way to decrease size of apk file 9 112
Java: anonymous class 4 39
passing enum to a method 4 37
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
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 about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

697 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