in this code i want to appear 8 icon in one row and their is an equal space between each icon
i do this but 4 icons only appear why ??
my code:
first class:
________
import javax.swing.JFrame;
public class RandomDemo extends JFrame {
private TestRandom random;
public RandomDemo() {
random=new TestRandom();
getContentPane().add(random);
}
public static void main(String[] args) {
JFrame frame=new RandomDemo();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 300);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
second class:
_______________
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class TestRandom extends JPanel {
private BufferedImage image;
private Graphics g;
private ImageIcon wall1;
private int wall1_size=40;
public TestRandom() {
image = new BufferedImage(1000, 1000, BufferedImage.TYPE_INT_RGB);
g = image.getGraphics();
g.fillRect(0, 0, 1000, 1000);
g.setColor(Color.WHITE);
wall1 = new ImageIcon(getClass().getResource("wall.gif"));
int x=(image.getWidth()-(wall1.getIconWidth()+wall1_size)*7)/2;
for (int i = 0; i <=7; ++i) {
wall1.paintIcon(this, g, (wall1.getIconWidth()+wall1_size)+ x*i , 0 );
repaint();
}
}
@Override
public void paintComponent(Graphics g) {
super.paintComponents(g);
g.drawImage(image, 0, 0, null);
}
}
the icon i use in this link
http://www.4shared.com/file/75186018/c080da00/icon.html