1 pièce(s) jointe(s)
Supprimer espace GridLayout
Hello !
Je bosse sur un projet dans lequel je dois créer un jeu du même style que CandyCrush (Ouais...)
Bref, j'ai utilisé GridLayout pour afficher mes boules et comme vous pouvez le voir sur l'image, je n'arrive pas à supprimer l'espace entre chaque image.
Pièce jointe 167931
J'ai essayé avec setHgap et setVgap, mais sans succès.
Voilà mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
public WindowVue() throws IOException
{
this.gamePanel = new GamePanel();
//this.content = this.gamePanel.createPanel();
initUI();
}
/**
* Initiate a basic window
*/
private void initUI(/*ArrayList panelList*/)
{
this.setTitle("ElementZ"); // Title of the window
// add(new Axes());
// this.setContentPane(this.content); // Warn the JFrame that the panel will be his contentpane
this.getContentPane().add(this.gamePanel); // Warn the JFrame that the panel will be his contentpane
this.setSize(800, 650);
this.setLocationRelativeTo(null); // Put the window in the middle of the screen
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Exit the windwo when you click on the red button
this.setVisible(true); // Set the window visible
}
} |
La classe GamePanel :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
public class GamePanel extends JPanel
{
// Variables' and class's declaration
private Panneau panelList[][];
// private JPanel bigPanel;
public GamePanel() throws HeadlessException
{
super();
GridLayout gbl = new GridLayout(8,8,0,0);
panelList = new Panneau[8][8];
this.setLayout(gbl);
for(int i = 0; i <= 7; i++)
{
for(int j = 0; j <= 7; j++)
{
Panneau panneau = new Panneau(); // Line
add(panneau);
panelList[i][j] = panneau;
}
}
}
} |
Et enfin, la classe "Panneau" :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
public class Panneau extends JPanel {
// Variables' and class's declaration
private Image img;
public Panneau()
{
super();
}
/**
* Add an image to the window
*
* @param graphic
*/
@Override
public void paintComponent(Graphics graphic)
{
// Try to add the image
try
{
this.img = ImageIO.read(new File("boule_0.jpg")); // Put the image into the buffer
graphic.drawImage(this.img, 0, 0, this.img.getWidth(null), this.img.getHeight(null), null); // Draw the image
}
catch (IOException ex)
{
Logger.getLogger(WindowVue.class.getName()).log(Level.SEVERE, null, ex);
}
// TODO : Ajouter une fonction random pour ajouter aléatoirement une boule à un panel
}
} |
Est ce que vous auriez une idée ?
Merci !
Steackfrite