public colours problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: public colours problem

  1. #1
    Join Date
    Mar 2003
    Posts
    1

    public colours problem

    This is probably a really basic question but;

    I need to carry out an assignment statement in my applet which is a colour picker. There is a grid of 12 coloured buttons and when you click one I want it to assign that colour to a public colour named current colour. So then I will be able to set the background or text of something else to whatever the current colour is.

    The way I did it with numbers was to have a

    public int currentnumber at the top and then I used

    if (e.getSource()==b1) currentnumber =1;

    this is what I want to do only instead of numbers to use colours.

    like I said i'm probably missing something really simple but i'd appreciate any help

    thanks in advance

  2. #2
    Join Date
    Mar 2003
    Posts
    84
    post your code, or at least what you have so far.

    use code blocks please.
    I'm surprised more of you people don't get hit by cars.

  3. #3
    Join Date
    Mar 2003
    Posts
    32
    If you want to store which color it is after the user clicks the button as the color name, you could do this... at the beginning of the code declare a string (String colorName) and then when you have the source of the event, instead of saying currentnumber = 1, put colorName = "red":

    if (e.getSource()==b1) colorName = "red";

    When you need to find out what color is chosen later on, you can use the compareTo function, like this:

    if (colorName.compareTo("red") == 0) {
    //The color is red
    }
    else if (colorName.compareTo("blue") {
    //the color is blue
    }

    etc.
    Hope this helps,
    - Master Of Souls
    "Weeks of coding can save hours of planning."


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center