A
ash34
Gast
Hy,
ich würde gerne zu einer Box einen String hinzufügen. Dieser String sollte links oben in der Box stehen.
Hier mal die Klasse Box:
Hat jemand eine Idee?
(setText() sollte das einfügen des Textes dann realisieren...ich weiß halt nur nicht wie..)
ich würde gerne zu einer Box einen String hinzufügen. Dieser String sollte links oben in der Box stehen.
Hier mal die Klasse Box:
Java:
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Stroke;
public class Box {
private int x, y;
private int width, height;
private Stroke stroke = new BasicStroke(1);
private Rectangle bounds;
public Box(int width, int height, int x, int y) {
this.width = width;
this.height = height;
this.setLocation(x, y);
}
public void setLocation(int x, int y) {
this.x = x;
this.y = y;
bounds = new Rectangle(x, y, width, height);
}
public Rectangle getBounds() {
return bounds;
}
public void setText(String str){
}
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)g.create();
g2.setStroke(stroke);
g2.setColor(Color.WHITE);
g2.fillRect(x, y, width, height);
g2.setColor(Color.BLACK);
g2.drawRect(x, y, width, height);
g2.dispose();
}
}
Hat jemand eine Idee?
(setText() sollte das einfügen des Textes dann realisieren...ich weiß halt nur nicht wie..)
Zuletzt bearbeitet von einem Moderator: