Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

not an enclosing class error

 
simcel jones
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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 Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
thanks very much
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic