permaculture playing cards
The moose likes Beginning Java and the fly likes Images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Images" Watch "Images" New topic


Terry Stehle

Joined: Mar 24, 2001
Posts: 24
I have extended the class JPanel like this
import java.awt.*;
import java.swing.*;
public class CustomPanel extends JPanel{
public CustomPanel(){
public void paintComponent(Graphics 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
I agree. Here's the link:
subject: Images
It's not a secret anymore!