All pastes #369806 Raw Edit

Someone

public java v1 · immutable
#369806 ·published 2007-02-24 01:52 UTC
rendered paste body
Two classes included in this code---------------------------------------------------------package twotees.desktop.gui;import java.awt.Dimension;import javax.swing.JFrame;import javax.swing.JPanel;import twotees.desktop.gui.widgets.StatusBar;public class TestCase{	public TestCase()	{		JFrame frame = new JFrame("Test Case");		frame.setSize(new Dimension(500, 500));		JPanel pane = new JPanel();		pane.add(new StatusBar(5));		frame.add(pane);		pane.setVisible(true);		frame.setVisible(true);	}		public static void main(String[] args)	{		new TestCase();	}}------------------------------------------------------------------------------package twotees.desktop.gui.widgets;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Image;import java.awt.image.ImageObserver;import java.util.ArrayList;import javax.swing.ImageIcon;import javax.swing.JLabel;/** * Represents a status bar that has a certain number of steps, each of which is completed over time * @author Henri Cook */public class StatusBar extends JLabel implements ImageObserver{	private static final long serialVersionUID = 1L;		private ArrayList<ImageIcon> parts = new ArrayList<ImageIcon>();		public StatusBar (int steps)	{		if (steps < 2) throw new IllegalArgumentException ("Status Bars must have at least two states");				parts.add(new ImageIcon(StatusBar.class.getResource("/images/statusbar-left-filled.jpg").getPath()));				for (int i=1; i<steps-1; i++)		{			parts.add(new ImageIcon(StatusBar.class.getResource("/images/statusbar-middle.jpg").getPath()));		}				parts.add(new ImageIcon(StatusBar.class.getResource("/images/statusbar-right.jpg").getPath()));	}		/**	 * Part of ImageObserver	 */	public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) 	{		// Do nothing		System.out.println("Image update trigger");		return true;	}		public void paintComponent(Graphics g)	{		super.paintComponent(g);		System.out.println("Called");				Graphics2D g2 = (Graphics2D) g;		g2.drawImage(parts.get(0).getImage(), 0, 0, parts.get(0).getIconWidth(), parts.get(0).getIconHeight(), Color.white, this);	}}