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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.lang.*;
import java.util.*;
class yam extends JPanel implements ActionListener{
JPanel ardoise = new JPanel();
JPanel carre = new JPanel();
JPanel ensemble = new JPanel();
JButton b1 = new JButton ("Commencer");
JButton b3 = new JButton ("Tirage");
JButton b2 = new JButton ("Quitter");
Font titre = new Font("TimesRoman",Font.BOLD,25);
Font mafonte = new Font("TimesRoman",Font.BOLD,25);
int coord [] = {29,89,149,209,269};
static Random r = new Random();
int i = 0;
yam() {
//setLayout(new FlowLayout());
setLayout(new BorderLayout());
ardoise.add(b1);
ardoise.add(b2);
ardoise.add(b3);
add(ardoise,BorderLayout.EAST);
add(carre,BorderLayout.WEST);
//add(ensemble);
carre.setLayout(new BorderLayout());
carre.setPreferredSize(new Dimension(400, 300));
//ensemble.setPreferredSize(new Dimension(700,500));
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
/*public void paint (Graphics g){
i++;
//g.setFont(titre);
//g.drawString("BIENVENUE SUR YAM 1.0",10,50);
//g.setFont(mafonte);
//g.setColor(Color.red);
//g.drawRect(10,100,50,50);
//g.drawRect(70,100,50,50);
//g.drawRect(130,100,50,50);
//g.drawRect(190,100,50,50);
//try {
// Thread.sleep(500);
// } catch(InterruptedException f){ System.out.println("attention");}
//g.drawRect(250,100,50,50);
//g.setColor(Color.black);
System.out.println(i);
//afficheChiffre(g,tirageChiffre());
}*/
public void paintComponent(Graphics g){
//super.paintComponent(g);
//g = carre.getGraphics();
g.setFont(titre);
g.drawString("BIENVENUE SUR YAM 1.0",10,50);
System.out.println("prob");
//afficheTitre(g);
}
public void afficheTitre(Graphics g){
g.setFont(titre);
g.drawString("BIENVENUE SUR YAM 1.0",10,50);
}
public void afficheChiffre(Graphics g,int tab []){
g.setColor(Color.black);
g.setFont(mafonte);
for (int i = 0; i < 5; i++)
g.drawString(String.valueOf(tab[i]),coord[i],133);
}
public int [] tirageChiffre (){
int chiffre [] = new int [5];
double tamp;
for (int i = 0; i < 5 ; i++){
tamp = Math.random() * 6 + 1;
chiffre[i] = r.nextInt(6) + 1;
}
return chiffre;
}
public void actionPerformed (ActionEvent e){
Graphics g = carre.getGraphics();
if (e.getSource() == b1){
g.setColor(Color.red);
g.drawRect(10,100,50,50);
g.drawRect(70,100,50,50);
g.drawRect(130,100,50,50);
g.drawRect(190,100,50,50);
g.drawRect(250,100,50,50);
afficheChiffre(g,tirageChiffre());
}
if (e.getSource() == b2)
System.exit(0);
if (e.getSource() == b3) {
//repaint();
repaint(carre);
}
}
public static void main (String argv[]){
JFrame affiche = new JFrame();
affiche.setContentPane(new yam());
affiche.pack();
affiche.setVisible(true);
}
} |
Partager