[AWT] paint() et ImageObserver
Bonsoir à tous et toutes,
Voilà, j'ai un petit problème pour modifier le background de mon Panel, je voudrai donc utiliser la méthode paint() pour pouvoir peindre ce background avec une image, le problème est qu'il me faut un ImageObserver pour utiliser la méthode drawImage. J'ai été voir l'API tout ça, voir d'autres solutions utilisant cette méthode, mais dans ces autres méthodes ils utilisent ''this'' (comme dans le code ci-dessous). Mais cela génère une erreur
Code:
1 2 3 4 5 6 7 8
| Exception in thread "main" java.lang.NullPointerException
at interfaceContainer.MenuGauche.paint(MenuGauche.java:38)
at interfaceContainer.MenuGauche.<init>(MenuGauche.java:52)
at interfaceContainer.InterfaceCard.getTaskPane(InterfaceCard.java:102)
at interfaceContainer.InterfaceCard.<init>(InterfaceCard.java:66)
at interfaceContainer.InterfaceCont.getJpAdmin(InterfaceCont.java:126)
at interfaceContainer.InterfaceCont.<init>(InterfaceCont.java:46)
at projet.Test.main(Test.java:108) |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
public void paint(Graphics g, String path){
Image img = getToolkit().getImage(path);
//ImageObserver ??
g.drawImage( img, 0, 0, 400, 150, this );
super.paint(g);
}
public MenuGauche(InterfaceCard princip){
//implements JXTaskPaneContainer
super();
this.principale=princip;
this.setMinimumSize(new Dimension(200,600));
this.setMaximumSize(new Dimension(200,600));
this.setPreferredSize(new Dimension(200,600));
Graphics g=this.getGraphics();
this.paint(g, "images/backMenuGauche.png");
...
} |
Merci d'avance pour votre aide,
Arkh.