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

Displaying Image

 
Patricia Fulk
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Sorry I figured it out. I forgot to set the size of the canvas.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic