Skip to content

Commit

Permalink
GUI Klassen Version 0.1
Browse files Browse the repository at this point in the history
Unvollständige Variante der Klassen für Button und Label, zusätzlich
noch die Oberklasse GUI_Interface.
  • Loading branch information
Zocker1999NET committed May 10, 2016
1 parent 40b1752 commit a1e62f8
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 8 deletions.
63 changes: 63 additions & 0 deletions Button.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
*/
public class Button extends GUI_Interface {

boolean autoSize = true;
Color foreC = Color.WHITE
Color backC = Color.BLACK
int textSize = 1;
String text = "";

ButtonEvent handler;

/**
Expand All @@ -28,4 +34,61 @@ public void act() {
}
}

public boolean getAutoSize() {
return autoSize;
}

public void setAutoSize(boolean b) {
autoSize = b;
if(autoSize) {
redraw();
}
}

public int getTextSize() {
return textSize;
}

public void setTextSize(int s) {
if(textSize != s && s > 0) {
textSize = s;
redraw();
}
}

public String getText() {
return text;
}

public void setText(String s) {
if(text != s) {
text = s;
redraw();
}
}

private void redraw() {
GreenfootImage tI = new GreenfootImage(text,textSize,foreC,backC);
GreenfootImage corner = new GreenfootImage("images/Button_Corner.png");
int csx = corner.getWidth();
int csy = corner.getHeight();
GreenfootImage side = new GreenfootImage("images/Button_Side.png");
if(autoSize) {
sx = tI.getWidth() + (csx * 2);
sy = tI.getHeight() + (csy * 2);
}
GreenfootImage all = new GreenfootImage(sx,sy);
all.drawImage(corner,0,0);
corner.rotate(90);
all.drawImage(corner,sx-csx,0);
corner.rotate(90);
all.drawImage(corner,sx-csx,sy-csy);
corner.rotate(90);
all.drawImage(corner,0,sy-csy);
for(int i = csx; i < (sx-csx+1); i++) {

}
all.drawImage(tI,(sx-tI.getWidth())/2,(sy-tI.getHeight())/2);
setImage(all);
}
}
2 changes: 2 additions & 0 deletions ButtonEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
* @version 26.04.2016
*/
public interface ButtonEvent {

public void buttonClicked(Button obj);

}
33 changes: 25 additions & 8 deletions GUI_Interface.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
* Write a description of class GUI_Interface here.
* Oberklasse für sämtliche GUI Objekte, wie Labels und Buttons
*
* @author (your name)
* @version (a version number or a date)
* @author Felix Stupp
* @version 10.05.2016
*/
public class GUI_Interface extends Actor
{
/**
* Act - do whatever the GUI_Interface wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
protected int sx = 1;
protected int sy = 1;

public int getWidth() {
return sx;
}

public int getHeight() {
return sy;
}

public void setSize(int w, int h) {
if(w < 0 || h < 0) {
return;
}
sx = w;
sy = h;
}

public void act()
{
// Add your action code here.
}
}

public abstract void redraw();
}
43 changes: 43 additions & 0 deletions Label.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import System.awt.Color;

/**
* Zeigt einen Text an.
*
* @author Felix Stupp
* @version 10.05.2016
*/
public class Label extends GUI_Interface {

Color foreC = Color.WHITE
Color backC = Color.BLACK
int textSize = 1;
String text = "";

private void redraw() {
GreenfootImage tI = new GreenfootImage(text,textSize,foreC,backC);
setImage(tI);
}

public int getTextSize() {
return textSize;
}

public void setTextSize(int s) {
if(textSize != s && s > 0) {
textSize = s;
redraw();
}
}

public String getText() {
return text;
}

public void setText(String s) {
if(text != s) {
text = s;
redraw();
}
}
}
Binary file added images/Button_Corner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Button_Side.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a1e62f8

Please sign in to comment.