Afficher des images ! [URGENT SVP]

Résolu/Fermé
BloodShinX Messages postés 507 Date d'inscription lundi 5 janvier 2009 Statut Membre Dernière intervention 31 juillet 2016 - 12 mai 2013 à 15:05
BloodShinX Messages postés 507 Date d'inscription lundi 5 janvier 2009 Statut Membre Dernière intervention 31 juillet 2016 - 12 mai 2013 à 16:13
Bonjour,
j'ai un programme à rendre, et je sais pas comment faire pour afficher des images
c'est un "Qui est ce", j'ai 24 persos, je veux afficher 24 images:
j'ai donc 24 canvas, mais je ne sais pas comment je met des images dedans :(

J'ai vraiment besoin d'aide !!
Ou je peux remplacer les canvas par des JLabel, JPanel??

Merci, c'est très important :
voici mon code:

import java.awt.BorderLayout;
import java.util.Arrays;
import java.util.Collections;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;


public class assemblage {
	static boolean[] affichage={true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true};
	static int restant=0;	
	static Label victoire;
	static String[] noms;
	
	
////////// FONCTIONS permettant la victoire "brutale"=quand 1 personnage reste debout ///////////////
////////////////////////////////////////////////////////////////////////////////////////////////
	static int restant(boolean[] affichage){
		int restant=0;
		for(int n=0;n<affichage.length;n++){  //calcule le nombre de personnages debout à chaque clique sur un canvas.
			if(affichage[n]){
				restant=restant+1;
			}			
		}	
		return(restant);
		
	}
	
	static int position(boolean[] affichage){ //trouve la position (le numéro) du personnage debout
		int position=0;
		
		for(int i = 0; i<affichage.length; i++)
	    {    
			if (affichage[i]){
				position=i;
			}
	    } 	
		return(position);
	}
	
	
	static boolean victoire(boolean[] affichage,int choix) { //victoire si ce personnage = personnage choisis par l'ordi.
		boolean result=false;
		int position=position(affichage);				
		System.out.println("pos : "+position+" et le choix :"+choix);		
			if(position==choix){
			  result=true;
			}
			else{
			result=false;
			}
		
		return(result);
	}	
////////////:::::::::::////////////:::::::::::        PROCEDURE POUR LA VICTOIRE "brutale" ////////////:::::::::::
	static void fait(Canvas canvas,int a,org.eclipse.swt.graphics.Color c,Label victoire,String[] noms,int choix){
		restant=0;
		a=a-1;
		if (affichage[a]){
		canvas.setBackground(SWTResourceManager.getColor(77, 77, 77));
		}
		else{
		canvas.setBackground(c);	
		}
		affichage[a]=!affichage[a];		
		
		//test de victoire
		if (restant(affichage)==1)
		{					
			if (victoire(affichage,choix)) 
				{
					victoire.setText("VICTOIRE!! tu as trouvé  "+noms[choix]);
			
				}
			else{
				 victoire.setText("Perdu!! "+noms[choix]);
			}
		}
				
	}
	
