Blame view

JPAINT/jpaint/ToolBox.java 1.55 KB
933d00ad   rlentieu   add JPaint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  import java.awt.Color;

  import java.awt.Graphics;

  import java.awt.Image;

  import javax.swing.JPanel;

  

  /**

   * ToolBox this is another main component of paint. This holds all the tools and 

   * all the different things can be done.

   **/

  public class ToolBox extends JPanel

  {

  	public static int RANDOMDRAW = 0, ERASER = 1, EYEDROPPER = 2, PENCIL = 3, 

  	SPRAY = 4, LINE = 5, RECTANGLE = 6, OVAL = 7, ROUNDRECTANGLE = 8, 

  	POLYGON = 9, CURVELINE = 10, TEXT = 11, BRUSH = 12, DRAG = 13, FILL = 14,

  	SELECT = 15;

  	public static ToolIcon[] tools;

  	public static int toolSelected;

  	

  	/** Creates a default ToolBox. **/

  	public ToolBox()

  	{

  		// sets the normal settings and calls the run method

  		setLayout(null);

  		setSize(200,300);

  		run();

  	}

  	

  	/** 

  	 * Instantiates the tools and creates them in an array of ToolIcons. Sets

  	 * bounds to them and a graphic and adds them to the screen.

  	 **/

  	public void run()

  	{

  		// instantiates and sets the background to white and then runs through

  		// a loop to go through 16 tools and sets a image to each one and sets 

  		// a location and size for it

  		tools = new ToolIcon[16];

  		setBackground(Color.white);

  		for(int i=0;i<tools.length;i++)

  		{

  			String iconPath = "Images/"+i+".gif";

  			tools[i] = new ToolIcon(iconPath,i);

  			if(i<8)

  				tools[i].setBounds(25,i*25+25,25,25);

  			else

  				tools[i].setBounds(50,(tools.length-i)*25,25,25);

  			add(tools[i]);

  			repaint();

  		}

  		// sets the initial default tool the pencil tool

  		toolSelected = PENCIL;

  		tools[toolSelected].setEnabled(false);

  	}

  }