internet.com logo The Java Boutique Java is a trademark of Sun Microsystems, Inc.
 ARTICLES
Tutorials
Reviews
Glossary
 APPLETS
by Category
by Date
by Name
Hall of Fame
Archive
Submit
Source Code
Servlets and JSP
 COMMUNITY
FAQ
Users Poll
Discussion Forum
Contact Us
 OTHER RESOURCES
Custom Applets
Java@Work
Java News
Jini Watch
Affiliate Programs

internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

internet.commerce
Partner With Us
Server Racks
Promote Your Website
Imprinted Gifts
Online Shopping
Televisions
Phone Cards
Prepaid Phone Card
Corporate Awards
Laptops
Web Hosting Directory
Free Business Cards
Online Education
Online Universities
Car Donations

WebDeveloper Network
ExtremeFlash
FlashKit
FlashPlanet
Gif.com
JavaBoutique
JavaScript.com
JavaScriptSource
Jobs.Webdeveloper.com
JustSMIL
ScriptSearch
StreamingMediaWorld
VoiceXML Planet
WebDevelopersJournal The WDVL
WebDeveloper.com
WebReference.com
XML101

Web Developer
Opt-in Lists

CGI
HTML
Java
JavaScript
Web Design and Promotion
Web Site Development
E-mail Address:


Can you receive
HTML e-mail?

Yes   No

Zip Code:


StringGradient


Java Source:

// Written By Bavo Bruylandt
// Http://javadesign.web.com
// This source is for reference only.
// Do not modify it for distribution.
// Thanks ;)
// Sorry for the mess with all those components.

