HomeForumSourceResearchGuide
Sign in to contribute to source. how it works
Component ui.Label by barry
expand copy to clipboardexpand
component provides Label requires os.SystemInfo sysInfo, ui.Font {
	
	char text[]
	
	Font font
	
	Color color
	
	Label:Label(char txt[])
		{
		font = new Font(sysInfo.getSystemFont(false), 15)
		
		if (font == null) throw new Exception("System default font could not be loaded")
		
		text = txt
		
		color = new Color(0, 0, 0, 255)
		}
	
	void Label:setFont(Font f)
		{
		font = f
		
		postRepaint()
		}
	
	void Label:setText(char txt[])
		{
		text = txt
		
		postRepaint()
		}
	
	void Label:setColor(Color c)
		{
		color = c
		
		postRepaint()
		}
	
	void Label:setPosition(int x, int y)
		{
		xPosition = x
		yPosition = y
		
		postRepaint()
		}
	
	Point Label:getPosition()
		{
		return new Point(xPosition, yPosition)
		}
	
	void Label:paint(Canvas c)
		{
		c.text(new Point2D(xPosition, yPosition, color), font, text)
		}
	
	WH Label:getPreferredSize()
		{
		return new WH(font.getTextWidth(text), font.getFontMetrics().height)
		}
	
	void Label:postRepaint()
		{
		emitevent repaint()
		}
	}
Revision history
To propose a new revision to this entity, use dana source put -uc your/new/version.dn -n ui.Label -m "reason for update" -u yourUsername
Version 2 by barry
Version 1 (this version) by barry
Notes for this version: Standard Library Initialisation