GUI Objekte 0.1 erweitert

Standard Textgröße auf 32 gesetzt
Button Handler darf nun auch "null" sein
Weitere Konstruktoren eingebaut
pull/20/head
Zocker1999NET 8 years ago
parent 51536fe0ca
commit ac3e6477f4

@ -12,24 +12,36 @@ public class Button extends GUI_Interface {
boolean autoSize = true;
Color foreC = Color.WHITE;
Color backC = Color.BLACK;
int textSize = 1;
int textSize = 32; // as default text size
String text = "";
ButtonEvent handler;
public Button(String txt, int size) {
text = txt;
textSize = size;
redraw();
}
/**
* Erstellt einen Button mit dem gegebenen Objekt als Event-Handler.
* @param h Der Handler mit dem Interface ButtonEvent implementiert.
*/
public Button(ButtonEvent h) {
handler = h;
redraw();
}
public Button(String txt, int size, ButtonEvent h) {
text = txt;
textSize = size;
handler = h;
redraw();
}
/**
* Fragt ab, ob ein Klick auf den Button gekommen ist.
*/
public void act() {
if(Greenfoot.mouseClicked(this)) {
if(Greenfoot.mouseClicked(this) && handler != this) {
handler.buttonClicked(this);
}
}
@ -37,7 +49,6 @@ public class Button extends GUI_Interface {
public boolean getAutoSize() {
return autoSize;
}
public void setAutoSize(boolean b) {
autoSize = b;
if(autoSize) {
@ -48,7 +59,6 @@ public class Button extends GUI_Interface {
public int getTextSize() {
return textSize;
}
public void setTextSize(int s) {
if(textSize != s && s > 0) {
textSize = s;
@ -59,7 +69,6 @@ public class Button extends GUI_Interface {
public String getText() {
return text;
}
public void setText(String s) {
if(text != s) {
text = s;
@ -67,6 +76,16 @@ public class Button extends GUI_Interface {
}
}
public ButtonEvent getHandler() {
return handler;
}
public void setHandler(ButtonEvent h) {
handler = h;
}
public void removeHandler() {
handler = null;
}
public void redraw() {
GreenfootImage tI = new GreenfootImage(text,textSize,foreC,backC);
GreenfootImage corner = new GreenfootImage("images/Button_Corner.png");
@ -74,32 +93,35 @@ public class Button extends GUI_Interface {
int csy = corner.getHeight();
GreenfootImage side = new GreenfootImage("images/Button_Side.png");
if(autoSize) {
sx = tI.getWidth() + (csx * 2);
sy = tI.getHeight() + (csy * 2);
sx = tI.getWidth() + (csx * 2) + 4;
sy = tI.getHeight() + (csy * 2) + 4;
}
GreenfootImage all = new GreenfootImage(sx,sy);
all.setColor(Color.BLACK);
all.fill();
all.drawImage(corner,0,0); // top left
corner.rotate(90);
all.drawImage(corner,0,sy-csy); // bottom left
all.drawImage(corner,sx-csx,0); // top right
corner.rotate(90);
all.drawImage(corner,sx-csx,sy-csy); // bottom right
corner.rotate(90);
all.drawImage(corner,sx-csx,0); // top right
all.drawImage(corner,0,sy-csy); // bottom left
for(int i = csx; i > (sx-csx); i++) {
all.drawImage(side,i,0); // top
System.out.println("This is a test line at " + i);
}
side.rotate(90);
for(int i = csy; i > (sy-csy); i++) { // left
all.drawImage(side,0,i);
for(int i = csy; i > (sy-csy); i++) {
all.drawImage(side,sx-csx,i); // right
}
side.rotate(90);
for(int i = csx; i > (sx-csx); i++) { // bottom
all.drawImage(side,i,sy-csy);
}
for(int i = csy; i > (sy-csy); i++) {
all.drawImage(side,sx-csx,i); // right
}
side.rotate(90);
for(int i = csy; i > (sy-csy); i++) { // left
all.drawImage(side,0,i);
}
all.drawImage(tI,(sx-tI.getWidth())/2,(sy-tI.getHeight())/2);
setImage(all);
}

@ -11,9 +11,15 @@ public class Label extends GUI_Interface {
Color foreC = Color.WHITE;
Color backC = Color.BLACK;
int textSize = 1;
int textSize = 32;
String text = "";
public Label(String txt, int size) {
text = txt;
textSize = size;
redraw();
}
public void redraw() {
GreenfootImage tI = new GreenfootImage(text,textSize,foreC,backC);
setImage(tI);

@ -8,6 +8,10 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
*/
public class Menue_Button extends Button
{
public Menue_Button(ButtonEvent h) {
super(h);
}
/**
* Act - do whatever the Menue_Button wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.

@ -8,6 +8,10 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
*/
public class Roll_Button extends Button
{
public Roll_Button(ButtonEvent h) {
super(h);
}
/**
* Act - do whatever the Würfel_Button_Angriff wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.

Loading…
Cancel
Save