how to execute a message box when game is over? and how to stop the game when the game is over? pls give me the commands
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
public class DialogTest extends JDialog {
private static final long serialVersionUID = 1L;
public static void main(String[] args)
{
new DialogTest();
}
public DialogTest() {
setVisible(true);
setDefaultCloseOperation(HIDE_ON_CLOSE);
setTitle("Mein JDialog Beispiel");
setLayout(new FlowLayout());
setSize(200,200);
setModal(true);
setVisible(true);
JLabel dialogLabel = new JLabel("Enter Your Text Here");
JButton okButton = new JButton("OK");
okButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
dispose();
}
});
add(dialogLabel);
add(okButton);
}
}// imports
import java.awt.Color;
// method in world class to run when game is over
public void gameOver()
{
removeObjects(getObjects(null)); // removes all actors
getBackground().setColor(Color.white);
getBackground().fill(); // clears the background
GreenfootImage message = new GreenfootImage("Game Over", 96, Color.black, Color.white); // creates the message image
getBackground().drawImage(message, (getWidth()-message.getWidth())/2, (getHeight()-message.getHeight())/2); // draws message on background
Greenfoot.stop(); // stops the execution of the scenario
}