	/////////////////////////////////////////////////////////Fin des fonctions////////////////////////////////
    ////////:::::::::::////////////:::::::::::////////////   et PROCEDURE ////////////::::::::::://///////////
	
	
	//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
	//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
	//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\	
	//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
	//\\//\\//\\//\\//\\//\\//\\//\\//\\//                              //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
	//\\//\\//\\//\\//\\//\\//\\//\\//\\//                              /\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
	//\\//\\//\\//\\//\\//\\//\\//\\//\\//      DEBUT DU PROGRAMME      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\\//\\//\\//\
	//\\//\\//\\//\\//\\//\\//\\//\\//\\//                              //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
	//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
	//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
	//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
	//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\

		
	public static void main(String[] args) {
				
		
		Display display = Display.getDefault();
		Shell shell = new Shell();
		shell.setSize(1707, 1041);
		shell.setMaximized(true);
		shell.setFullScreen(true);
		shell.setText("QUI EST CE?");
				//Tableau de caractères de chaques personnages
		final boolean [][] caractref={ //LISTE DES CARACTERES DE CHAQUE PERSONNAGES
				//homme//femme//bleus/verts/marrons//long/courts/Chauve//Barbe//lunettes//noire/blanche/bronzee
				{false,false,false,false,true,false,true,false,false,true,true,true,false},
				{true,false,false,false,true,false,false,false,true,true,true,true,false},
				{true,false,false,false,true,false,true,false,false,true,true,true,false},
				{true,false,false,false,true,false,true,false,false,true,true,true,false},
				{true,false,false,false,true,false,true,false,false,true,true,true,false},
				{false,false,false,false,true,false,true,false,false,true,true,true,false},
				{false,false,false,false,true,false,true,false,false,true,true,true,false},
				{true,false,false,false,true,false,true,false,false,true,true,true,false},
				{true,false,false,false,true,false,true,false,false,true,true,true,false},
				{true,false,false,false,true,false,true,false,false,true,true,true,false},
				{true,false,false,false,true,false,true,false,false,true,true,true,false},
				{true,false,false,false,true,false,true,false,false,true,true,true,false},
				{true,false,false,false,true,false,true,false,false,true,true,true,false},
				{true,false,false,false,false,false,true,false,false,true,true,true,false},
				{true,false,false,false,true,false,true,false,false,true,true,true,false},
				{true,false,false,false,true,false,true,false,false,true,true,true,false},
				{true,false,false,false,true,false,true,false,false,true,true,true,false},
				{true,false,false,false,true,false,true,false,false,true,true,true,false},
				{true,true,true,true,true,true,true,true,true,true,true,true,true},
				{true,false,false,false,true,false,true,false,false,true,true,true,false},
				{true,false,false,false,true,false,true,false,false,true,true,true,false},
				{true,false,false,false,true,false,true,false,false,true,true,true,false},
				{true,false,false,false,true,false,true,false,false,true,true,true,false},
				{true,false,false,false,true,false,true,false,false,true,true,true,false}};
		
			//nous les mélangerons ensuite selon la liste aléatoire.
		
		//Tableau initial sans mélange
		final String [] noms={"M.Alexandre","M.Oudran","M.Jean-Eudes","M.Eudes","M.Fappe","M.Patrick","M.Rambo","M.Arnold",
				"M.Berns","M.Onche","M.Flamby","M.Guedindin","Melle Mojji","Melle Vettan","Melle Pauler","Melle Etzer",
				"Melle Elizabeth","Melle Claire","Melle Dudu","Melle Boulbeur",
				"Melle Kilag","Melle Dabidabou","Melle Sladiniev","Melle Ianian"};
		
		String[] nomsref = (String[])noms.clone(); //on crée une copie de noms[] avant qu'il soit mélangé
		
		//caractref et nomsref sont les tableaux qui sont associés, et qui ne seront pas modifiés.
		
		java.util.List<String> list = Arrays.asList(noms); //convertissons le tableau en liste	pour le mélange			
		Collections.shuffle(list); //shuffle est un bon mélangeur "pseudo-aléatoire"
	
				
		final boolean [][] caract={{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}};
		//ce tableau sera le nouveau tableaux de caractères qui sera associé aux noms qui ont été mélangés.
		
		
		
		//////// Réattribuons les caractères aux personnages mélangés //////////
		
		for(int i=0;i<24;i++){
			for(int k=0;k<24;k++){
				if(nomsref[i].equals(noms[k])){
					caract[k]=caractref[i];				
				}
			}			
		}
		//////////////////////////////////////
		
		
		final int choix= (int) (Math.random()*noms.length); // séléction du personnage à trouver
		System.out.println("choix: "+choix+" est :"+noms[choix]);
		
						
		 final Combo question = new Combo(shell, SWT.SINGLE | SWT.BORDER); //menu déroulant principal des questions
		 question.setForeground(SWTResourceManager.getColor(255, 0, 0));
		 question.setFont(SWTResourceManager.getFont("Segoe UI", 18, SWT.BOLD | SWT.ITALIC));
		 question.setBackground(SWTResourceManager.getColor(255, 255, 204));
		   question.setBounds(690, 211, 496, 40);
		   question.setItems(new String[] {"Est ce un homme ?", "Est ce une femme ?",
				   "A t'il les yeux bleus ?", "A t'il/elle les yeux marrons ?", "A t'il/elle les yeux verts ?", 
				   "A t'il/elle les cheuveux longs ?", "A t'il/elle les cheveux courts ?","Est il chauve ?"
				   ,"A t'il une barbe ?",
				   "A t'il des lunettes ?","Est ce qu'il/elle est de peau noir/noire ?"
				   ,"Est ce qu'il/elle est de peau blanche ?","Est ce qu'il/elle est de peau bronzée ?"});

		  
		   
		   final Combo ultime = new Combo(shell, SWT.SINGLE | SWT.BORDER);		  
		   ultime.setFont(SWTResourceManager.getFont("Segoe UI", 10, SWT.BOLD));
		   ultime.setForeground(SWTResourceManager.getColor(255, 0, 0));
		   ultime.setBackground(SWTResourceManager.getColor(51, 204, 255));
		   ultime.setBounds(741, 279, 183, 40);
		   ultime.setVisible(false);
		   ultime.setItems(noms);

		   		
			
		   final Button JePenseSavoir = new Button(shell, SWT.NONE);
		   JePenseSavoir.setFont(SWTResourceManager.getFont("Times New Roman", 14, SWT.BOLD | SWT.ITALIC));
			JePenseSavoir.setBounds(716, 257, 230, 64);
			JePenseSavoir.setText("Je pense savoir qui c'est !");
			
		
			
			
			///////////////////////////////////////////////////////
			///////////////////////////////////////////////////////
			/////LABELS des noms des personnages.
			org.eclipse.swt.widgets.Label p0 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);// ligne 1
			p0.setBounds(450, 518, 80, 15);
			p0.setText(noms[0]);		
			org.eclipse.swt.widgets.Label p1 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p1.setBounds(589, 518, 80, 15);
			p1.setText(noms[1]);		
			org.eclipse.swt.widgets.Label p2 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p2.setBounds(724, 518, 80, 15);
			p2.setText(noms[2]);		
			org.eclipse.swt.widgets.Label p3 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p3.setBounds(866, 518, 80, 15);
			p3.setText(noms[3]);
			org.eclipse.swt.widgets.Label p4 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p4.setBounds(1016, 518, 80, 15);
			p4.setText(noms[4]);
			org.eclipse.swt.widgets.Label p5 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE); 
			p5.setBounds(1153, 518, 80, 15);
			p5.setText(noms[5]);
			org.eclipse.swt.widgets.Label p6 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);//ligne 2
			p6.setBounds(453, 656, 80, 15);
			p6.setText(noms[6]);
			org.eclipse.swt.widgets.Label p7 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p7.setBounds(587, 656, 80, 15);
			p7.setText(noms[7]);
			org.eclipse.swt.widgets.Label p8 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p8.setBounds(723, 656, 80, 15);
			p8.setText(noms[8]);
			org.eclipse.swt.widgets.Label p9 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p9.setBounds(864, 656, 80, 15);
			p9.setText(noms[9]);
			org.eclipse.swt.widgets.Label p10 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p10.setBounds(1013, 656, 80, 15);
			p10.setText(noms[10]);
			org.eclipse.swt.widgets.Label p11 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p11.setBounds(1153, 656, 80, 15);
			p11.setText(noms[11]);
			org.eclipse.swt.widgets.Label p12 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);//ligne 3
			p12.setBounds(453, 786, 80, 15);
			p12.setText(noms[12]);
			org.eclipse.swt.widgets.Label p13 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p13.setBounds(587, 786, 80, 15);
			p13.setText(noms[13]);
			org.eclipse.swt.widgets.Label p14 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p14.setBounds(723, 786, 80, 15);
			p14.setText(noms[14]);
			org.eclipse.swt.widgets.Label p15 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p15.setBounds(864, 786, 80, 15);
			p15.setText(noms[15]);
			org.eclipse.swt.widgets.Label p16 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p16.setBounds(1013, 786, 80, 15);
			p16.setText(noms[16]);
			org.eclipse.swt.widgets.Label p17 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p17.setBounds(1153, 786, 80, 15);
			p17.setText(noms[17]);
			org.eclipse.swt.widgets.Label p18 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);//ligne 4
			p18.setBounds(453, 934, 80, 15);
			p18.setText(noms[18]);
			org.eclipse.swt.widgets.Label p19 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p19.setBounds(587, 934, 80, 15);
			p19.setText(noms[19]);
			org.eclipse.swt.widgets.Label p20 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p20.setBounds(723, 934, 80, 15);
			p20.setText(noms[20]);
			org.eclipse.swt.widgets.Label p21 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p21.setBounds(865, 934, 80, 15);
			p21.setText(noms[21]);
			org.eclipse.swt.widgets.Label p22 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p22.setBounds(1015, 934, 80, 15);
			p22.setText(noms[22]);
			org.eclipse.swt.widgets.Label p23 = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			p23.setBounds(1153, 934, 80, 15);
			p23.setText(noms[23]);
						
		
			//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
			//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
			//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
			
			
		
			org.eclipse.swt.widgets.Label EstIl = new org.eclipse.swt.widgets.Label(shell, SWT.NONE);
			//Label "est il" devant la question
			EstIl.setFont(SWTResourceManager.getFont("Times New Roman CYR", 33, SWT.BOLD | SWT.ITALIC));
			EstIl.setBounds(447, 200, 300, 100);
			EstIl.setText("Questions :");
			
			final Label victoire = new Label(shell, SWT.NONE); //label affichant la  victoire
			victoire.setForeground(SWTResourceManager.getColor(255, 0, 0));
			victoire.setFont(SWTResourceManager.getFont("Rockwell Extra Bold", 27, SWT.BOLD));
			victoire.setBounds(778, 341, 408, 56);
			victoire.setText("");


			Label titre = new Label(shell, SWT.NONE); //le titre
			titre.setBackground(SWTResourceManager.getColor(102, 51, 255));
			titre.setFont(SWTResourceManager.getFont("Times New Roman", 52, SWT.BOLD));
			titre.setForeground(SWTResourceManager.getColor(255, 0, 0));
			titre.setBounds(622, 20, 350, 129);
			titre.setText("Qui est ce ?");
			
			///////////////////////////////////////////////////////////////////////////////////////////////////
			/////////////////////////                                 /////////////////////////////////////////
			/////////////////////////  PARTIE DYNAMIQUE DU PROGRAMME  /////////////////////////////////////////
			/////////////////////////                                 /////////////////////////////////////////
			///////////////////////////////////////////////////////////////////////////////////////////////////
			
			
			/////////////////////////////// CANVAS des PERSONNAGES ///////////////////////////////////////////
			
			
			
			final Canvas canvas1 = new Canvas(shell, SWT.NONE);
			canvas1.setBackground(SWTResourceManager.getColor(255, 255, 0));	
			canvas1.setBounds(447, 427, 86, 85);
			final org.eclipse.swt.graphics.Color c1=canvas1.getBackground();
			canvas1.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas1,1,c1,victoire,noms,choix);	// fait (canvas, position dans affichage[],label victoire,
															// tableau noms[],entier choix)
				}
			});	
			
			final Canvas canvas2 = new Canvas(shell, SWT.NONE);
			canvas2.setBackground(SWTResourceManager.getColor(139, 69, 19));
			canvas2.setBounds(580, 427, 86, 85);
			final org.eclipse.swt.graphics.Color c2=canvas2.getBackground();
			canvas2.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas2,2,c2,victoire,noms,choix);
				}
			});
			
		
			
			final Canvas canvas3 = new Canvas(shell, SWT.NONE);
			canvas3.setBounds(716, 427, 86, 85);
			canvas3.setBackground(SWTResourceManager.getColor(233, 150, 122));
			final org.eclipse.swt.graphics.Color c3=canvas3.getBackground();
			canvas3.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas3,3,c3,victoire,noms,choix);
				}
			});
			
			
			final Canvas canvas4 = new Canvas(shell, SWT.NONE);
			canvas4.setBackground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
			canvas4.setBounds(858, 427, 86, 85);
			final org.eclipse.swt.graphics.Color c4=canvas4.getBackground();
			canvas4.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas4,4,c4,victoire,noms,choix);
				}
			});
			
			final Canvas canvas5 = new Canvas(shell, SWT.NONE);
			canvas5.setBackground(SWTResourceManager.getColor(SWT.COLOR_RED));
			final org.eclipse.swt.graphics.Color c5=canvas5.getBackground();
			canvas5.setBounds(1007, 427, 86, 85);
			canvas5.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas5,5,c5,victoire,noms,choix);
				}
			});
			
			final Canvas canvas6 = new Canvas(shell, SWT.NONE);
			canvas6.setBackground(SWTResourceManager.getColor(SWT.COLOR_YELLOW));
			final org.eclipse.swt.graphics.Color c6=canvas6.getBackground();
			canvas6.setBounds(1146, 427, 86, 85);
			canvas6.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas6,6,c6,victoire,noms,choix);
				}
			});
			
			final Canvas canvas7 = new Canvas(shell, SWT.NONE);
			canvas7.setBackground(SWTResourceManager.getColor(153, 204, 102));
			final org.eclipse.swt.graphics.Color c7=canvas7.getBackground();
			canvas7.setBounds(447, 559, 86, 87);
			canvas7.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas7,7,c7,victoire,noms,choix);
				}
			});
			
			final Canvas canvas8 = new Canvas(shell, SWT.NONE);
			canvas8.setBackground(SWTResourceManager.getColor(204, 204, 0));
			final org.eclipse.swt.graphics.Color c8=canvas8.getBackground();
			canvas8.setBounds(581, 559, 85, 87);
			canvas8.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas8,8,c8,victoire,noms,choix);
				}
			});
			
			final 	Canvas canvas9 = new Canvas(shell, SWT.NONE);
			canvas9.setBackground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
			final org.eclipse.swt.graphics.Color c9=canvas9.getBackground();
			canvas9.setBounds(716, 559, 86, 87);
			canvas9.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas9,9,c9,victoire,noms,choix);
				}
			});
			
			final Canvas canvas10 = new Canvas(shell, SWT.NONE);
			canvas10.setBackground(SWTResourceManager.getColor(SWT.COLOR_YELLOW));
			final org.eclipse.swt.graphics.Color c10=canvas10.getBackground();
			canvas10.setBounds(858, 559, 86, 87);
			canvas10.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas10,10,c10,victoire,noms,choix);
				}
			});
			
			final 	Canvas canvas11 = new Canvas(shell, SWT.NONE);
			canvas11.setBackground(SWTResourceManager.getColor(SWT.COLOR_GRAY));
			final org.eclipse.swt.graphics.Color c11=canvas11.getBackground();
			canvas11.setBounds(1007, 559, 86, 87);
			canvas11.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas11,11,c11,victoire,noms,choix);
				}
			});
			
			final 	Canvas canvas12 = new Canvas(shell, SWT.NONE);
			canvas12.setBackground(SWTResourceManager.getColor(SWT.COLOR_RED));
			final org.eclipse.swt.graphics.Color c12=canvas12.getBackground();
			canvas12.setBounds(1146, 559, 86, 87);
			canvas12.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas12,12,c12,victoire,noms,choix);
				}
			});
			
			final 	Canvas canvas13 = new Canvas(shell, SWT.NONE);
			canvas13.setBackground(SWTResourceManager.getColor(SWT.COLOR_GRAY));
			final org.eclipse.swt.graphics.Color c13=canvas13.getBackground();
			canvas13.setBounds(447, 695, 86, 85);
			canvas13.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas13,13,c13,victoire,noms,choix);
				}
			});
			
			final 	Canvas canvas14 = new Canvas(shell, SWT.NONE);
			canvas14.setBackground(SWTResourceManager.getColor(SWT.COLOR_RED));
			final org.eclipse.swt.graphics.Color c14=canvas14.getBackground();
			canvas14.setBounds(580, 695, 86, 85);
			canvas14.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas14,14,c14,victoire,noms,choix);
				}
			});
			
			final Canvas canvas15 = new Canvas(shell, SWT.NONE);
			canvas15.setBackground(SWTResourceManager.getColor(SWT.COLOR_RED));
			final org.eclipse.swt.graphics.Color c15=canvas15.getBackground();
			canvas15.setBounds(716, 696, 86, 85);
			canvas15.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas15,15,c15,victoire,noms,choix);
				}
			});
			
			final Canvas canvas16 = new Canvas(shell, SWT.NONE);
			canvas16.setBackground(SWTResourceManager.getColor(SWT.COLOR_YELLOW));
			final org.eclipse.swt.graphics.Color c16=canvas16.getBackground();
			canvas16.setBounds(858, 695, 86, 85);
			canvas16.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas16,16,c16,victoire,noms,choix);
				}
			});
			
			final Canvas canvas17 = new Canvas(shell, SWT.NONE);
			canvas17.setBackground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
			final org.eclipse.swt.graphics.Color c17=canvas17.getBackground();
			canvas17.setBounds(1007, 695, 86, 85);
			canvas17.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas17,17,c17,victoire,noms,choix);
				}
			});
			
			final Canvas canvas18 = new Canvas(shell, SWT.NONE);
			canvas18.setBackground(SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN));
			final org.eclipse.swt.graphics.Color c18=canvas18.getBackground();
			canvas18.setBounds(1146, 695, 86, 85);
			canvas18.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas18,18,c18,victoire,noms,choix);
				}
			});
			
			final Canvas canvas19 = new Canvas(shell, SWT.NONE);
			canvas19.setBackground(SWTResourceManager.getColor(0, 102, 255));
			final org.eclipse.swt.graphics.Color c19=canvas19.getBackground();
			canvas19.setBounds(447, 838, 86, 85);
			canvas19.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas19,19,c19,victoire,noms,choix);
				}
			});
			
			final 	Canvas canvas20 = new Canvas(shell, SWT.NONE);
			canvas20.setBackground(SWTResourceManager.getColor(255, 51, 51));
			final org.eclipse.swt.graphics.Color c20=canvas20.getBackground();
			canvas20.setBounds(580, 838, 86, 85);
			canvas20.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas20,20,c20,victoire,noms,choix);
				}
			});
			
			final Canvas canvas21 = new Canvas(shell, SWT.NONE);
			canvas21.setBackground(SWTResourceManager.getColor(255, 0, 0));
			final org.eclipse.swt.graphics.Color c21=canvas21.getBackground();
			canvas21.setBounds(716, 838, 86, 85);
			canvas21.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas21,21,c21,victoire,noms,choix);
				}
			});
			
			final Canvas canvas22 = new Canvas(shell, SWT.NONE);
			canvas22.setBackground(SWTResourceManager.getColor(51, 51, 255));
			final org.eclipse.swt.graphics.Color c22=canvas22.getBackground();
			canvas22.setBounds(858, 838, 86, 87);
			canvas22.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas22,22,c22,victoire,noms,choix);
				}
			});
			
			final Canvas canvas23 = new Canvas(shell, SWT.NONE);
			canvas23.setBackground(SWTResourceManager.getColor(102, 0, 255));
			final org.eclipse.swt.graphics.Color c23=canvas23.getBackground();
			canvas23.setBounds(1007, 838, 86, 87);
			canvas23.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas23,23,c23,victoire,noms,choix);
				}
			});
			
			final Canvas canvas24 = new Canvas(shell, SWT.NONE);
			canvas24.setBackground(SWTResourceManager.getColor(0, 51, 255));
			final org.eclipse.swt.graphics.Color c24=canvas24.getBackground();
			canvas24.setBounds(1146, 838, 86, 87);
			canvas24.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					fait(canvas24,24,c24,victoire,noms,choix);
				}
			});
			
			///////////////////////////////////////////// FIN DES CANVAS /////////////////////////////////::
			///////////////////////////////////////////////////////////////////////////////////////////////
			
			 question.addListener(SWT.Selection, new Listener()
			    {
			        @Override
			        public void handleEvent(Event arg0)
			        {		          
			          int indice=question.getSelectionIndex(); //on récupère l'indice de la question séléctionnée
			          if (caract[choix][indice]){
			        	  victoire.setText("Oui !");
			          }
			          else{
			        	  victoire.setText("Eh non !");
			          }
			         
			        }
			    });
			
			//////////////////////
			//////////////////// Dans le cas où le joueur veut "tenter" de deviner.			
			final boolean[] combo={false,true};//tableau pour alterner la visibilité du bouton et du menu déroulant
				 
			ultime.addListener(SWT.Selection, new Listener() //pour le bouton et le menu déroulant (combo)
		    {
		        @Override
		        public void handleEvent(Event arg0)
		        {
		        	if (ultime.getText().equals(noms[choix])){
		        		victoire.setText("Bravo !");
		        	}
		        	else{
		        		victoire.setText("Non !");
		        	}        	
		        	combo[0]=!combo[0];
		        	combo[1]=!combo[1];

		        	ultime.setVisible(combo[0]);
		        	JePenseSavoir.setVisible(combo[1]);		
		        }
		    });
			
			JePenseSavoir.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent e) {
					combo[0]=!combo[0];
		        	combo[1]=!combo[1];
					JePenseSavoir.setVisible(combo[1]);
					ultime.setVisible(combo[0]);
				}
			});
			 //////////////////
			
			//bouton pour quitter tout simplement
			Button quitter = new Button(shell, SWT.NONE);
			quitter.setFont(SWTResourceManager.getFont("Segoe UI", 13, SWT.BOLD));
			quitter.addSelectionListener(new SelectionAdapter() {
				@Override
				public void widgetSelected(SelectionEvent e) {
					System.exit(1);
				
				}
			});
			quitter.setForeground(SWTResourceManager.getColor(SWT.COLOR_YELLOW));
			quitter.setBounds(1505, 911, 145, 56);
			quitter.setText("Quitter");
			
			Label label = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
			label.setBounds(450, 403, 783, 2);
			
			Label label_1 = new Label(shell, SWT.SEPARATOR | SWT.VERTICAL);
			label_1.setBounds(443, 333, 10, 64);
			
			Label label_2 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
			label_2.setBounds(450, 327, 783, 2);
			
			Label label_3 = new Label(shell, SWT.SEPARATOR);
			label_3.setBounds(1234, 333, 2, 64);
			
			Label label_4 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
			label_4.setBounds(447, 539, 783, 2);
			
			Label label_5 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
			label_5.setBounds(450, 677, 783, 2);
			
			Label label_6 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
			label_6.setBounds(450, 814, 783, 2);
			
			Label label_7 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
			label_7.setBounds(450, 959, 783, 2);
			
			Label label_8 = new Label(shell, SWT.SEPARATOR);
			label_8.setBounds(564, 440, 10, 64);
			
			Label label_9 = new Label(shell, SWT.SEPARATOR);
			label_9.setBounds(539, 440, 10, 64);
			
			Label label_10 = new Label(shell, SWT.SEPARATOR);
			label_10.setBounds(671, 440, 10, 64);
			
			Label label_11 = new Label(shell, SWT.SEPARATOR);
			label_11.setBounds(700, 440, 10, 64);
			
			Label label_12 = new Label(shell, SWT.SEPARATOR);
			label_12.setBounds(837, 440, 10, 64);
			
			Label label_13 = new Label(shell, SWT.SEPARATOR);
			label_13.setBounds(808, 440, 10, 64);
			
			Label label_14 = new Label(shell, SWT.SEPARATOR);
			label_14.setBounds(991, 440, 10, 64);
			
			Label label_15 = new Label(shell, SWT.SEPARATOR);
			label_15.setBounds(950, 440, 10, 64);
			
			Label label_16 = new Label(shell, SWT.SEPARATOR);
			label_16.setBounds(1130, 440, 10, 64);
			
			Label label_17 = new Label(shell, SWT.SEPARATOR);
			label_17.setBounds(1101, 440, 10, 64);
			
			Label label_18 = new Label(shell, SWT.SEPARATOR);
			label_18.setBounds(568, 570, 10, 64);
			
			Label label_19 = new Label(shell, SWT.SEPARATOR);
			label_19.setBounds(539, 570, 10, 64);
			
			Label label_20 = new Label(shell, SWT.SEPARATOR);
			label_20.setBounds(568, 705, 10, 64);
			
			Label label_21 = new Label(shell, SWT.SEPARATOR);
			label_21.setBounds(539, 705, 10, 64);
			
			Label label_22 = new Label(shell, SWT.SEPARATOR);
			label_22.setBounds(568, 850, 10, 64);
			
			Label label_23 = new Label(shell, SWT.SEPARATOR);
			label_23.setBounds(539, 850, 10, 64);
			
			Label label_24 = new Label(shell, SWT.SEPARATOR);
			label_24.setBounds(701, 850, 10, 64);
			
			Label label_25 = new Label(shell, SWT.SEPARATOR);
			label_25.setBounds(672, 850, 10, 64);
			
			Label label_26 = new Label(shell, SWT.SEPARATOR);
			label_26.setBounds(701, 705, 10, 64);
			
			Label label_27 = new Label(shell, SWT.SEPARATOR);
			label_27.setBounds(672, 705, 10, 64);
			
			Label label_28 = new Label(shell, SWT.SEPARATOR);
			label_28.setBounds(701, 570, 10, 64);
			
			Label label_29 = new Label(shell, SWT.SEPARATOR);
			label_29.setBounds(672, 570, 10, 64);
			
			Label label_30 = new Label(shell, SWT.SEPARATOR);
			label_30.setBounds(837, 570, 10, 64);
			
			Label label_31 = new Label(shell, SWT.SEPARATOR);
			label_31.setBounds(808, 570, 10, 64);
			
			Label label_32 = new Label(shell, SWT.SEPARATOR);
			label_32.setBounds(837, 705, 10, 64);
			
			Label label_33 = new Label(shell, SWT.SEPARATOR);
			label_33.setBounds(808, 705, 10, 64);
			
			Label label_34 = new Label(shell, SWT.SEPARATOR);
			label_34.setBounds(837, 850, 10, 64);
			
			Label label_35 = new Label(shell, SWT.SEPARATOR);
			label_35.setBounds(808, 850, 10, 64);
			
			Label label_36 = new Label(shell, SWT.SEPARATOR);
			label_36.setBounds(1128, 850, 10, 64);
			
			Label label_37 = new Label(shell, SWT.SEPARATOR);
			label_37.setBounds(1099, 850, 10, 64);
			
			Label label_38 = new Label(shell, SWT.SEPARATOR);
			label_38.setBounds(1128, 705, 10, 64);
			
			Label label_39 = new Label(shell, SWT.SEPARATOR);
			label_39.setBounds(1099, 705, 10, 64);
			
			Label label_40 = new Label(shell, SWT.SEPARATOR);
			label_40.setBounds(1130, 570, 10, 64);
			
			Label label_41 = new Label(shell, SWT.SEPARATOR);
			label_41.setBounds(1101, 570, 10, 64);
			
			Label label_42 = new Label(shell, SWT.SEPARATOR);
			label_42.setBounds(991, 570, 10, 64);
			
			Label label_43 = new Label(shell, SWT.SEPARATOR);
			label_43.setBounds(950, 570, 10, 64);
			
			Label label_44 = new Label(shell, SWT.SEPARATOR);
			label_44.setBounds(950, 705, 10, 64);
			
			Label label_45 = new Label(shell, SWT.SEPARATOR);
			label_45.setBounds(991, 705, 10, 64);
			
			Label label_46 = new Label(shell, SWT.SEPARATOR);
			label_46.setBounds(950, 850, 10, 64);
			
			Label label_47 = new Label(shell, SWT.SEPARATOR);
			label_47.setBounds(991, 850, 10, 64);
		
			ImageIcon image = new ImageIcon("48.jpg");
			JLabel label50 = new JLabel("", image, JLabel.CENTER);
			JPanel panel50 = new JPanel(new BorderLayout());
			panel50.add( label50, BorderLayout.CENTER );

			
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}
}




A voir également:

2 réponses

BloodShinX Messages postés 507 Date d'inscription lundi 5 janvier 2009 Statut Membre Dernière intervention 31 juillet 2016 89
12 mai 2013 à 15:06
Je sais que c'est très mal conçu mais ce n'est pas grave ! j'aurais pu utilisé des listes d'objets mais je ne sais pas faire. Juste aidez moi pour les images dans les canvas merci beaucoup
0
BloodShinX Messages postés 507 Date d'inscription lundi 5 janvier 2009 Statut Membre Dernière intervention 31 juillet 2016 89
12 mai 2013 à 16:13
Bon ba j'ai changé, j'ai pris des button.
0