Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Cannot Invoke Method in Container

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot call a Method that's in an applet from a components code. The component I've created (ImageButton) by having a seperate file that extends Canvas and implements MouseListener.
//--- Seperate File ( ------>
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
public class IconApplet extends Applet implements ActionListener {
Label myLabel = null;

public void init() {
URL imgURL = null;
try {
imgURL = new URL(getDocumentBase(), "bean.gif");
} catch (Exception ignore) {
Image beanImg = getImage(imgURL);
ImageButton myCanvas = new ImageButton(beanImg);
myLabel = new Label("Here is some text.", Label.RIGHT);
setLayout(new GridLayout(1, 0));
public void myChange(String strChange){
//-------Seperate File ( ----->
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
public class ImageButton extends Canvas implements MouseListener {
Image img = null;
public ImageButton(Image picture){
addMouseListener (this);
img = picture;
setSize(80, 80);
public void init() { }
public void paint(Graphics g) {
g.drawImage(img, 8, 8, 16, 16, this);
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseClicked(MouseEvent e) {
//This is where I cannto call myChange("some text");
//from the container that created this component
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vic,
You don't have a handle on the IconApplet parent so you need to walk up the tree starting from your self. If you add the following at the point of your comments (inside mouseClicked) routine it should work for you.

Evacuate the building! Here, take this tiny ad with you:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic