• 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

No enclosing instance of type is accessible in scope

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have inherited this program from someone who left our organisation and this java code was written in visual age for java.We are trying to re-compile it all in Websphere now and I am getting this error when I compile the code in WebSphere.I know this has to do with the issue of scope but as far as I can see,I have imported the package it needs.Can anyone help me with this.Thanks in advance.
Ann
******************************************************
package fr.query.ui;
import javax.swing.plaf.*;
import javax.swing.*;
import java.awt.*;
import fr.ui.*;
import fr.query.cntl.*;
import java.util.*;
public class QueryTabbedPane
extends TexturedTabbedPane
implements Blinker, MessageDisplayCollection
{
private boolean day = true;
private final Vector blinkers = new Vector();
protected class QueryTabbedPaneUI
extends TexturedTabbedPane.TexturedTabbedPaneUI
{
protected void paintTabBackground(Graphics g,int tabPlacement,
int tabIndex,int x,int y,int w,int h,
boolean isSelected)
{
super.paintTabBackground(g,tabPlacement,tabIndex,x,y,w,h,
isSelected);
if (blinkers.contains(getComponentAt(tabIndex)))
{
Image currentTexture = day ? MESSAGE_LISTS_BLINK_TEXTURE_DAY: MESSAGE_LISTS_BLINK_TEXTURE_NIGHT;
if (getTextured() && currentTexture != null)
{
TextureComponentUtil.drawTexturedBackground
(g,TexturedTabbedPane.this, currentTexture,
x, y, x + w, y + h);
/*I get an error on this line ,saying,No enclosing instance of type
fr.ui.TexturedTabbedPane is accesible in scope.*/
}
}
}
 
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ann, I believe this is what gives you an error:

You cannot refer to TexturedTabbedPane.this in this context because TexturedTabbedPane is not an enclosing outer class for protected inner class QueryTabbedPane. What you can do, though, is to change TexturedTabbedPane.this to QueryTabbedPane.this. QueryTabbedPane is-a TexturedTabbedPane, so the argument type test should pass. It'll be your responsibility though to upcast the actual object passed to drawTexturedBackground method to TexturedTabbedPane in case you want to access its fields or static methods. Any overridden methods called will be of QueryTabbedPane object type.
Hope this helps.
[ November 17, 2003: Message edited by: Vad Fogel ]
 
Ann Ron
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That did remove my scope error but I am not sure what exactly you mean by upcasting the object passed to drawTexturedBackground to TexturedTabbedPane.
I now get another error on the preceding line of code : TextureComponentUtil.drawTexturedBackground namely,the method drawTexturedBackground() in the type fr.ui.TexturedComponentUtil() is not applicable for the arguments....
I am sorry if this is a really basic question,I am still learning Java and new to a lot of aspects...
Thanks a lot for your help.
Ann
 
Vad Fogel
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you validate the exact signature of drawTexturedBackground you're calling?
 
Ann Ron
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by validate the signature??? will that resolve my error?
 
Vad Fogel
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've moduled the problem by a simple example:

The problematic line functionally corresponds to
TextureComponentUtil.drawTexturedBackground(g,TexturedTabbedPane.this, currentTexture,x, y, x + w, y + h);
My code compiles fine. The error you're getting makes me wonder what public static drawTexturedBackground defined in TextureComponentUtil class has as argument list? Just post it here.
 
Ann Ron
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am pasting the whole TexturedComponentUtil class here.
******************************************************
package fr.ui;
import java.awt.*;
import javax.swing.*;

public final class TextureComponentUtil {
/**
* Tiles a texture across a range
* @param g the graphics object used for drawing
* @param component the component that needs to be drawn
* @param bgImage the texture
* @param x1 the starting x location, which may be negative
* @param y1 the starting y location, which may be negative
* @param x2 the ending x location, which must be larger than x1
* @param y2 the ending y location, which must be larger than y2
*/
public static final void drawTexturedBackground(Graphics g, Component component, Image bgImage, int x1, int y1, int x2, int y2) {
if (g == null || component == null || bgImage == null) {throw new NullPointerException();}
if (x2 < x1 || y2 < y1) {return;}
int imageWidth = bgImage.getWidth(component), imageHeight = bgImage.getHeight(component);
// the number of complete rows and columns
int numX = (x2-x1)/imageWidth;
int numY = (y2-y1)/imageWidth;
// start at left
int drawX = x1;
// get everything across until the last incomplete column
for (int x = 0; x<numX; x++) {
// start at top
int drawY = y1;
for (int y=0; y<numY; y++) {
g.drawImage(bgImage, drawX, drawY, component);
// move down one space
drawY += imageHeight;
}
// this completes the column
g.drawImage(bgImage, drawX, drawY, drawX+imageWidth, y2, 0,0, imageWidth, y2-drawY, component);
drawX += imageWidth;
}
// get the last column except for the last little box
int drawY = y1;
for (int y=0; y<numY; y++) {
g.drawImage(bgImage, drawX, drawY, x2, drawY+imageHeight, 0, 0, x2-drawX, imageHeight, component);
drawY+= imageHeight;
}
// now draw whatever is leftover, which is smaller than one texture unit
g.drawImage(bgImage, drawX, drawY, x2, y2, 0, 0, x2-drawX, y2-drawY, component);
}
/**
* Tiles a texture across a range
* @param g the graphics object used for drawing
* @param component the component that needs to be drawn
* @param bgImage the texture
*/
public static final void drawTexturedBackground(Graphics g, JComponent component, Image bgImage) {
drawTexturedBackground(g, component, bgImage, 0, 0, component.getWidth(), component.getHeight());
}
}
 
Vad Fogel
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ann, if you can make sure that TexturedTabbedPane extends java.awt.Component, that should solve the problem. However, if it already extends something else, we'll go further with another workaround.
 
Ann Ron
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
It already extends JTabbedPane.cant we make it extend two saperate classes...?I am sorry for asking such novice questions..
public class TexturedTabbedPane extends JTabbedPane implements SelectableTexturedComponent, BackgroundTexturedComponent.
Thanks..
 
Vad Fogel
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There was a typo in my first post. QueryTabbedPaneUI.this should read QueryTabbedPane.this. I already edited the post.
JTabbedPane is-a Component. I don't see any problem with the method call. Just change the code in the method call from QueryTabbedPaneUI.this to QueryTabbedPane.this and try to compile it again. Here's your method call:

[ November 17, 2003: Message edited by: Vad Fogel ]
 
Ann Ron
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was it!! Thanks a lot...for your help.
Ann
 
reply
    Bookmark Topic Watch Topic
  • New Topic