import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.io.Serializable; import javax.swing.JLabel; public class TextBox extends JLabel implements Serializable{ public String text; public int x; public int y; public int width; public int height; public TextBox(String text,int x, int y,int width, int height){ this.text = text; this.x = x; this.y = y; this.width = width; this.height = height; } public void paint(Graphics g){ super.paintComponent(g); Graphics2D g2=(Graphics2D) g; Rectangle2D rect = new Rectangle2D.Double(x,y,width,height); g2.setPaint(Color.BLACK); g2.drawString(text, x + width/2 , y + height/2); g2.draw(rect); } }