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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| // Le constructeur
public Jeu(int n, int p)
{
nbLig = n;
nbCol = p;
// Grille de jeu = cadre au centre
JPanel cadreCentre = new JPanel();
cadreCentre.setLayout((new GridLayout(nbLig,nbCol,4,4)));
cases = new JButton[nbLig][nbCol];
for (int i = 0; i <nbLig; i++)
{
for (int j = 0; j <nbCol; j++)
{
cases[i][j] = new JButton();
cases[i][j].setFont(new Font("Verdana", Font.BOLD, 30));
cases[i][j].setText("");
cases[i][j].addKeyListener(this);
cadreCentre.add(cases[i][j]);
}
}
// Fenêtre du jeu
JFrame jeu = new JFrame();
jeu.setSize(500,500);
jeu.add(cadreCentre);
jeu.setVisible(true);
}
public void paintComponent(Graphics g)
{
g.setColor(new Color(254, 247, 235));
g.fillRect(0, 0, 460, 599);
g.setColor(new Color(84, 84, 84));
g.setFont(new Font("Verdana", Font.PLAIN, 13));
g.drawString("Joins les nombres et atteins la case", 40, 110);
g.setFont(new Font("Verdana", Font.BOLD, 13));
g.drawString("2048 !", 282, 110);
g.setFont(new Font("Verdana", Font.BOLD, 50));
g.drawString("2048", 40, 70);
g.setColor(new Color(187, 173, 160));
g.fillRoundRect(43, 143, 371, 371, 3, 3);
g.fillRoundRect(302, 20, 110, 50, 11, 11);
g.setColor(new Color(237, 224, 200));
g.setFont(new Font("Verdana", Font.BOLD, 17));
g.drawString("Score", 330, 40);
} |
Partager