import java.io.*;
import java.lang.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class GradientPanel extends Applet implements ActionListener, ItemListener{
	Button Prepaint = new Button("Calculate");
	TextField Ptext=new TextField("JavaBoutique",30);
	TextField Pcyclecolor=new TextField("red",10);
	TextField Pcyclespeed=new TextField("10",10);
	TextField Pfontred=new TextField("0",10);
	TextField Pfontblue=new TextField("0",10);
	TextField Pfontgreen=new TextField("0",10);
	TextField Pfontsize =new TextField("30",10);
	TextField Pbgred=new TextField("100",10);
	TextField Pbggreen=new TextField("100",10);
	TextField Pbgblue=new TextField("100",10);
	CheckboxGroup mv=new CheckboxGroup();
	Checkbox Pred=new Checkbox("Red", mv,false);
	Checkbox Pgreen=new Checkbox("Green", mv,true);
	Checkbox Pblue=new Checkbox("Blue", mv,false);
	Checkbox Pall=new Checkbox("All", mv,false);
	Checkbox Pupsidedown=new Checkbox("Reverse",false);
	Label Pistring = new Label("String");

	Label Pisize = new Label("Fontsize");
	Label Pistrength = new Label("Strength");
	Label Pirgb = new Label("StartColor of Gradient (Red,Green,Blue)");
	Label Pibgrgb = new Label("Bgcolor of String (Red,Green,Blue)");

	String text;
	int a=0;
	int pixely=10;
	int fontsize;
	Color kleur;
	Color bgkleur;
	boolean upsidedown = false;
	int blue;
	int green;
	int red;
	int bgblue;
	String cyclecolor;
	int bggreen;
	int bgred;
	int cyclespeed;
  int fontwidth = 0;
			
	public void init() {
		Color bgboxes= new Color(100,100,100);
		setBackground(Color.yellow);
		setLayout(null);
		Ptext.setBounds(30,100,60,20);
		Pfontsize.setBounds(120,100,60,20);
		Pcyclespeed.setBounds(200,100,60,20);
		Pbgred.setBounds(30,150,60,20);
		Pbggreen.setBounds(120,150,60,20);
		Pbgblue.setBounds(200,150,60,20);
		Pfontred.setBounds(30,200,60,20);
		Pfontgreen.setBounds(120,200,60,20);
		Pfontblue.setBounds(200,200,60,20);
		Pupsidedown.setBounds(30,250,80,20);
		Prepaint.setBounds(120,250,140,30);
		Pred.setBounds(30,300,60,20);
		Pblue.setBounds(120,300,60,20);
		Pgreen.setBounds(200,300,60,20);
		Pistring.setBounds(30,80,60,15);
		Pisize.setBounds(120,80,60,15);
		Pistrength.setBounds(200,80,60,15);
		Pirgb.setBounds(30,180,230,15);
		Pibgrgb.setBounds(30,130,230,15);

		Pblue.setBackground(bgboxes);
		Pred.setBackground(bgboxes);
		Pgreen.setBackground(bgboxes);
		Ptext.setBackground(Color.white);
		Pfontsize.setBackground(Color.white);
		Pcyclespeed.setBackground(Color.white);
		Pbgred.setBackground(Color.white);
		Pbggreen.setBackground(Color.white);
		Pbgblue.setBackground(Color.white);
		Pfontred.setBackground(Color.white);
		Pfontgreen.setBackground(Color.white);
		Pfontblue.setBackground(Color.white);
		Pupsidedown.setBackground(bgboxes);
		Prepaint.setBounds(120,250,140,30);
		add(Pistring);
		add(Pibgrgb);
		add(Pisize);
		add(Pistrength);
		add(Pirgb);
		add(Pred);
		add(Pgreen);
		add(Pblue);
		add(Ptext);
		add(Pfontsize);
		add(Pcyclespeed);
		add(Pbgred);
		add(Pbggreen);
		add(Pbgblue);
		add(Pfontred);
		add(Pfontgreen);
		add(Pfontblue);
		add(Ptext);
		add(Pupsidedown);
		add(Prepaint);
		Prepaint.addActionListener(this);
		Pfontblue.addActionListener(this);
		Pfontred.addActionListener(this);
		Pfontgreen.addActionListener(this);
		Pred.addItemListener(this);
		Pgreen.addItemListener(this);
		Pblue.addItemListener(this);
		Pupsidedown.addItemListener(this);
	}
	
	public void paint(Graphics g) {
		cyclecolor = Pcyclecolor.getText();
		if (Pred.getState()) cyclecolor = "red";
		if (Pgreen.getState()) cyclecolor = "green";
		if (Pblue.getState()) cyclecolor = "blue";
		text = Ptext.getText();
		cyclespeed = Integer.parseInt(Pcyclespeed.getText());
		fontsize = Integer.parseInt(Pfontsize.getText());
  	red = Integer.parseInt(Pfontred.getText());
   	green = Integer.parseInt(Pfontgreen.getText());
   	blue = Integer.parseInt(Pfontblue.getText());
  	kleur = new Color(red,green,blue);
		bgred = Integer.parseInt(Pbgred.getText());
   	bggreen = Integer.parseInt(Pbggreen.getText());
  	bgblue = Integer.parseInt(Pbgblue.getText());
  	bgkleur = new Color(bgred,bggreen,bgblue);
		if (Pupsidedown.getState()) upsidedown = true;
		else upsidedown = false;
		Image [] line = new Image [fontsize+fontsize/2];
		Graphics [] lineGraph = new Graphics [fontsize+fontsize/2];
 		Font nl = new Font("Impact", Font.PLAIN, fontsize);
   	FontMetrics fontmetrics = getFontMetrics(nl);
   	fontwidth = fontmetrics.stringWidth(text);
		for (int w=0;w<fontsize+fontsize/2;w++) {
 			line[w] = createImage(fontwidth+30,1);
 			lineGraph[w] = line[w].getGraphics();
			if (cyclecolor.equals("red")) {
				red+=cyclespeed;
				if (red >255)red=0;
			}
			else if (cyclecolor.equals("green")) {
				green+=cyclespeed;
				if (green >255)green=0;
			}
			else if (cyclecolor.equals("blue")) {
				blue+=cyclespeed;
				if (blue >255)blue=0;
			}
			else if (cyclecolor.equals("all")) {
				blue+=cyclespeed;
				red+=cyclespeed;
				green+=cyclespeed;
			if (blue >255)blue=0;
			if (red >255)red=0;
			if (green >255)green=0;
			}

  		kleur = new Color(red,green,blue);
 			lineGraph[w].setColor(kleur);
 			setBackground(bgkleur);
 			lineGraph[w].setFont(nl);
		}
		
		if (upsidedown) {
			for (int w=0;w<fontsize+fontsize/2-1;w++) {
			lineGraph[w].drawString(text,20,a);
			g.drawImage(line[w],20,pixely+20,this);
			a+=1;
			pixely++;
			}
		}
		else {
			for (int w=0;w<fontsize+fontsize/2-1;w++) {
			lineGraph[w].drawString(text,20,a);
			g.drawImage(line[fontsize+fontsize/2-1-w],20,pixely-fontsize+20,this);
			a+=1;
			pixely++;
		}
	}
	a=0;
	pixely=10;
	}
	
	public void actionPerformed (ActionEvent act) {
		repaint();
  			
	}
	public void itemStateChanged (ItemEvent ievt) {
		repaint();
	}
}		
Back to GradientString

Applet Index
(sorted alphabetically)

A B C D E F G H I J K
L M N O P Q R S T U
V W X Y Z #s
The Java Source
(applets w/source code)

A B C D E F G H I J K
L M N O P Q R S T U
V W X Y Z

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.


Copyright 2002 INT Media Group, Incorporated. All Rights Reserved.
Legal Notices,  Licensing, Reprints, & Permissions,  Privacy Policy.
http://www.internet.com/