-
Notifications
You must be signed in to change notification settings - Fork 0
/
Screen.java
54 lines (47 loc) · 1.45 KB
/
Screen.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
47
48
49
50
51
52
53
54
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
import java.awt.Font;
import java.lang.Math;
/**
* Class for text displaying objects.
*/
public class Screen extends hackedActor
{
static final float FONT_SIZE = 48.0f;
/**
* Act - do whatever the Screen wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
}
public Screen(String... Text)
{
makeImage(Text);
}
/**
* Erstellt ein Textfeld
*/
private void makeImage(String... Text)
{
int WIDTH = getDungeon().frameWidth;
int HEIGHT = getDungeon().frameHeight;
int i = 0;
GreenfootImage image = new GreenfootImage(WIDTH, HEIGHT);
image.setColor(new Color(255,255,255, 128));
image.fillRect(0, 0, WIDTH, HEIGHT);
image.setColor(new Color(0, 0, 0, 128));
image.fillRect(5, 5, WIDTH-10, HEIGHT-10);
Font font = image.getFont();
font = font.deriveFont(FONT_SIZE);
image.setFont(font);
image.setColor(Color.WHITE);
for(String curText: Text)
{
image.drawString(curText, WIDTH / 2 - Math.round(curText.length() / 2) * 20, 100 +i * HEIGHT/Text.length);
i++;
}
setImage(image);
}
}