GUI Klassen Version 0.1

Unvollständige Variante der Klassen für Button und Label, zusätzlich
noch die Oberklasse GUI_Interface.
pull/20/head
Felix Stupp 8 years ago
parent 40b1752ddc
commit a1e62f825e

@ -8,6 +8,12 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
*/
public class Button extends GUI_Interface {
boolean autoSize = true;
Color foreC = Color.WHITE
Color backC = Color.BLACK
int textSize = 1;
String text = "";
ButtonEvent handler;
/**
@ -28,4 +34,61 @@ public class Button extends GUI_Interface {
}
}
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);
}
}

@ -8,5 +8,7 @@ import greenfoot.*;
* @version 26.04.2016
*/
public interface ButtonEvent {
public void buttonClicked(Button obj);
}

@ -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();
}

@ -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 not shown.

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 B

Loading…
Cancel
Save