-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathColorButtonPanel.java
More file actions
79 lines (73 loc) · 2.18 KB
/
ColorButtonPanel.java
File metadata and controls
79 lines (73 loc) · 2.18 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
*
* @author Aman
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class ColorButtonPanel extends JPanel
{
private JPanel colorButtonPanel;
private JButton foreGroundColorBtn,backGroundColorBtn;
private JLabel foreGroundColorLbl,backGroundColorLbl,foreColorLbl,backColorLbl;
private Color foreColor, backColor;
private CanvasPanel canvasPanel;
public ColorButtonPanel(CanvasPanel inCanvasPanel)
{
canvasPanel = inCanvasPanel;
foreGroundColorLbl = new JLabel(" ");
foreGroundColorLbl.setOpaque(true);
foreGroundColorLbl.setBackground(canvasPanel.getForeGroundColor());
foreGroundColorLbl.setBorder(BorderFactory.createLineBorder(Color.BLACK));
backGroundColorLbl = new JLabel(" ");
backGroundColorLbl.setOpaque(true);
backGroundColorLbl.setBackground(canvasPanel.getBackGroundColor());
backGroundColorLbl.setBorder(BorderFactory.createLineBorder(Color.WHITE));
foreGroundColorBtn = new JButton("ForeGroundColor->");
foreGroundColorBtn.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
setForeGroundColor();
}
}
);
backGroundColorBtn = new JButton("BackGroundColor->");
backGroundColorBtn.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
setBackGroundColor();
}
}
);
this.setLayout(new GridLayout(1,4));
this.add(foreGroundColorBtn);
this.add(foreGroundColorLbl);
this.add(backGroundColorBtn);
this.add(backGroundColorLbl);
}
/*----------------------------------------------------------------------------*/
public void setForeGroundColor()
{
foreColor = JColorChooser.showDialog(null,"ForeGround Color",foreColor);
if(foreColor!=null)
{
foreGroundColorLbl.setBackground(foreColor);
canvasPanel.setForeGroundColor(foreColor);
}
}
/*----------------------------------------------------------------------------*/
public void setBackGroundColor()
{
backColor = JColorChooser.showDialog(null,"BackGround Color",backColor);
if(backColor!=null)
{
backGroundColorLbl.setBackground(backColor);
canvasPanel.setBackGroundColor(backColor);
}
}
}