Bonjour,
Je ne comprends pas pourquoi rien ne s'affiche dans ma fenêtre. Je pense qu'il s'agit d'un problème de variable.
Merci de votre réponse.
package fourmiliere; import javax.swing.JFrame; import javax.swing.*; import java.awt.*; import javax.swing.border.TitledBorder; public class phasedejeu extends JFrame{ public phasedejeu() { try { jbInit(); } catch (Exception ex) { ex.printStackTrace(); } this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setLocation(100,100); this.setSize(700,550); this.setTitle("Simulation"); this.setVisible(true); } private JPanelDessin2 jPanel5 = new JPanelDessin2(this); private Dimension dim = jPanel5.getSize() ; private int larg = dim.width ; private int haut = dim.height; public int getLarg(){ return larg; } public void setLarg(int x){ larg=x; } public int getHaut(){ return haut; } public void setHaut(int y){ haut=y; } JPanel jPanel6 = new JPanel(); JPanel jPanel7 = new JPanel(); TitledBorder titledBorder1 = new TitledBorder(""); Icon tigerIcon = new ImageIcon("stop.gif"); JButton jButton1 = new JButton("",tigerIcon); Icon stopIcon = new ImageIcon("lecture2.gif"); JButton jButton2 = new JButton("",stopIcon); Icon fourmIcon = new ImageIcon("fourmis.gif"); }
package fourmiliere; import java.awt.*; import javax.swing.*; public class JPanelDessin2 extends JPanel { private phasedejeu jeu; public int largeur ; public int hauteur ; Image tete2,fourmiliere,texture; public JPanelDessin2(phasedejeu paramJeu){ this.jeu=paramJeu; this.largeur = jeu.getLarg(); this.hauteur = jeu.getHaut(); texture=Toolkit.getDefaultToolkit().getImage("herbe.32934.jpg"); tete2 = Toolkit.getDefaultToolkit().getImage("fourmi.jpg"); fourmiliere = Toolkit.getDefaultToolkit().getImage("DSC_4798 Anthill l.jpg"); try { jbInit(); } catch (Exception ex) { ex.printStackTrace(); } } public void paintComponent (Graphics g) { super.paintComponent(g); this.setBackground(Color.white); int x=largeur; int y=hauteur; //g.drawImage(texture,0,0,1350,758,this); g.drawImage(tete2,200,50,x,y, this); //g.drawImage(fourmiliere,50,100,100,100,this); } private void jbInit() throws Exception { } }