This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Images

 
Terry Stehle
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have extended the class JPanel like this
import java.awt.*;
import java.swing.*;
public class CustomPanel extends JPanel{
public CustomPanel(){
repaint();
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.drawImage(someimg,0,0,this); //this works fine
but when I try to draw images from an array of images like this
int index = 1;
for(int i = 1; i<4; i++ {
g.drawImage(imgList[index++],0,0,this) //I get an error
}
}
}
My code is different from the above but the concept is the same. Im currently working on a chess program. I have a class called squares which holds the image of the piece that occupies the square with the horz and vertical coordinates of that piece. My actual code checks to see if the square is occupied if it is then it will call the g.drawImage(Square.getImage(colNum,rowNum),Square.getHorz(colNum,rowNum),Square.getVert(colNum,rowNum),this); //Im certain that there are no problems with the class Square. If this is not possible to do in this way. Then maybe someone can tell me how I can create an Image of the board with the pieces on it. So I can just use paintComponent to draw one Image instead of a list of images. I would appricaite any help. Thanks Terry Stehle
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic