IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 Java Discussion :

Renvoyer un JLabel dans une JFrame


Sujet :

Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    Homme Profil pro
    Inscrit en
    Novembre 2012
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Albanie

    Informations forums :
    Inscription : Novembre 2012
    Messages : 11
    Par défaut Renvoyer un JLabel dans une JFrame
    Bonjour à toutes et à tous,
    Je me retourne vers vous après une réponse claire de l'un des participant, parce que un autre problème se présente à moi, je n'arrive pas à renvoyé un JLabel dans une JFrame préalablement construite.
    Malgré plusieurs méthodes utilisées, une d'entre elle m'a été conseillée parmi les plusieurs testées.
    Pourtant je n'arrive pas à renvoyer l'image, malgré toutes absence d'erreur.
    Je ne suis que débutant et je ne vois pas pourquoi elle ne marche pas est ce que quelqu’un peut m'éclairer ?
    Merci d'avance !

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
     
    public class Frame extends JFrame {
     
    	private static final long    serialVersionUID    = 4983727800375272097L;
    	public static JLabel label;
    	public static JFrame frame;
     
    	public Frame() {
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    		setSize(1367, 703);
    		setLocationRelativeTo(null);
    		BufferedImage img = null;
    		try {
    			img = ImageIO.read(new File("Background0.jpg"));
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		setContentPane(new MyCanvas(img));
    	}
     
     
     
    	public static void main(String[] args) {
    		new Frame().setVisible(true);
    	}
     
    	private static class MyCanvas extends JComponent implements MouseListener {
    		//ici on défini toutes les zones clicables de l'écran 1
     
    		private static final long    serialVersionUID    = 1L;
    		// position de la première zone de limage que l'on veut (ici elle se trouve au pixel x=0, y=0 et s'étend sur width=10 et height=10)
    		private static final Rectangle    ZONE_IMAGE_1 = new Rectangle(21, 10, 281, 50);
    		// position de la première zone de limage que l'on veut (ici elle se trouve au pixel x=100, y=100 et s'étend sur width=30 et height=20)
    		private static final Rectangle    ZONE_IMAGE_2 = new Rectangle(320, 10, 265, 50);
     
    		private static final Rectangle    ZONE_IMAGE_3 = new Rectangle(602, 10, 290, 50);
    		// position de la première zone de limage que l'on veut (ici elle se trouve au pixel x=100, y=100 et s'étend sur width=30 et height=20)
    		private static final Rectangle    ZONE_IMAGE_4 = new Rectangle(135, 200, 170, 140);
    		private static final Rectangle    ZONE_IMAGE_5 = new Rectangle(135, 352, 170, 140);
    		private static final Rectangle    ZONE_IMAGE_6 = new Rectangle(135, 506, 170, 140);
     
     
    		private static final Rectangle    ZONE_IMAGE_10 = new Rectangle(368, 200, 61, 45);
    		private static final Rectangle    ZONE_IMAGE_11 = new Rectangle(368, 247, 61, 45);
    		private static final Rectangle    ZONE_IMAGE_12 = new Rectangle(368, 294, 61, 44);
    		private static final Rectangle    ZONE_IMAGE_13 = new Rectangle(368, 340, 60, 44);
    		private static final Rectangle    ZONE_IMAGE_14 = new Rectangle(368, 386, 60, 44);
    		private static final Rectangle    ZONE_IMAGE_15 = new Rectangle(368, 432, 60, 44);
    		private static final Rectangle    ZONE_IMAGE_16 = new Rectangle(368, 478, 60, 46);
    		private static final Rectangle    ZONE_IMAGE_17 = new Rectangle(368, 526, 60, 45);
    		private static final Rectangle    ZONE_IMAGE_18 = new Rectangle(368, 573, 60, 54);
     
    		private BufferedImage buff= null;
     
     
     
    		public MyCanvas(BufferedImage img) {
    			this.addMouseListener(this);
    			this.buff = img;
    		}
     
    		public void paintComponent(Graphics g) {//zone images
    			// dessine l'image
    			g.drawImage(buff, 0, 0, buff.getWidth(), buff.getHeight(), this);
    			// juste histoire de voir ou se trouvent les zones clicables 
    			g.setColor(Color.GREEN);
    			g.drawRect(ZONE_IMAGE_1.x, ZONE_IMAGE_1.y, ZONE_IMAGE_1.width, ZONE_IMAGE_1.height);
    			g.drawRect(ZONE_IMAGE_2.x, ZONE_IMAGE_2.y, ZONE_IMAGE_2.width, ZONE_IMAGE_2.height);
    			g.drawRect(ZONE_IMAGE_3.x, ZONE_IMAGE_3.y, ZONE_IMAGE_3.width, ZONE_IMAGE_3.height);
    			g.drawRect(ZONE_IMAGE_4.x, ZONE_IMAGE_4.y, ZONE_IMAGE_4.width, ZONE_IMAGE_4.height);
    			g.drawRect(ZONE_IMAGE_5.x, ZONE_IMAGE_5.y, ZONE_IMAGE_5.width, ZONE_IMAGE_5.height);
    			g.drawRect(ZONE_IMAGE_6.x, ZONE_IMAGE_6.y, ZONE_IMAGE_6.width, ZONE_IMAGE_6.height);
    			g.drawRect(ZONE_IMAGE_10.x, ZONE_IMAGE_10.y, ZONE_IMAGE_10.width, ZONE_IMAGE_10.height);
    			g.drawRect(ZONE_IMAGE_11.x, ZONE_IMAGE_11.y, ZONE_IMAGE_11.width, ZONE_IMAGE_11.height);
    			g.drawRect(ZONE_IMAGE_12.x, ZONE_IMAGE_12.y, ZONE_IMAGE_12.width, ZONE_IMAGE_12.height);
    			g.drawRect(ZONE_IMAGE_13.x, ZONE_IMAGE_13.y, ZONE_IMAGE_13.width, ZONE_IMAGE_13.height);
    			g.drawRect(ZONE_IMAGE_14.x, ZONE_IMAGE_14.y, ZONE_IMAGE_14.width, ZONE_IMAGE_14.height);
    			g.drawRect(ZONE_IMAGE_15.x, ZONE_IMAGE_15.y, ZONE_IMAGE_15.width, ZONE_IMAGE_15.height);
    			g.drawRect(ZONE_IMAGE_16.x, ZONE_IMAGE_16.y, ZONE_IMAGE_16.width, ZONE_IMAGE_16.height);
    			g.drawRect(ZONE_IMAGE_17.x, ZONE_IMAGE_17.y, ZONE_IMAGE_17.width, ZONE_IMAGE_17.height);
    			g.drawRect(ZONE_IMAGE_18.x, ZONE_IMAGE_18.y, ZONE_IMAGE_18.width, ZONE_IMAGE_18.height);
     
     
    		}
     
    		private Boolean testLocation(Point mouse, Rectangle area, String text) {//ici on a juste le test pour savoir si les zones de clics répondes 
    			// test si la souris est dans les data de l'image
    			if(area.contains(mouse)) {
    				System.out.println(text + " - image");
    				return true;
    			}
    			else {
    				System.out.println(text + " - !image");
    				return false;
    			}
    		}
     
    		public void mouseClicked(MouseEvent e) {
    		}
     
     
    		public void mousePressed(MouseEvent e) 
    		{            //récupération de la position de la souris
    			Point p = e.getPoint();
    			if (testLocation(p, ZONE_IMAGE_1, "mouseClicked - data 1"))
    			{new Frame2().setVisible(true);// j'appelle ma nouvelle fenêtre 
    			}
    			testLocation(p, ZONE_IMAGE_2, "mouseClicked - data 2");
    			if (testLocation( p, ZONE_IMAGE_2, "mouseClicked - data 2")){
    				new Frame3().setVisible(true);// j'appelle ma nouvelle fenêtre 
    			}
    			testLocation(p, ZONE_IMAGE_3, "mouseClicked - data 3");
    			if(testLocation(p, ZONE_IMAGE_3, "mouseClicked - data 3")){
    				new Frame4().setVisible(true);// j'appelle ma nouvelle fenêtre 
    			}
     
     
    			testLocation(p, ZONE_IMAGE_4, "mouseClicked - data 4");//clapier1
    			testLocation(p, ZONE_IMAGE_5, "mouseClicked - data 5");//clapier2
    			testLocation(p, ZONE_IMAGE_6, "mouseClicked - data 6");//clapier3
     
     
    			testLocation(p, ZONE_IMAGE_10, "mouseClicked - data 10");//case 1
    			if (testLocation( p, ZONE_IMAGE_10, "mouseClicked - data 10")){
    				try {																				
    					///////////////////////////////
    					///////////////////////////////////////
    					JLabel imageLabel = new JLabel();
    					ImageIcon ii = new ImageIcon(this.getClass().getResource("Essaye-lapin2.gif"));
    					imageLabel.setIcon(ii);
    					imageLabel.setBounds(0,0,ii.getIconWidth(),ii.getIconHeight());
    					frame.getContentPane().add(imageLabel, BorderLayout.CENTER); 
    					label.repaint(); 
    					frame.repaint();
    					frame.getContentPane().repaint();
    					////////// c'est ici !//////////////////
    					///////////////////////////////////////
    					///"tudieu fichtre bigre ça ne marche pas !"
    				} 
    				catch (Exception exception) {
    					exception.printStackTrace();
    				}
     
    			}
    			testLocation(p, ZONE_IMAGE_11, "mouseClicked - data 11");//case 2
    			testLocation(p, ZONE_IMAGE_12, "mouseClicked - data 12");//case 3
    			testLocation(p, ZONE_IMAGE_13, "mouseClicked - data 13");//case 4
    			testLocation(p, ZONE_IMAGE_14, "mouseClicked - data 14");//case 5
    			testLocation(p, ZONE_IMAGE_15, "mouseClicked - data 15");//case 6
    			testLocation(p, ZONE_IMAGE_16, "mouseClicked - data 16");//case 7
    			testLocation(p, ZONE_IMAGE_17, "mouseClicked - data 17");//case 8
    			testLocation(p, ZONE_IMAGE_18, "mouseClicked - data 18");//case 9
     
     
     
    		}
    		public void mouseReleased(MouseEvent e) {}//peut servir pour plus tard 
    		public void mouseEntered(MouseEvent e) { }//peut servir pour plus tard 
    		public void mouseExited(MouseEvent e) { }//peut servir pour plus tard 
     
    	}
     
     
    }

  2. #2
    Membre chevronné
    Homme Profil pro
    Inscrit en
    Janvier 2010
    Messages
    312
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2010
    Messages : 312
    Par défaut
    ta variable frame est declarée au debut mais elle n'est jamais initialisée???

  3. #3
    Membre chevronné
    Avatar de Laine
    Femme Profil pro
    Doctorat informatique
    Inscrit en
    Mars 2013
    Messages
    238
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 36
    Localisation : Algérie

    Informations professionnelles :
    Activité : Doctorat informatique

    Informations forums :
    Inscription : Mars 2013
    Messages : 238
    Par défaut
    Bonjour
    Je ne comprends pas, renvoyer quel label dans quel frame ?

  4. #4
    Membre habitué
    Homme Profil pro
    Inscrit en
    Novembre 2012
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Albanie

    Informations forums :
    Inscription : Novembre 2012
    Messages : 11
    Par défaut
    Citation Envoyé par Laine Voir le message
    Bonjour
    Je ne comprends pas, renvoyer quel label dans quel frame ?
    Bonjour,
    à la ligne 40, j'exécute ma fonction Frame qui ouvre une nouvelle frame justement, mais après ? je sais vraiment pas comment faire pour y rajouter un Jlabel.

  5. #5
    Membre habitué
    Homme Profil pro
    Inscrit en
    Novembre 2012
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Albanie

    Informations forums :
    Inscription : Novembre 2012
    Messages : 11
    Par défaut
    Citation Envoyé par ludomacho Voir le message
    ta variable frame est declarée au debut mais elle n'est jamais initialisée???
    Bah j'aimerais bien qu'elle corresponde à celle appelée en ligne 40 mais ça je vois pas comment faire.
    le but étant que les deux soit les mêmes si je comprends bien ce que tu me demande ?

  6. #6
    Membre chevronné
    Avatar de Laine
    Femme Profil pro
    Doctorat informatique
    Inscrit en
    Mars 2013
    Messages
    238
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 36
    Localisation : Algérie

    Informations professionnelles :
    Activité : Doctorat informatique

    Informations forums :
    Inscription : Mars 2013
    Messages : 238
    Par défaut
    Bonjour
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
     
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
     
    public class Frame extends JFrame {
     
    	private static final long    serialVersionUID    = 4983727800375272097L;
    	public static JLabel label= new JLabel("Je suis là");
    	public static JFrame frame;
     
    	public Frame() {
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    		setSize(1367, 703);
    		setLocationRelativeTo(null);
     
    		BufferedImage img = null;
    		try {
    			img = ImageIO.read(new File("sablier.png"));
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		this.getContentPane().add(new MyCanvas(img));
    	}
     
     
     
    	public static void main(String[] args) {
    		frame= new Frame();
    		frame.setVisible(true);
    	}
     
    	private static class MyCanvas extends JComponent implements MouseListener {
    		//ici on défini toutes les zones clicables de l'écran 1
     
    		private static final long    serialVersionUID    = 1L;
    		// position de la première zone de limage que l'on veut (ici elle se trouve au pixel x=0, y=0 et s'étend sur width=10 et height=10)
    		private static final Rectangle    ZONE_IMAGE_1 = new Rectangle(21, 10, 281, 50);
    		// position de la première zone de limage que l'on veut (ici elle se trouve au pixel x=100, y=100 et s'étend sur width=30 et height=20)
    		private static final Rectangle    ZONE_IMAGE_2 = new Rectangle(320, 10, 265, 50);
     
    		private static final Rectangle    ZONE_IMAGE_3 = new Rectangle(602, 10, 290, 50);
    		// position de la première zone de limage que l'on veut (ici elle se trouve au pixel x=100, y=100 et s'étend sur width=30 et height=20)
    		private static final Rectangle    ZONE_IMAGE_4 = new Rectangle(135, 200, 170, 140);
    		private static final Rectangle    ZONE_IMAGE_5 = new Rectangle(135, 352, 170, 140);
    		private static final Rectangle    ZONE_IMAGE_6 = new Rectangle(135, 506, 170, 140);
     
     
    		private static final Rectangle    ZONE_IMAGE_10 = new Rectangle(368, 200, 61, 45);
    		private static final Rectangle    ZONE_IMAGE_11 = new Rectangle(368, 247, 61, 45);
    		private static final Rectangle    ZONE_IMAGE_12 = new Rectangle(368, 294, 61, 44);
    		private static final Rectangle    ZONE_IMAGE_13 = new Rectangle(368, 340, 60, 44);
    		private static final Rectangle    ZONE_IMAGE_14 = new Rectangle(368, 386, 60, 44);
    		private static final Rectangle    ZONE_IMAGE_15 = new Rectangle(368, 432, 60, 44);
    		private static final Rectangle    ZONE_IMAGE_16 = new Rectangle(368, 478, 60, 46);
    		private static final Rectangle    ZONE_IMAGE_17 = new Rectangle(368, 526, 60, 45);
    		private static final Rectangle    ZONE_IMAGE_18 = new Rectangle(368, 573, 60, 54);
     
    		private BufferedImage buff= null;
     
     
     
    		public MyCanvas(BufferedImage img) {
    			this.addMouseListener(this);
    			this.buff = img;
    		}
     
    		public void paintComponent(Graphics g) {//zone images
    			// dessine l'image
    			g.drawImage(buff, 0, 0, buff.getWidth(), buff.getHeight(), this);
    			// juste histoire de voir ou se trouvent les zones clicables 
    			g.setColor(Color.GREEN);
    			g.drawRect(ZONE_IMAGE_1.x, ZONE_IMAGE_1.y, ZONE_IMAGE_1.width, ZONE_IMAGE_1.height);
    			g.drawRect(ZONE_IMAGE_2.x, ZONE_IMAGE_2.y, ZONE_IMAGE_2.width, ZONE_IMAGE_2.height);
    			g.drawRect(ZONE_IMAGE_3.x, ZONE_IMAGE_3.y, ZONE_IMAGE_3.width, ZONE_IMAGE_3.height);
    			g.drawRect(ZONE_IMAGE_4.x, ZONE_IMAGE_4.y, ZONE_IMAGE_4.width, ZONE_IMAGE_4.height);
    			g.drawRect(ZONE_IMAGE_5.x, ZONE_IMAGE_5.y, ZONE_IMAGE_5.width, ZONE_IMAGE_5.height);
    			g.drawRect(ZONE_IMAGE_6.x, ZONE_IMAGE_6.y, ZONE_IMAGE_6.width, ZONE_IMAGE_6.height);
    			g.drawRect(ZONE_IMAGE_10.x, ZONE_IMAGE_10.y, ZONE_IMAGE_10.width, ZONE_IMAGE_10.height);
    			g.drawRect(ZONE_IMAGE_11.x, ZONE_IMAGE_11.y, ZONE_IMAGE_11.width, ZONE_IMAGE_11.height);
    			g.drawRect(ZONE_IMAGE_12.x, ZONE_IMAGE_12.y, ZONE_IMAGE_12.width, ZONE_IMAGE_12.height);
    			g.drawRect(ZONE_IMAGE_13.x, ZONE_IMAGE_13.y, ZONE_IMAGE_13.width, ZONE_IMAGE_13.height);
    			g.drawRect(ZONE_IMAGE_14.x, ZONE_IMAGE_14.y, ZONE_IMAGE_14.width, ZONE_IMAGE_14.height);
    			g.drawRect(ZONE_IMAGE_15.x, ZONE_IMAGE_15.y, ZONE_IMAGE_15.width, ZONE_IMAGE_15.height);
    			g.drawRect(ZONE_IMAGE_16.x, ZONE_IMAGE_16.y, ZONE_IMAGE_16.width, ZONE_IMAGE_16.height);
    			g.drawRect(ZONE_IMAGE_17.x, ZONE_IMAGE_17.y, ZONE_IMAGE_17.width, ZONE_IMAGE_17.height);
    			g.drawRect(ZONE_IMAGE_18.x, ZONE_IMAGE_18.y, ZONE_IMAGE_18.width, ZONE_IMAGE_18.height);
     
     
    		}
     
    		private Boolean testLocation(Point mouse, Rectangle area, String text) {//ici on a juste le test pour savoir si les zones de clics répondes 
    			// test si la souris est dans les data de l'image
    			if(area.contains(mouse)) {
    				//System.out.println(text + " - image");
    				return true;
    			}
    			else {
    				//System.out.println(text + " - !image");
    				return false;
    			}
    		}
     
    		public void mouseClicked(MouseEvent e) {
    		}
     
     
    		public void mousePressed(MouseEvent e) 
    		{            //récupération de la position de la souris
    			Point p = e.getPoint();
    			if (testLocation(p, ZONE_IMAGE_1, "mouseClicked - data 1"))
    			{//new Frame2().setVisible(true);// j'appelle ma nouvelle fenêtre 
    			}
    			testLocation(p, ZONE_IMAGE_2, "mouseClicked - data 2");
    			if (testLocation( p, ZONE_IMAGE_2, "mouseClicked - data 2")){
    				//new Frame3().setVisible(true);// j'appelle ma nouvelle fenêtre 
    			}
    			testLocation(p, ZONE_IMAGE_3, "mouseClicked - data 3");
    			if(testLocation(p, ZONE_IMAGE_3, "mouseClicked - data 3")){
    				//new Frame4().setVisible(true);// j'appelle ma nouvelle fenêtre 
    			}
     
     
    			testLocation(p, ZONE_IMAGE_4, "mouseClicked - data 4");//clapier1
    			testLocation(p, ZONE_IMAGE_5, "mouseClicked - data 5");//clapier2
    			testLocation(p, ZONE_IMAGE_6, "mouseClicked - data 6");//clapier3
     
     
    			testLocation(p, ZONE_IMAGE_10, "mouseClicked - data 10");//case 1
    			if (testLocation( p, ZONE_IMAGE_10, "mouseClicked - data 10")){
    				try {																				
    					///////////////////////////////
    					///////////////////////////////////////
    					JLabel imageLabel = new JLabel(new ImageIcon("sablier.png"));
    					frame.getContentPane().setVisible(false);
    					frame.getContentPane().removeAll();
    					frame.getContentPane().add(imageLabel, BorderLayout.CENTER);
    					frame.getContentPane().repaint();
    					frame.getContentPane().setVisible(true);
    					////////// c'est ici !//////////////////
    					///////////////////////////////////////
    					///"tudieu fichtre bigre ça ne marche pas !"
    				} 
    				catch (Exception exception) {
    					exception.printStackTrace();
    				}
     
    			}
    			testLocation(p, ZONE_IMAGE_11, "mouseClicked - data 11");//case 2
    			testLocation(p, ZONE_IMAGE_12, "mouseClicked - data 12");//case 3
    			testLocation(p, ZONE_IMAGE_13, "mouseClicked - data 13");//case 4
    			testLocation(p, ZONE_IMAGE_14, "mouseClicked - data 14");//case 5
    			testLocation(p, ZONE_IMAGE_15, "mouseClicked - data 15");//case 6
    			testLocation(p, ZONE_IMAGE_16, "mouseClicked - data 16");//case 7
    			testLocation(p, ZONE_IMAGE_17, "mouseClicked - data 17");//case 8
    			testLocation(p, ZONE_IMAGE_18, "mouseClicked - data 18");//case 9
     
     
     
    		}
    		public void mouseReleased(MouseEvent e) {}//peut servir pour plus tard 
    		public void mouseEntered(MouseEvent e) { }//peut servir pour plus tard 
    		public void mouseExited(MouseEvent e) { }//peut servir pour plus tard 
     
    	}
     
     
    }
    Essaye ce code et dis moi
    Désolé j'ai mis des trucs en commentaires, changé le nom de l'image
    et travaillé avec frame car j'avais pas trop compris où tu voulais afficher ton image mais ça marche

  7. #7
    Membre habitué
    Homme Profil pro
    Inscrit en
    Novembre 2012
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Albanie

    Informations forums :
    Inscription : Novembre 2012
    Messages : 11
    Par défaut
    Citation Envoyé par Laine Voir le message
    Bonjour
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
     
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
     
    public class Frame extends JFrame {
     
    	private static final long    serialVersionUID    = 4983727800375272097L;
    	public static JLabel label= new JLabel("Je suis là");
    	public static JFrame frame;
     
    	public Frame() {
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    		setSize(1367, 703);
    		setLocationRelativeTo(null);
     
    		BufferedImage img = null;
    		try {
    			img = ImageIO.read(new File("sablier.png"));
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		this.getContentPane().add(new MyCanvas(img));
    	}
     
     
     
    	public static void main(String[] args) {
    		frame= new Frame();
    		frame.setVisible(true);
    	}
     
    	private static class MyCanvas extends JComponent implements MouseListener {
    		//ici on défini toutes les zones clicables de l'écran 1
     
    		private static final long    serialVersionUID    = 1L;
    		// position de la première zone de limage que l'on veut (ici elle se trouve au pixel x=0, y=0 et s'étend sur width=10 et height=10)
    		private static final Rectangle    ZONE_IMAGE_1 = new Rectangle(21, 10, 281, 50);
    		// position de la première zone de limage que l'on veut (ici elle se trouve au pixel x=100, y=100 et s'étend sur width=30 et height=20)
    		private static final Rectangle    ZONE_IMAGE_2 = new Rectangle(320, 10, 265, 50);
     
    		private static final Rectangle    ZONE_IMAGE_3 = new Rectangle(602, 10, 290, 50);
    		// position de la première zone de limage que l'on veut (ici elle se trouve au pixel x=100, y=100 et s'étend sur width=30 et height=20)
    		private static final Rectangle    ZONE_IMAGE_4 = new Rectangle(135, 200, 170, 140);
    		private static final Rectangle    ZONE_IMAGE_5 = new Rectangle(135, 352, 170, 140);
    		private static final Rectangle    ZONE_IMAGE_6 = new Rectangle(135, 506, 170, 140);
     
     
    		private static final Rectangle    ZONE_IMAGE_10 = new Rectangle(368, 200, 61, 45);
    		private static final Rectangle    ZONE_IMAGE_11 = new Rectangle(368, 247, 61, 45);
    		private static final Rectangle    ZONE_IMAGE_12 = new Rectangle(368, 294, 61, 44);
    		private static final Rectangle    ZONE_IMAGE_13 = new Rectangle(368, 340, 60, 44);
    		private static final Rectangle    ZONE_IMAGE_14 = new Rectangle(368, 386, 60, 44);
    		private static final Rectangle    ZONE_IMAGE_15 = new Rectangle(368, 432, 60, 44);
    		private static final Rectangle    ZONE_IMAGE_16 = new Rectangle(368, 478, 60, 46);
    		private static final Rectangle    ZONE_IMAGE_17 = new Rectangle(368, 526, 60, 45);
    		private static final Rectangle    ZONE_IMAGE_18 = new Rectangle(368, 573, 60, 54);
     
    		private BufferedImage buff= null;
     
     
     
    		public MyCanvas(BufferedImage img) {
    			this.addMouseListener(this);
    			this.buff = img;
    		}
     
    		public void paintComponent(Graphics g) {//zone images
    			// dessine l'image
    			g.drawImage(buff, 0, 0, buff.getWidth(), buff.getHeight(), this);
    			// juste histoire de voir ou se trouvent les zones clicables 
    			g.setColor(Color.GREEN);
    			g.drawRect(ZONE_IMAGE_1.x, ZONE_IMAGE_1.y, ZONE_IMAGE_1.width, ZONE_IMAGE_1.height);
    			g.drawRect(ZONE_IMAGE_2.x, ZONE_IMAGE_2.y, ZONE_IMAGE_2.width, ZONE_IMAGE_2.height);
    			g.drawRect(ZONE_IMAGE_3.x, ZONE_IMAGE_3.y, ZONE_IMAGE_3.width, ZONE_IMAGE_3.height);
    			g.drawRect(ZONE_IMAGE_4.x, ZONE_IMAGE_4.y, ZONE_IMAGE_4.width, ZONE_IMAGE_4.height);
    			g.drawRect(ZONE_IMAGE_5.x, ZONE_IMAGE_5.y, ZONE_IMAGE_5.width, ZONE_IMAGE_5.height);
    			g.drawRect(ZONE_IMAGE_6.x, ZONE_IMAGE_6.y, ZONE_IMAGE_6.width, ZONE_IMAGE_6.height);
    			g.drawRect(ZONE_IMAGE_10.x, ZONE_IMAGE_10.y, ZONE_IMAGE_10.width, ZONE_IMAGE_10.height);
    			g.drawRect(ZONE_IMAGE_11.x, ZONE_IMAGE_11.y, ZONE_IMAGE_11.width, ZONE_IMAGE_11.height);
    			g.drawRect(ZONE_IMAGE_12.x, ZONE_IMAGE_12.y, ZONE_IMAGE_12.width, ZONE_IMAGE_12.height);
    			g.drawRect(ZONE_IMAGE_13.x, ZONE_IMAGE_13.y, ZONE_IMAGE_13.width, ZONE_IMAGE_13.height);
    			g.drawRect(ZONE_IMAGE_14.x, ZONE_IMAGE_14.y, ZONE_IMAGE_14.width, ZONE_IMAGE_14.height);
    			g.drawRect(ZONE_IMAGE_15.x, ZONE_IMAGE_15.y, ZONE_IMAGE_15.width, ZONE_IMAGE_15.height);
    			g.drawRect(ZONE_IMAGE_16.x, ZONE_IMAGE_16.y, ZONE_IMAGE_16.width, ZONE_IMAGE_16.height);
    			g.drawRect(ZONE_IMAGE_17.x, ZONE_IMAGE_17.y, ZONE_IMAGE_17.width, ZONE_IMAGE_17.height);
    			g.drawRect(ZONE_IMAGE_18.x, ZONE_IMAGE_18.y, ZONE_IMAGE_18.width, ZONE_IMAGE_18.height);
     
     
    		}
     
    		private Boolean testLocation(Point mouse, Rectangle area, String text) {//ici on a juste le test pour savoir si les zones de clics répondes 
    			// test si la souris est dans les data de l'image
    			if(area.contains(mouse)) {
    				//System.out.println(text + " - image");
    				return true;
    			}
    			else {
    				//System.out.println(text + " - !image");
    				return false;
    			}
    		}
     
    		public void mouseClicked(MouseEvent e) {
    		}
     
     
    		public void mousePressed(MouseEvent e) 
    		{            //récupération de la position de la souris
    			Point p = e.getPoint();
    			if (testLocation(p, ZONE_IMAGE_1, "mouseClicked - data 1"))
    			{//new Frame2().setVisible(true);// j'appelle ma nouvelle fenêtre 
    			}
    			testLocation(p, ZONE_IMAGE_2, "mouseClicked - data 2");
    			if (testLocation( p, ZONE_IMAGE_2, "mouseClicked - data 2")){
    				//new Frame3().setVisible(true);// j'appelle ma nouvelle fenêtre 
    			}
    			testLocation(p, ZONE_IMAGE_3, "mouseClicked - data 3");
    			if(testLocation(p, ZONE_IMAGE_3, "mouseClicked - data 3")){
    				//new Frame4().setVisible(true);// j'appelle ma nouvelle fenêtre 
    			}
     
     
    			testLocation(p, ZONE_IMAGE_4, "mouseClicked - data 4");//clapier1
    			testLocation(p, ZONE_IMAGE_5, "mouseClicked - data 5");//clapier2
    			testLocation(p, ZONE_IMAGE_6, "mouseClicked - data 6");//clapier3
     
     
    			testLocation(p, ZONE_IMAGE_10, "mouseClicked - data 10");//case 1
    			if (testLocation( p, ZONE_IMAGE_10, "mouseClicked - data 10")){
    				try {																				
    					///////////////////////////////
    					///////////////////////////////////////
    					JLabel imageLabel = new JLabel(new ImageIcon("sablier.png"));
    					frame.getContentPane().setVisible(false);
    					frame.getContentPane().removeAll();
    					frame.getContentPane().add(imageLabel, BorderLayout.CENTER);
    					frame.getContentPane().repaint();
    					frame.getContentPane().setVisible(true);
    					////////// c'est ici !//////////////////
    					///////////////////////////////////////
    					///"tudieu fichtre bigre ça ne marche pas !"
    				} 
    				catch (Exception exception) {
    					exception.printStackTrace();
    				}
     
    			}
    			testLocation(p, ZONE_IMAGE_11, "mouseClicked - data 11");//case 2
    			testLocation(p, ZONE_IMAGE_12, "mouseClicked - data 12");//case 3
    			testLocation(p, ZONE_IMAGE_13, "mouseClicked - data 13");//case 4
    			testLocation(p, ZONE_IMAGE_14, "mouseClicked - data 14");//case 5
    			testLocation(p, ZONE_IMAGE_15, "mouseClicked - data 15");//case 6
    			testLocation(p, ZONE_IMAGE_16, "mouseClicked - data 16");//case 7
    			testLocation(p, ZONE_IMAGE_17, "mouseClicked - data 17");//case 8
    			testLocation(p, ZONE_IMAGE_18, "mouseClicked - data 18");//case 9
     
     
     
    		}
    		public void mouseReleased(MouseEvent e) {}//peut servir pour plus tard 
    		public void mouseEntered(MouseEvent e) { }//peut servir pour plus tard 
    		public void mouseExited(MouseEvent e) { }//peut servir pour plus tard 
     
    	}
     
     
    }
    Essaye ce code et dis moi
    Désolé j'ai mis des trucs en commentaires, changé le nom de l'image
    et travaillé avec frame car j'avais pas trop compris où tu voulais afficher ton image mais ça marche
    Désolé, je suis pas très claire , mon but, c'est d'afficher un .gif animé dans la Jframe précedente tout en gardant le fond qu'il y avait avant, en claire afficher le .gif à l'écran au premier plan avant le Back-ground, mais là le code que tu m'a rendu est propre et nickel, mais fait pas comme je veux , je suis désolé, c'est de ma faute j'ai du mal à expliquer.

  8. #8
    Membre chevronné
    Homme Profil pro
    Inscrit en
    Janvier 2010
    Messages
    312
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2010
    Messages : 312
    Par défaut
    je n'est pas testé mais l'idée c'est de passer ta Frame en parametre de ton canvas. Pour cela il faut changer le constructeur de Canvas.

    D'abord, changer

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    setContentPane(new MyCanvas(img));
    en

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    setContentPane(new MyCanvas(img,this));
    ensuite ajouter

    dans la declaration des variables de MyCanvas

    enfin changer :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    public MyCanvas(BufferedImage img) {
    			this.addMouseListener(this);
    			this.buff = img;
    		}
    en

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    public MyCanvas(BufferedImage img, Frame f) {
    			this.addMouseListener(this);
    			this.buff = img;
                            this.frame = f;
    		}

  9. #9
    Membre habitué
    Homme Profil pro
    Inscrit en
    Novembre 2012
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Albanie

    Informations forums :
    Inscription : Novembre 2012
    Messages : 11
    Par défaut
    Citation Envoyé par ludomacho Voir le message
    je n'est pas testé mais l'idée c'est de passer ta Frame en parametre de ton canvas. Pour cela il faut changer le constructeur de Canvas.

    D'abord, changer

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    setContentPane(new MyCanvas(img));
    en

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    setContentPane(new MyCanvas(img,this));
    ensuite ajouter

    dans la declaration des variables de MyCanvas

    enfin changer :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    public MyCanvas(BufferedImage img) {
    			this.addMouseListener(this);
    			this.buff = img;
    		}
    en

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    public MyCanvas(BufferedImage img, Frame f) {
    			this.addMouseListener(this);
    			this.buff = img;
                            this.frame = f;
    		}
    Merci pour le temps passé, mais là j'ai toujours un problème, "quand ça veux pas...", franchement j'ai essayé mais sans résultat.

  10. #10
    Membre chevronné
    Homme Profil pro
    Inscrit en
    Janvier 2010
    Messages
    312
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2010
    Messages : 312
    Par défaut
    Bonjour,
    J'ai repris ton code initial sans trop le modifier pour faire en sorte que quand tu cliques sur zone 10 le gif s'affiche au centre de la fenetre et quand tu cliques sur 11 il s'efface.

    tu verras que la première fois que tu cliques sur 10 l'affichage est lent car c'est la première fois qu'il s'affiche.....apres c'est bon.

    En fait comme tu voulais afficher le gif sur l'image contenue dans MyCanvas je lui ai demandé de l'afficher dans MyCanvas et comme on l'affiche après l'image de fond il reste au dessus. Ainsi plus besoin d'appeler la frame principale.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
     
    public class Frame extends JFrame {
     
    	private static final long    serialVersionUID    = 4983727800375272097L;
    	public static JLabel label;
     
    	public Frame() {
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    		setSize(1367, 703);
    		setLocationRelativeTo(null);
    		BufferedImage img = null;
    		try {
    			img = ImageIO.read(new File("Background0.jpg"));
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		setContentPane(new MyCanvas(img));
    	}
     
     
     
    	public static void main(String[] args) {
    		new Frame().setVisible(true);
    	}
     
    	private static class MyCanvas extends JComponent implements MouseListener {
    		//ici on défini toutes les zones clicables de l'écran 1
     
    		private static final long    serialVersionUID    = 1L;
    		// position de la première zone de limage que l'on veut (ici elle se trouve au pixel x=0, y=0 et s'étend sur width=10 et height=10)
    		private static final Rectangle    ZONE_IMAGE_1 = new Rectangle(21, 10, 281, 50);
    		// position de la première zone de limage que l'on veut (ici elle se trouve au pixel x=100, y=100 et s'étend sur width=30 et height=20)
    		private static final Rectangle    ZONE_IMAGE_2 = new Rectangle(320, 10, 265, 50);
     
    		private static final Rectangle    ZONE_IMAGE_3 = new Rectangle(602, 10, 290, 50);
    		// position de la première zone de limage que l'on veut (ici elle se trouve au pixel x=100, y=100 et s'étend sur width=30 et height=20)
    		private static final Rectangle    ZONE_IMAGE_4 = new Rectangle(135, 200, 170, 140);
    		private static final Rectangle    ZONE_IMAGE_5 = new Rectangle(135, 352, 170, 140);
    		private static final Rectangle    ZONE_IMAGE_6 = new Rectangle(135, 506, 170, 140);
     
     
    		private static final Rectangle    ZONE_IMAGE_10 = new Rectangle(368, 200, 61, 45);
    		private static final Rectangle    ZONE_IMAGE_11 = new Rectangle(368, 247, 61, 45);
    		private static final Rectangle    ZONE_IMAGE_12 = new Rectangle(368, 294, 61, 44);
    		private static final Rectangle    ZONE_IMAGE_13 = new Rectangle(368, 340, 60, 44);
    		private static final Rectangle    ZONE_IMAGE_14 = new Rectangle(368, 386, 60, 44);
    		private static final Rectangle    ZONE_IMAGE_15 = new Rectangle(368, 432, 60, 44);
    		private static final Rectangle    ZONE_IMAGE_16 = new Rectangle(368, 478, 60, 46);
    		private static final Rectangle    ZONE_IMAGE_17 = new Rectangle(368, 526, 60, 45);
    		private static final Rectangle    ZONE_IMAGE_18 = new Rectangle(368, 573, 60, 54);
     
    		private BufferedImage buff= null;
     
    		JLabel imageLabel;
     
     
    		public MyCanvas(BufferedImage img) {
    			setLayout(null);
    			this.addMouseListener(this);
    			this.buff = img;
    					imageLabel = new JLabel();
    					ImageIcon ii = new ImageIcon(this.getClass().getResource("gifAnime.gif"));
    					imageLabel.setIcon(ii);
    					imageLabel.setBounds(626,296,ii.getIconWidth(),ii.getIconHeight());
    					imageLabel.setVisible(false);
    					add(imageLabel);
    					//imageLabel = new JLabel(new ImageIcon(this.getClass().getResource("gifAnime.gif")));
    		}
     
    		public void paintComponent(Graphics g) {//zone images
    			// dessine l'image
    			g.drawImage(buff, 0, 0, buff.getWidth(), buff.getHeight(), this);
    			// juste histoire de voir ou se trouvent les zones clicables 
    			g.setColor(Color.GREEN);
    			g.drawRect(ZONE_IMAGE_1.x, ZONE_IMAGE_1.y, ZONE_IMAGE_1.width, ZONE_IMAGE_1.height);
    			g.drawRect(ZONE_IMAGE_2.x, ZONE_IMAGE_2.y, ZONE_IMAGE_2.width, ZONE_IMAGE_2.height);
    			g.drawRect(ZONE_IMAGE_3.x, ZONE_IMAGE_3.y, ZONE_IMAGE_3.width, ZONE_IMAGE_3.height);
    			g.drawRect(ZONE_IMAGE_4.x, ZONE_IMAGE_4.y, ZONE_IMAGE_4.width, ZONE_IMAGE_4.height);
    			g.drawRect(ZONE_IMAGE_5.x, ZONE_IMAGE_5.y, ZONE_IMAGE_5.width, ZONE_IMAGE_5.height);
    			g.drawRect(ZONE_IMAGE_6.x, ZONE_IMAGE_6.y, ZONE_IMAGE_6.width, ZONE_IMAGE_6.height);
    			g.drawRect(ZONE_IMAGE_10.x, ZONE_IMAGE_10.y, ZONE_IMAGE_10.width, ZONE_IMAGE_10.height);
    			g.drawRect(ZONE_IMAGE_11.x, ZONE_IMAGE_11.y, ZONE_IMAGE_11.width, ZONE_IMAGE_11.height);
    			g.drawRect(ZONE_IMAGE_12.x, ZONE_IMAGE_12.y, ZONE_IMAGE_12.width, ZONE_IMAGE_12.height);
    			g.drawRect(ZONE_IMAGE_13.x, ZONE_IMAGE_13.y, ZONE_IMAGE_13.width, ZONE_IMAGE_13.height);
    			g.drawRect(ZONE_IMAGE_14.x, ZONE_IMAGE_14.y, ZONE_IMAGE_14.width, ZONE_IMAGE_14.height);
    			g.drawRect(ZONE_IMAGE_15.x, ZONE_IMAGE_15.y, ZONE_IMAGE_15.width, ZONE_IMAGE_15.height);
    			g.drawRect(ZONE_IMAGE_16.x, ZONE_IMAGE_16.y, ZONE_IMAGE_16.width, ZONE_IMAGE_16.height);
    			g.drawRect(ZONE_IMAGE_17.x, ZONE_IMAGE_17.y, ZONE_IMAGE_17.width, ZONE_IMAGE_17.height);
    			g.drawRect(ZONE_IMAGE_18.x, ZONE_IMAGE_18.y, ZONE_IMAGE_18.width, ZONE_IMAGE_18.height);
     
     
    		}
     
    		private Boolean testLocation(Point mouse, Rectangle area, String text) {//ici on a juste le test pour savoir si les zones de clics répondes 
    			// test si la souris est dans les data de l'image
    			if(area.contains(mouse)) {
    				System.out.println(text + " - image");
    				return true;
    			}
    			else {
    				System.out.println(text + " - !image");
    				return false;
    			}
    		}
     
    		public void mouseClicked(MouseEvent e) {
    		}
     
     
    		public void mousePressed(MouseEvent e) 
    		{            //récupération de la position de la souris
    			Point p = e.getPoint();
    			if (testLocation(p, ZONE_IMAGE_1, "mouseClicked - data 1"))
    			{//new Frame2().setVisible(true);// j'appelle ma nouvelle fenêtre 
    			}
    			testLocation(p, ZONE_IMAGE_2, "mouseClicked - data 2");
    			if (testLocation( p, ZONE_IMAGE_2, "mouseClicked - data 2")){
    				//new Frame3().setVisible(true);// j'appelle ma nouvelle fenêtre 
    			}
    			testLocation(p, ZONE_IMAGE_3, "mouseClicked - data 3");
    			if(testLocation(p, ZONE_IMAGE_3, "mouseClicked - data 3")){
    				//new Frame4().setVisible(true);// j'appelle ma nouvelle fenêtre 
    			}
     
     
    			testLocation(p, ZONE_IMAGE_4, "mouseClicked - data 4");//clapier1
    			testLocation(p, ZONE_IMAGE_5, "mouseClicked - data 5");//clapier2
    			testLocation(p, ZONE_IMAGE_6, "mouseClicked - data 6");//clapier3
     
     
    			testLocation(p, ZONE_IMAGE_10, "mouseClicked - data 10");//case 1
    			if (testLocation( p, ZONE_IMAGE_10, "mouseClicked - data 10")){
    					imageLabel.setVisible(true);  
    					repaint();
    			}
    			if (testLocation(p, ZONE_IMAGE_11, "mouseClicked - data 11")) {
    					imageLabel.setVisible(false);  
    					repaint();
    			}
    			testLocation(p, ZONE_IMAGE_12, "mouseClicked - data 12");//case 3
    			testLocation(p, ZONE_IMAGE_13, "mouseClicked - data 13");//case 4
    			testLocation(p, ZONE_IMAGE_14, "mouseClicked - data 14");//case 5
    			testLocation(p, ZONE_IMAGE_15, "mouseClicked - data 15");//case 6
    			testLocation(p, ZONE_IMAGE_16, "mouseClicked - data 16");//case 7
    			testLocation(p, ZONE_IMAGE_17, "mouseClicked - data 17");//case 8
    			testLocation(p, ZONE_IMAGE_18, "mouseClicked - data 18");//case 9
     
     
     
    		}
    		public void mouseReleased(MouseEvent e) {}//peut servir pour plus tard 
    		public void mouseEntered(MouseEvent e) { }//peut servir pour plus tard 
    		public void mouseExited(MouseEvent e) { }//peut servir pour plus tard 
     
    	}
     
     
    }

Discussions similaires

  1. Affichage d'un JLabel dans une JFrame
    Par Christophe39 dans le forum Agents de placement/Fenêtres
    Réponses: 1
    Dernier message: 17/02/2014, 13h41
  2. Récupérer un objet dans une jFrame, et le renvoyer.
    Par jerrypeeren dans le forum Agents de placement/Fenêtres
    Réponses: 1
    Dernier message: 13/04/2013, 21h14
  3. Affichage d'un JLabel dans une popup (JFrame)
    Par mattyeux dans le forum Agents de placement/Fenêtres
    Réponses: 17
    Dernier message: 05/02/2007, 15h17
  4. [JLabel] Chargement d'image dans une JFrame
    Par mr.t dans le forum Composants
    Réponses: 10
    Dernier message: 27/01/2005, 18h32
  5. [JFrame] affichage de component et d'image dans une JFrame
    Par Joeleclems dans le forum Agents de placement/Fenêtres
    Réponses: 8
    Dernier message: 08/10/2004, 16h17

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo