-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.java
More file actions
70 lines (60 loc) · 2.12 KB
/
Menu.java
File metadata and controls
70 lines (60 loc) · 2.12 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* World representing the menu screen
*
* @author Austin
* @version 0
*/
public class Menu extends World {
Button projectileButton;
Button shmButton;
Button collisionButton;
Button frictionButton;
/**
* Constructor for objects of class Menu.
*/
public Menu() {
// Create a new world with 1200x800 cells with a cell size of 1x1 pixels.
super(1200, 800, 1, false);
prepare();
setBackground(new GreenfootImage("Menu.png"));
}
/**
* Listen for button presses
*/
public void act() {
if (projectileButton.mouseDown()) {
Greenfoot.setWorld(new ProjectileMotion());
}
if (shmButton.mouseDown()) {
Greenfoot.setWorld(new SHM());
}
if (collisionButton.mouseDown()) {
Greenfoot.setWorld(new Collision());
}
if (frictionButton.mouseDown()) {
Greenfoot.setWorld(new Friction());
}
}
/**
* Define buttons and add them to the world
*/
private void prepare() {
projectileButton = new Button(205, 275, 300, 200, new Color(0, 148, 68, 0));
projectileButton.addToWorld(this);
projectileButton.setHoverColour(new Color(0, 148, 68, 120));
projectileButton.setBorderRadius(15);
shmButton = new Button(695, 275, 300, 200, new Color(0, 148, 68, 0));
shmButton.addToWorld(this);
shmButton.setHoverColour(new Color(0, 148, 68, 120));
shmButton.setBorderRadius(15);
collisionButton = new Button(205, 526, 300, 200, new Color(0, 148, 68, 0));
collisionButton.addToWorld(this);
collisionButton.setHoverColour(new Color(0, 148, 68, 120));
collisionButton.setBorderRadius(15);
frictionButton = new Button(695, 526, 300, 200, new Color(0, 148, 68, 0));
frictionButton.addToWorld(this);
frictionButton.setHoverColour(new Color(0, 148, 68, 120));
frictionButton.setBorderRadius(15);
}
}