java - Message dialog reappears over and over -
we made method determine our image in our frame. if image in part of frame show message dialog , return our main jpanel ( we're making minigolf game ;) )
the problem when message dialog appears, keeps reappearing after switched our main panel. here's code:
package project; import java.awt.graphics; import java.awt.image; import java.io.file; import javax.swing.imageicon; import javax.swing.jlabel; import javax.swing.joptionpane; public class blackhole { image blackhole; int xblack; int yblack; public final int breedte=75; public final int hoogte=75; public string afbeelding2; public atoom atoom; public frame venster; public spelpaneel x; public blackhole(int xblack, int yblack, string afbeelding2) { this.xblack = xblack; this.yblack = yblack; blackhole = new imageicon(getclass().getresource(afbeelding2)).getimage(); } public void tekenblackhole(graphics g) { g.drawimage(blackhole,xblack,yblack,75,75,null); } public boolean gameover(atoom atoom) { return ((atoom.xpositie +atoom.breedte > this.xblack) && (atoom.xpositie < this.xblack + this.breedte) && (atoom.ypositie + atoom.hoogte>this.yblack && atoom.ypositie<this.yblack+this.hoogte )) ; } and method call upon in our class playing happens.
if (blackhole.gameover(atoom)) { joptionpane.showmessagedialog(null, "you're goneee in black hole !!"); venster.switchpanel(); }
you need have boolean variable tell if message has been shown. like
if (blackhole.gameover(atoom) && !messagehasbeenshown) { messagehasbeenshown = true; joptionpane.showmessagedialog(null, "you're goneee in black hole !!"); venster.switchpanel(); } and messagehasbeenshown = true; somewhere before.
Comments
Post a Comment