please dont rip this site

Language Java Nosugar Graphics Font Code Fontwobbler.java

// 
//	FontWobbler class
//	part of the set of documents known as Java no sugar.
//	Copyright (c) 1996 Sunil Gupta, sunil@magnetic.demon.co.uk
//	placed into the public domain by the author
//
import java.awt.*;
	
public class FontWobbler extends ThreadedCanvas
{
	//*******************************************************************
	// globals
	//*******************************************************************
	static final String HELVETICA = "Helvetica";
	static final String TIMES = "TimesRoman";
	static final String COURIER ="Courier";
	static final String DIALOG = "Dialog";
	static final String DIALOGINPUT = "DialogInput";
	static final String ZAPFDINGBATS = "ZapfDingbats";

	static final String PLAIN = "Normal";
	static final String ITALIC = "Italic";
	static final String BOLD = "Bold";
	static final String BOLDITALIC = "BoldItalic";

	//*******************************************************************
	// instance variables
	//*******************************************************************
	Font the_font;
	String the_caption;
	int x,y;
	FontMetrics metrics = null;
	
	//*******************************************************************
	// Public interface
	//*******************************************************************
	public void wobbleFont(String font_name, String font_style, String font_size)
	{
		int style;
		
		// ------------------ build font ---------------
		if ( font_style.equals(ITALIC))
			style = Font.ITALIC;
		else if ( font_style.equals(BOLD))
			style = Font.BOLD;
		else if ( font_style.equals(BOLDITALIC))
			style = Font.ITALIC + Font.BOLD;
		else
			style = 0;

		the_font = new Font(font_name, style, Integer.parseInt(font_size));
		the_caption = font_name + "-" + font_style + "-" + font_size;
		
		start();
	}
	
	//*******************************************************************
	// APPLET 
	//*******************************************************************
	public Dimension minimumSize() 	
	{
		return ( new Dimension(200,200));
	}

	//*******************************************************************
	// THREADS 
	//*******************************************************************
	public void onRun(Graphics g)
	{
		g.setFont(the_font);
		metrics = g.getFontMetrics();
			
		x = (rect.width -metrics.stringWidth(the_caption) ) / 2;
		y = (rect.height -metrics.getHeight()) / 2;
	}
	
	//------draw the font with small but random offset---
	public void onLoop(Graphics g)
	{
		int dx,dy;
		
		dx = (int) (5 * Math.random());
		dy = (int) (5 * Math.random());
		g.drawString( the_caption, x+dx, y+dy);
	}
}


file: /Techref/language/java/nosugar/graphics/font/code/FontWobbler.java, 2KB, , updated: 1997/6/1 00:35, local time: 2024/6/26 06:46,
TOP NEW HELP FIND: 
3.148.109.105:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://ecomorder.com/Techref/language/java/nosugar/graphics/font/code/FontWobbler.java"> language java nosugar graphics font code FontWobbler</A>

Did you find what you needed?

 

Welcome to ecomorder.com!

 

Welcome to ecomorder.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .