• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

not an enclosing class error

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
does anyone know why I am getting this error message

Soundmap.java:94: not an enclosing class: java.applet.Applet
Graphics g = Applet.this.getGraphics();
the offending code is below

public void mousePressed(MouseEvent e) {
ImagemapRectangle r = findrect(e);
if (r == null) return;
Graphics g = Applet.this.getGraphics();
g.setXORMode(Color.red);
g.drawRect(r.x, r.y, r.width, r.height);
Applet.this.showStatus("To: " + r.url);
sound.play();
lastrect = r;
}

many thanks for your help
simon
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simcel,
Your inner class looks like it is expecting the outer class to extend Applet... since you have not posted the entire code... Is your outer class extending Applet?
HTH,
-Nate
 
simcel jones
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Nate

these are the opening lines of my code
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;

public class Soundmap extends Applet {
thanks for your help
simon
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simcel,
Oh... OK... I am stupid... ( *slaps head* ) change the code to this:

( i.e. - change all references from Applet to Soundmap.... you have to reference the class directly enclosing the inner class...)
HTH
-Nate
 
simcel jones
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks very much
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic