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
Solved

Make buttons work in a runnable applet

Posted on 2004-04-18
5
834 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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HashTable highest marks enumeration alternative 9 43
use lov values 2 61
spring jars download 1 35
Java class and jar 3 21
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

840 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