Re: how to use rgb color?
Hi,
U can set a color to graphics object as below:
g2obj.setColor(Color.blue);
You can also create your own color objects:
1. Color ( int red, int green, int blue)
parameter values between 0 and 255
2. Color ( int red, int green, int blue , int alpha )
4th parameter transparency measure
0 - transparent
255 - opaque
also exist with float parameters…….
3. Color ( float red, float green, float blue)
4. Color ( float red, float green, float blue , float alpha )
parameter values between 0.0 and 1.0
After deciding upon the sequence of colors, Use MouseMotionListener and change color
Re: how to use rgb color?
You can get the the device context of the dialog and OnLButtonDown do as shown in the code snippet ..
void CKeyboardcaptureDlg::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
char lschar;
lschar = char(nChar); //Get the Key Up character
CClientDC dc(this); //Get the device context for this dialog
CRect rc;
GetWindowRect(&rc);
ScreenToClient(&rc);
if(lschar == 'R')
{
dc.FillSolidRect(rc,RGB(200,4,56));
}
if(lschar == 'T')
{
//CString strText = "Hello world";
//dc.DrawText(strText ,rc,DT_MODIFYSTRING);
dc.FillSolidRect(rc,RGB(0,4,244));
}
CDialog::OnKeyUp(nChar, nRepCnt, nFlags);
}
Re: how to use rgb color?
To generate random colors everytime. Use Math.random()*255
Give the below code in mousePressed()
int r=(int)(Math.random()*255);
int g=(int)(Math.random()*255);
int b=(int)(Math.random()*255);
Color c=new Color(r,g,b);
gr.setColor(c);
gr.fillRect(50,50,100,100);
Let me know, if you still have problem.
-pkalp