• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Displaying Image

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am trying to add an image to one of the layout managers. I am guessing that I would use the Canvas to do this. Can someone give me an example of how this works? I made it work by overriding the paint() and not using the layout manager. But, of coarse when I added the layout manager you couldn't see the image anymore.
Thanks!
 
Patricia Fulk
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought it might be more helpful if I just let you all see the code and find out why the image in Canvas isn't displaying on the screen.
public void init() {
leftBoardWalk = getImage(getCodeBase(),"leftBoardWalk.gif");
}
public void start() {
...
DisplayImage leftBoardWalkDisplayImage = new DisplayImage(leftBoardWalk);
...
Panel mainStartPanel = new Panel();
mainStartPanel.setLayout(new BorderLayout());
...
mainStartPanel.add(leftBoardWalkDisplayImage,BorderLayout.WEST);
...
}
class DisplayImage extends Canvas {
Image image ;

public DisplayImage(Image image) {
setBackground(Color.white);
this.image = image;
}

public void paint(Graphics g) {
update(g);
}

public void update(Graphics g) {
g.drawImage(image,0,0,this);
}
}
 
Patricia Fulk
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I figured it out. I forgot to set the size of the canvas.
reply
    Bookmark Topic Watch Topic
  • New Topic