voila je suis debutant en java, et je veux faire un damier avec des pions jai deja fait un trucs du genre je sais c pas très structuré(c juste pour tester):
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Damier extends JFrame {
JPanel [][]tab=new JPanel[14][16];
private JButton b_cactus;
private JButton b_pions;
private JLabel label;
Container cf=getContentPane();
/***************Constructeur*************/
public Damier(){
setTitle("Le Billabong");
cf.setLayout(new GridLayout(1,2));
JPanel p1=new JPanel();
JPanel p2=new JPanel();
/****************Damier*********************/
p1.setLayout(new GridLayout(14,16));
for(int i=0;i<=13;i++)
for(int j=0;j<=15;j++){
tab[i][j]=new JPanel();
p1.add(tab[i][j]);
}
for(int i=0;i<=13;i++)
for(int j=0;j<=15;j++){
if(((i+j)%2)==0){
if(i==7&&j==7||i==6&&j==8){}
else
tab[i][j].setBackground(Color.gray);
}
}
for(int i=6;i<=7;i++)
for(int j=7;j<=8;j++)
tab[i][j].setBackground(Color.blue);
cf.add(p1);
/********************* A droite du Damier*************************/
p2.setLayout(new GridLayout(3,1));
JPanel p3=new JPanel();
JPanel p4=new JPanel();
JPanel p5=new JPanel();
/*************************Panneau Score***************************/
p3.setBackground(Color.yellow);
label=new JLabel("Score");
p3.add(label);
p2.add(p3);
/*************************Bouton cactus***************************/
p4.setBackground(Color.red);
b_cactus=new JButton("Placez les cactus");
p4.add("CENTER",b_cactus);
p2.add(p4);
/********************bouton placez vos pions************************/
p5.setBackground(Color.green);
b_pions=new JButton("Placez vos pions");
p5.add("CENTER",b_pions)
p2.add(p5);
cf.add(p2);
/******************************Gestion des evenements**********************/
b_pions.addActionListener(new Del1(b_pions));
b_cactus.addActionListener(new Del1(b_cactus));
for(int i=0;i<=13;i++)
for(int j=0;j<=15;j++){
if((i==6&&j==8)||(i==7&&j==7)||(i==6&&j==7)||(
i==7&&j==8)){}
else if(((i+j)%2)==0)
tab[i][j].addMouseListener(new Del2(tab[i][j]));
else
tab[i][j].addMouseListener(new Del3(tab[i][j]));
}
/***************************Centrer la fenetre***************************/
Dimension screenSize =Toolkit.getDefaultToolkit().getScreenSize();
pack();
setLocation((screenSize.width-getWidth())/2,(scr
eenSize.height-getHeight())/2);
}
/**************************Classes Déléguées**************************/
public class Del1 implements ActionListener{
JButton bouton=new JButton();
public Del1(JButton b){
bouton=b;
}
public void actionPerformed(ActionEvent e){
System.out.println("Message 1");
bouton.setEnabled(false);
}
}
public class Del2 extends MouseAdapter{
JPanel panel=new JPanel();
Del2(JPanel p){
panel=p;
}
public void mouseClicked(MouseEvent e ){
System.out.println("Message 2");
}
public void mouseEntered(MouseEvent e){
panel.setBackground(Color.red);
}
public void mouseExited(MouseEvent e){
panel.setBackground(Color.gray);
}
}
public class Del3 extends MouseAdapter{
JPanel panel=new JPanel();
Del3(JPanel p){
panel=p;
}
public void mouseClicked(MouseEvent e ){
System.out.println("Message 2");
}
public void mouseEntered(MouseEvent e){
panel.setBackground(Color.red);
}
public void mouseExited(MouseEvent e){
panel.setBackground(Color.white);
}
}
/***************************Main******************
public static void main(String []args){
Damier da=new Damier();
da.pack();
da.setVisible(true);
}
}