-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExitButton.java
46 lines (39 loc) · 1.1 KB
/
ExitButton.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class ExitButton here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ExitButton extends Actor implements Button
{
int appeared;
public ExitButton(){
resize();
appeared = 0;
}
public int appear(){
setImage("ExitButton.png");
resize();
return 1;
}
/**
* Act - do whatever the ExitButton wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if(appeared == 0){
appeared = appear();
}
if(Greenfoot.mouseClicked(this)){
Greenfoot.playSound("Select.mp3");
}
}
public void resize(){
GreenfootImage myImage = getImage();
int newHeight = (int)myImage.getHeight()/1+10;
int newWidth = (int)myImage.getWidth()/4-30;
myImage.scale(newHeight, newWidth);
}
}