- , , . , , - , . , - ( ):
class GridPanel extends JPanel{
JLabel mountain, map, animal;
public GridPanel(JPanel panel){
super();
setLayout(new GridLayout(2, 2));
animal = new JLabel(new ImageIcon(getClass().getResource("pictures/animal.gif")));
map = new JLabel(new ImageIcon(getClass().getResource("pictures/map.gif")));
mountain = new JLabel(new ImageIcon(getClass().getResource("pictures/mountain.gif")));
add(panel);
add(mountain);
add(map);
add(animal);
}
}
, , . coud . , , :
JPanel grid = new GridPanel(new JPanel());
for(int i = 1; i <= 5; i++){
grid = new GridPanel(grid);
}
add(grid);
JPanel. . .., , .. . 5 .
, ImageIO . , BufferedImage, , :
BufferedImage mointainImg = ImageIO.read(new File("pictures/mountain.gif"));
JLabel, :
mountain = new JLabel(new ImageIcon(mountainImg));
, , .