From: Sam Takoy on 16 Mar 2010 11:12 Hi, The following code doesn't compile with the error: "No enclosing instance of the type JPanel is accessible in scope" but isn't my class a JPanel? Many thanks in advance! Sam import java.awt.event.*; import javax.swing.JPanel; public class MyClass extends JPanel { public class MyMouseLisetener extends MouseAdapter { public void mouseClicked(MouseEvent e) { JPanel.this.revalidate(); } } }
From: Thomas Richter on 16 Mar 2010 11:15 Sam Takoy wrote: > Hi, > > The following code doesn't compile with the error: > > import java.awt.event.*; > import javax.swing.JPanel; > > public class MyClass extends JPanel { > > public class MyMouseLisetener extends MouseAdapter { > public void mouseClicked(MouseEvent e) { > JPanel.this.revalidate(); > } > } > > } > > "No enclosing instance of the type JPanel is accessible in scope" > > but isn't my class a JPanel? No, obviously not - it is a MouseAdapter. "this" always refers to the class the member function is part of. So long, Thomas
From: Sam Takoy on 16 Mar 2010 11:23 Thomas Richter wrote: > Sam Takoy wrote: >> Hi, >> >> The following code doesn't compile with the error: > > >> import java.awt.event.*; >> import javax.swing.JPanel; >> >> public class MyClass extends JPanel { >> >> public class MyMouseLisetener extends MouseAdapter { >> public void mouseClicked(MouseEvent e) { >> JPanel.this.revalidate(); >> } >> } >> >> } > >> "No enclosing instance of the type JPanel is accessible in scope" >> >> but isn't my class a JPanel? > > No, obviously not - it is a MouseAdapter. "this" always refers to the > class the member function is part of. > > So long, > Thomas Are you guessing or giving an educated answer? My impression (perhaps false) was that the device I was attempting to use was designed for the specific purpose of going up to the enclosing class.
From: Sam Takoy on 16 Mar 2010 11:28 Stefan Ram wrote: > Sam Takoy <samtakoy(a)yahoo.com> writes: >> JPanel.this.revalidate(); > > This (no pun intended) should be: > > MyClass.this.revalidate(); > > . > Yup - thank you!
From: Alessio Stalla on 16 Mar 2010 11:32 On Mar 16, 4:23 pm, Sam Takoy <samta...(a)yahoo.com> wrote: > Thomas Richter wrote: > > Sam Takoy wrote: > >> Hi, > > >> The following code doesn't compile with the error: > > >> import java.awt.event.*; > >> import javax.swing.JPanel; > > >> public class MyClass extends JPanel { > > >> public class MyMouseLisetener extends MouseAdapter { > >> public void mouseClicked(MouseEvent e) { > >> JPanel.this.revalidate(); > >> } > >> } > > >> } > > >> "No enclosing instance of the type JPanel is accessible in scope" > > >> but isn't my class a JPanel? > > > No, obviously not - it is a MouseAdapter. "this" always refers to the > > class the member function is part of. > > > So long, > > Thomas > > Are you guessing or giving an educated answer? My impression (perhaps > false) was that the device I was attempting to use was designed for the > specific purpose of going up to the enclosing class. You have to use MyClass.this, not JPanel.this. The enclosing class is not JPanel, it's MyClass. Alessio
|
Next
|
Last
Pages: 1 2 Prev: Cross Platform/Browser way to send PNG file to Webserver Next: JLabel.setText |