diff --git a/Button.java b/Button.java index 82bb984..9d196df 100644 --- a/Button.java +++ b/Button.java @@ -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); } diff --git a/Label.java b/Label.java index 1a21cc3..f6c95ec 100644 --- a/Label.java +++ b/Label.java @@ -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); diff --git a/Menue_Button.java b/Menue_Button.java index 44805e3..cb538aa 100644 --- a/Menue_Button.java +++ b/Menue_Button.java @@ -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. diff --git a/Roll_Button.java b/Roll_Button.java index 53ff8bc..46b6d7d 100644 --- a/Roll_Button.java +++ b/Roll_Button.java @@ -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.