Mettre un arrière-plan sur mon Interface graphique

Fermé
thek_ Messages postés 2 Date d'inscription samedi 18 mars 2017 Statut Membre Dernière intervention 21 mars 2017 - 21 mars 2017 à 22:57
Bonjour,

Cela fait deux jours que j'essaie de mettre un arrière-plan derrière mon menu, mais rien n'y fait. Soit le fond reste noir, soit les boutons disparaissent. Je vous met mon code ci-dessous. J'ai déjà parcourut pas mal de sujet sur le forum concernant les arrières plan mais aucun utilisant les boutons JLabel.
		import javax.swing.*;
import java.awt.*;
import java.awt.*;
import java.awt.event.*; 
import javax.swing.*;
import javax.swing.event.*;
import java.awt.image.*;

public class Interface extends JFrame {
	String [] tabCouleur = {"Rouge", "Bleu", "Vert" , "Jaune"};
	String [] tabMode = {"Ville", "Campagne", "..." , "..."};
	BufferedImage ArrierePlan; // L'arriere plan sur lequel on va dessiner
    Image img1; 	    // L'image du papier peint
    Dimension dim;     // Dimension de la fenetre
    Graphics buffer;   // Pour la fluidite des animations  
 

	public Interface(){
		this.setTitle(" JEU ");
		this.setLayout(null);
		this.setSize(550,550);
		this.setLocation(100,100);
		this.setResizable(true);
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		

		
		/**
		* ARRIERE PLAN 
		*/
		// Creation de l'arriere plan sur laquelle on va dessiner
		ArrierePlan=new BufferedImage(550,550,BufferedImage.TYPE_INT_RGB);
		// Tous ce qui sera dessine par le buffer sera ecrit dans l'ArrierePlan
		//buffer = ArrierePlan.getGraphics(); 
		// charge une image 400x400 d un mur comme papier peint
		//wall = Toolkit.getDefaultToolkit().getImage("backround.png");
		
		Toolkit t = Toolkit.getDefaultToolkit();
		img1 = t.getImage("backround.png");
		
		/**
		* Mon bouton sélection de couleur
		*/
		JPanel panneauChoix = new JPanel();
		panneauChoix.setBounds(40,190,210,100);
		panneauChoix.setLayout(null);
		panneauChoix.setBackground(Color.white);
		
		JLabel affTest = new JLabel();
		affTest.setText("  Selectionnez une couleur");
		affTest.setBounds(25,10,350,50);
		affTest.setBackground(Color.white);
		panneauChoix.add(affTest);
		
		String[] couleurStrings = new String[tabCouleur.length+1];
		couleurStrings[0] = "Toutes les couleurs";
		couleurStrings[1] = tabCouleur[0];
		couleurStrings[2] = tabCouleur[1];
		couleurStrings[3] = tabCouleur[2];
		couleurStrings[4] = tabCouleur[3];
		JComboBox couleurList = new JComboBox(couleurStrings);
		couleurList.setBounds(25,50,160,20);
		panneauChoix.add(couleurList);
		
		/**
		* Mon bouton sélection de mode
		*/
		JPanel panneauChoix2 = new JPanel();
		panneauChoix2.setBounds(280,190,210,100);
		panneauChoix2.setLayout(null);
		panneauChoix2.setBackground(Color.white);
		
		JLabel affTest2 = new JLabel();
		affTest2.setText("     Selectionnez un mode");
		affTest2.setBounds(25,10,350,50);
		affTest2.setBackground(Color.white);
		panneauChoix2.add(affTest2);
		
		String[] modeStrings = new String[tabMode.length+1];
		modeStrings[0] = "Toutes les modes";
		modeStrings[1] = tabMode[0];
		modeStrings[2] = tabMode[1];
		modeStrings[3] = tabMode[2];
		modeStrings[4] = tabMode[3];
		JComboBox modeList = new JComboBox(modeStrings);
		modeList.setBounds(25,50,160,20);
		panneauChoix2.add(modeList);
		
		/**
		 * Mon panneau 3
		 */
		
		JPanel panneauBouton = new JPanel();
		panneauBouton.setBounds(165,350,200,100);
		panneauBouton.setLayout(null);
		panneauBouton.setBackground(new Color(34,66,124));
		
		JButton monBoutonPlot = new JButton("Play");
		monBoutonPlot.setBounds(10,10,180,80);
		monBoutonPlot.setBackground(new Color(219,23,2));
		monBoutonPlot.setForeground(Color.white);
		panneauBouton.add(monBoutonPlot);
		
		/**
		 * Mon panneau Global
		 */
		JPanel panneauGlobal = new JPanel();
		panneauGlobal.setBounds(0,0,400,400);
		panneauGlobal.setLayout(null);
		panneauGlobal.setBackground(Color.black);
		panneauGlobal.add(panneauChoix);
		panneauGlobal.add(panneauChoix2);
		panneauGlobal.add(panneauBouton);
		this.setContentPane(panneauGlobal);
	
	}
			
}


Merci par avance
A voir également: