Blame view

JPAINT/jpaint/ColorPanel.java 1.38 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
  import java.awt.HeadlessException;

  import java.awt.event.ActionListener;

  import java.awt.event.ActionEvent;

  import javax.swing.JColorChooser;

  import javax.swing.JDialog;

  import javax.swing.JPanel;

  import javax.swing.JButton;

  

  /**

   * ColorPanel creates a JColorChooser and allows the user to choose a new color 

   * to change with the selected swatch.

   **/

  public class ColorPanel extends JPanel implements ActionListener

  {

  	private JColorChooser jcc;

  	private JDialog jccHolder;

  	

  	/** Creates a default ColorBox. **/

  	public ColorPanel()

  	{

  		// instantiates the JColorChooser and sets it visible.

  		jcc = new JColorChooser();

  		try{

  			jccHolder = jcc.createDialog(this, "Color Panel", false, jcc, this, this);

  		}

  		catch(HeadlessException he){}

  	}

  	

  	/** Sets the JDialog's visible attribute true or false. **/

  	public void setVisible(boolean visible)

  	{

  		jccHolder.setVisible(visible);

  	}	

  	

  	/** Changes the color you selected with the last selected swatch. **/

  	public void actionPerformed(ActionEvent e)

  	{

  		// if the okay button is clicked then change the selected swatch and 

  		// the left mouse click color

  		JButton button = (JButton)e.getSource();

  		if(button.getText() == "OK")

  		{

  			ColorBox.colorPal[ColorBox.selectedSwatchX][ColorBox.selectedSwatchY].setBackground(jcc.getColor());

  			ColorBox.foreGround.setBackground(jcc.getColor());

  		}

  	}

  }