please dont rip this site

Language Java Nosugar Custom Progress Code Progressbar.java

// 
//	ProgressBar class
//	part of the set of documents known as Java no sugar.
//	Copyright (c) 1996,1997 Sunil Gupta, sunil@magnetic.demon.co.uk
//	placed into the public domain by the author
//
import java.awt.*;

public class ProgressBar extends Canvas
{
	//##################################################################
	//
	//##################################################################
	public static final int HORIZONTAL = 0;
	public static final int VERTICAL = 1;
	public static final int SOLID = 2;
	public static final int SLATTED = 3;
	
	private int percentage = 0;
	private int style = SOLID;
	private int orientation = HORIZONTAL;
	private Color bar_colour = Color.blue;
	private Color border_colour = Color.gray;
	private int slat_gap = 2; // pixels;
	private int slat_width = 10; // pixels;
	
	
	//##################################################################
	//
	//##################################################################
	public ProgressBar( int orientation)
	{
		this.orientation = orientation;
	}
	
	public ProgressBar( int orientation, int style)
	{
		this(orientation);
		this.style = style;
	}
	
	//******************************************************************
	// initial size must be set in addNotify, not in constructor or
	// tharr be null pointers
	public void addNotify()
	{
		super.addNotify();
		resize(this.preferredSize());
	}
	
	//******************************************************************
	public void paint (Graphics g)
	{
		Dimension size;
		int bar_width, bar_height;
		
		size = size();
		
		//---------figure out the size of the bar------------------------------
		if (orientation == HORIZONTAL)
		{
			bar_height = size.height;
			bar_width = (int) Math.round( (double)percentage/100.0 * (double)size.width);
		}
		else
		{
			bar_width = size.width;
			bar_height = (int) Math.round( (double)percentage/100.0 * (double)size.height);
		}
		
		//---------draw bar-----------------------------------------------------
		g.setColor( bar_colour);
		
		switch (style)
		{
			case SLATTED:
				if (orientation == HORIZONTAL)
					horizontal_slats(g, bar_width, bar_height);
				else
					vertical_slats(g, bar_width, bar_height, size.height);
				break;
				
			case SOLID:
			default:
				if (orientation == VERTICAL)
					g.fillRect(1, size.height-2-bar_height , bar_width-2, bar_height);
				else
					g.fillRect(1,1, bar_width-2, bar_height-2);
				break;
		}

		
		g.setColor( border_colour);
		g.draw3DRect(0,0,size.width-1, size.height-1, false);
		
	}
	
	
	//******************************************************************
	public Dimension minimumSize()
	{
		if (orientation == HORIZONTAL)
			return ( new Dimension (100,40));
		else
			return ( new Dimension (40,100));
	}
	
	//******************************************************************
	public Dimension preferredSize()
	{
		return minimumSize();
	}
	
	//******************************************************************
	public void randomize()
	{
		percentage = (int) Math.round(Math.random() * 100.0);
	}
	
	//******************************************************************
	public void increment()
	{
		if (percentage < 100)
		{
			percentage++;
			repaint();
		}
	}

	//******************************************************************
	public void decrement()
	{
		if (percentage > 0)
		{
			percentage--;
			repaint();
		}
	}

	//******************************************************************
	private void horizontal_slats( Graphics g, int width, int height)
	{
		int x = width;
		
		while (x > 1)
		{
			g.fillRect( x-slat_width, 1, slat_width, height-2);
			x -= (slat_width + slat_gap);
		}
	}

	//******************************************************************
	private void vertical_slats( Graphics g, int width, int height, int ymax)
	{
		int y = ymax-height;
		
		while (y < ymax)
		{
			g.fillRect( 1, y, width-2, slat_width);
			y += (slat_width + slat_gap);
		}
	}
	
	
}

file: /Techref/language/java/nosugar/custom/progress/code/ProgressBar.java, 4KB, , updated: 1997/1/22 20:42, local time: 2024/11/26 20:43,
TOP NEW HELP FIND: 
18.191.97.133: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://techref.massmind.org/Techref/language/java/nosugar/custom/progress/code/ProgressBar.java"> language java nosugar custom progress code ProgressBar</A>

Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to techref.massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .