Change color with mouse click

I have a textfield that has a red background color. How do i make it white by just clicking the textfield?

See
Component.setBackground
MouseListener / MouseAdapter
java.awt.Color

Similar Messages

  • Change Color on mouse click

    Hi Guys.  I have followed Ned's code from another post, whereby if a text button is clicked, the color will change.  The code is like
    var clicked:Boolean = false;
    var clicked2:Boolean = false;
    btn1.addEventListener(MouseEvent.CLICK, btn1click);
    function btn1click(event:MouseEvent):void {
        clicked = true;
        var newColorTransform:ColorTransform = btn1.transform.colorTransform;
        if(clicked){
        newColorTransform.color = 0xc97f22;
        } else {
        newColorTransform.color = 0x000000;
        btn1.transform.colorTransform = newColorTransform;
        gotoAndStop(5);
    btn2.addEventListener(MouseEvent.CLICK, btn2click);
    function btn2click(event:MouseEvent):void {
        clicked2 = true;
        var newColorTransform:ColorTransform = btn2.transform.colorTransform;
        if(clicked2){
        newColorTransform.color = 0xc97f22;
        } else {
        newColorTransform.color = 0x000000;
        btn2.transform.colorTransform = newColorTransform;
        gotoAndStop(6);
    Now if I click on the first button, it changes color and stays like that, which is perfect.  If I click on btn2, this changes color and stays like it.  The problem is that if btn2 is pressed, it should change color and stay like it (as it is doing), but btn1 should return back to its normal color (black).  I am not sure how to achieve this.
    Any advise appreciated
    Cheers

    When you mention something is from another post it is helpful if you provide a link so that the context of the code offered can be understood. What you choose as a solution might not be the optimum choice.
    Use the following instead:
    var newColorTransform:ColorTransform = new ColorTransform();
    var btns:Array = new Array({btn:btn1, frameNum:5},{btn:btn2, frameNum:6});
    for(var i:uint=0; i< btns.length; i++){
        btns[i].btn.addEventListener(MouseEvent.CLICK, btnclick);
    function btnclick(evt:MouseEvent):void {
        var frameToGoTo:uint;
        for(var i:uint=0; i< btns.length; i++){
            if(evt.currentTarget == btns[i].btn){
                newColorTransform.color = 0xc97f22;
                frameToGoTo = btns[i].frameNum;
            } else {
                newColorTransform.color = 0x000000;
            btns[i].btn.transform.colorTransform = newColorTransform;

  • Different colors on mouse click

    Hi,
    Can anyone tell me know how to change the color of the applet on click of a mouse. Different color for each click.
    Any examples or sample code will be helpful.
    Thanks in advance

    How is this for a start:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Ncolor extends Applet
    public void init()
         addMouseListener(new MouseAdapter()
              public void mousePressed(MouseEvent event)
                   if (getBackground() == Color.red) setBackground(Color.orange);
                      else                       setBackground(Color.red);
    public void paint(Graphics gb)
         gb.drawString("Test",50,50);}
    Noah

  • Problems with mouse clicks..

    Hello.
    i�m having problems with the mouse clicks in a component...
    i have events that occur when a click is given and others when 2 clicks are given, but these events occurs only once a while....it�s not always that they occur...
    can anyone help me with it?? it�s very strange...
    thanx

    How about copy and pasting your mouseClicked or mousePressed methods. Are you sure you know the difference between a click and a press?

  • Firefox 9.0.1 with Flash player not catch keyboard event with mouse click.

    In a flash application, I need select mutil items using shite key and mouse click, it is not working. looks like firefox didn't pass the keyboard even alone with the click event. This happen on Window 7, IE and Chrome have no problem. only FF

    i have the same problem everytime i open a website with flashcontent firefox freezes and i have to kill the flash process to unfreeze the browser the only way i can see a youtube video is in html5 mode.
    Hardware
    Acer aspire 4553
    Turion X2 p520
    3gb of ddr3 ram
    Ati Mobility Radeon 4250

  • ALL SHAPES LAYERS SUDDENLY CHANGED COLOR WITH SOME ACCIDENTALLY USED KEYBOARD SHORT CUT PLEASE HELP

    I was working away in photoshop on an INCREDIBLY important file and suddenly all of my shape layers inverted... there is NOTHING in the history and I have literally tried everything I can think of. this is seriously a crucial issue and i really need this to be fixed. if ANYONE knows anything please help. I'm posting a screenshot of what it looked like and what it looks like now. naturally adobe wont let me call them or do ANYTHING to get immediate help with this absolutely infuriating problem so if someone out there could help that would be great. SERIOUSLY regretting using photoshop, it is so infuriating even after 7 years of using it.
    ^^ this is what the colors looked like
    and VV this is what they look like now. as far as i can tell, its only the shape layers that have changed color. I have tried everything and nothing works.
    roughly, all the yellow turned green and all the red and white turned black? I have no idea. please PLEASE someone help me.

    The colors are present even when  I exported Jpegs from the photoshop file. Gamut warning is off. the difficult thing with screenshots is that the image appears in different colors at different sizes... which is bizzare.. at the full shape, some of the shape layers appear fine as pictured below
    and then when i zoom in this happens

  • Changing Colors with PSE 3

    If you want to change a color of a stripe...say pink, light green, light blue to a totally diferent color scheme can it be done??? I know that you can use the hue sat. and slider but all that does is change the hue of the existing background. I'm doing digital scrapbooking and want to pick up exact color from a photo..I know you use the eyedropper..Is there a way to incorporate that color in a multi background.
    Also is change to target an option in PSE 3?? I know it is in Photoshop. Someone had suggested I try it. Not even sure as to how to use it.

    Terri,
    Here are 2 ways to change color.
    Using Hue/Saturation:
    1. Select the area you want to change.
    2. Enhance>Adjust Color>Hue/Saturation
    3. In the Hue/Saturation dialog box, adjust the Hue slider.
    Optionally adjust the Saturation and Lightness sliders.
    Note: Instead of step 2, you can add a Hue/Satuation adjustment layer. This will enable you to go back later and make further adjustments.
    Using Replace Color:
    1. Enhance>Adjust Color>Replace Color.
    2. In the Replace Color dialog box, use the Eyedropper to select the old color in the image (this color will appear in the Sample box).
    You can also sample with the Eyedropper before invoking Replace Color, in case you want to sample from another image first.
    3. Move the Fuzziness slider until only the old color area is white.
    4. Adjust the Hue slider to get the new color.
    Optionally adjust the Saturation and Lightness sliders.
    Note: Prior to step 1 you might want to roughly select the area to change so that you don't change other areas in step 4. e.g., if you just want to change the red balloon you don't want to also change the red dress!
    Mark

  • Changing JPanel with button click.

    Hi, I have a class call TOC(Table of Content) which contains all the buttons. One class call MainController. All buttons I add an actionListener which the MainController class will handle. Anothe class which is the main one which contain a JPanel.
    When I click on the button in TOC class, it will go through the MainController class and display the respective JPanel associate with the button.
    Now the problem is how do I change the JPanel in the main class with a click on the button in TOC class?
    Please advise. Thanks in advance.

    Not sure what you mean exactly. However,
    Assuming that your view class is a JPanel, when you create your controller,
    ViewPanel view = new ViewPanel();
    MainController controller = new MainController(viewPanel);
    In MainController track a reference to your viewPanel. Also in viewPanel have a method called setCurrentPanel(JPanel panel). then int he controller's action listener
    public void actionPerformed(ActionEvent ev) {
    JPanel pnl = (JPanel) panelMap.get(ev.getSource().getName());
    viewPanel.setCurrentPanel(pnl);
    I am assuming you have a way of mapping each button to the panel it will use, which is what is in the panelMap. The viewPanel can have a CardPanel layout for the panels it displays and its setCurrentPanel, can bring to front/oradd the specified panel.
    Good luck, hope this helps :-)

  • Issues with mouse clicks/jumps after using CleanMyMac App.

    Since using this app. my hitherto slightly slow responding iMac has required multiple mouse clicks and is less/unresponsive.
    Anyone else used this software?
    As yet have not approached CleanMy Mac.
    I have reinstalled Mountain Lion (download) not clean install.
    Any suggestions? Is there a separate app for mouse that I can reload. Im guessing a minor chunk of code was deleted along with rubbish.
    Reg25x

    Uninstall CleanMyMac and do not reinstall it.
    CleanMyMac is one of a broad category of time- and money-wasters capable of causing system corruption that can only be rectified by reinstalling OS X, restoring from a backup, or completely erasing your system and rebuilding it from the ground up. Get rid of it and test your Mac for operation. If it does not perform normally, the possibility that Cleanmymac resulted in system corruption must be considered.
    The vast majority of Mac problems reported on this site are the direct result of having used garbage like that. Never install such junk on a Mac.

  • Firefox stop to work in one time,and i have to restart all because ff dont wor when i try to change page with mouse

    firefox stop to work in one time,and i have to restart all because ff dont wor when i try to change page with mouse

    Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]
    If it does work in Safe-mode then disable all your extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    * Use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    * Close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")

  • Change state with timer as well as with mouse click?

    I would like to set up an image with two states, "State 1" and "State 2"
    I would like the button to toggle between "State 1" and "State 2" onMouseDown.
    But I would also like the button to alternate between "State 1" and "State 2" on its own every 3 seconds.
    Can you tell me how to set this up?

    This should get you started:
    http://www.playingwithfire.com/fun.html

  • Possible to change colors of mouse cursor?

    I was wondering if it was possible to change the color of the mouse cursor. With out the use of a program/haxie.
    Is there a particular file/preference I can edit, some command line for teminal?
    Thanks in advance
    nerd2

    Might try looking here for WebKit ones...
    /System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebCore.framew ork/Versions/A/Resources/<anything>Cursor.png
    Double click for Some info...
    /System/Library/Frameworks/Tk.framework/Versions/8.4/Resources/Documentation/Ref erence/Tk/TkLib/GetCursor.htm
    Not sure what these cursors are for...
    /Volumes/TigerOS9/System/Library/Frameworks/GLUT.framework/Versions/A/Resources/ <anything>Cursor.tiff
    "The default cursor and the wait cursor are stored here: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ CoreGraphics.framework/Versions/A/CoreGraphics. Default Cursor: $23556C - $23766C; Wait Cursor: $23766C - $23D66C"
    http://forums.macnn.com/90/mac-os-x/121657/osx-cursors-location-found/
    And what you didn't want...
    http://www.versiontracker.com/dyn/moreinfo/macosx/18336

  • Character movement with mouse click

    This will be for an MMO online game/ world. So it needs to be good.
    Hi guys. I'm really happy I got this to work as I'm a neebie to AS3 but getting to love its simplicity. My problem is not my AS3 but my maths.
    I click the mouse and the movieclip runs to the mouse's x position. However, it only goes in one direction ie: downwards and to the right.
    I need to it go in all directions depending on where I click. I suppose it has to do with comparing x and y positions of both mouse and mc - ie: if one is bigger than the other then you can tell where both are positioned and then put the code in. Am I right and does anybody hace a little code like this flying around for me?
    import flash.display.Stage;
    import flash.events.Event;
    stage.addEventListener(MouseEvent.CLICK, myClickReaction);
    function myClickReaction (e:MouseEvent):void{
        sunny.gotoAndPlay("runback")
        //sunny.x = root.stage.mouseX
        //sunny.y = root.stage.mouseY
        addEventListener(Event.ENTER_FRAME, onEnterFrame);
    function onEnterFrame(event:Event):void {
                 var xDistance:Number
                 var yDistance:Number
                //mc increments by 5 until it reaches mouse - mc (ie the distance)
                sunny.x += 5;
                sunny.y += 5;
                xDistance = root.stage.mouseX - sunny.x
                trace (xDistance)
                if (xDistance <= 0 ) {
                trace("works")
                sunny.gotoAndPlay("static")
                removeEventListener(Event.ENTER_FRAME, onEnterFrame);

    Thanks for contacting but the code more or less works already apart from the comments below.
    The position I get comparing mousex position and movieclip position. BUT it goes loopy when I move the mouse around. ie: I need the coordinates when I click and not a variable that changes while I move mouse around.
    I will check it out now.
    import flash.display.Stage;
    import flash.events.Event;
    stage.addEventListener(MouseEvent.CLICK, myClickReaction);
    function myClickReaction (e:MouseEvent):void{
    //sunny.x = root.stage.mouseX
    //sunny.y = root.stage.mouseY
    addEventListener(Event.ENTER_FRAME, onEnterFrame);
    function onEnterFrame(event:Event):void {
                 var xDistance:Number
        var yDistance:Number
       //mc increments by 5 until it reaches mouse - mc (ie the distance)
                // if you click to the right of sunny then mouse is > than sunny.x so x = 5
       if (root.stage.mouseX > sunny.x) {
        sunny.gotoAndPlay("walk right")
        sunny.x += 5;
        sunny.y += 0;
        xDistance = root.stage.mouseX - sunny.x
        //if (xDistance <= 0 ) {
        //sunny.gotoAndPlay("static")
        //removeEventListener(Event.ENTER_FRAME, onEnterFrame);

  • Trouble with mouse click

    I used to have a LOGITECH but reverted to the wired APPLE mouse that came with my computer. My problem is when I try to click on a file ONCE to : let's say change a file name or edit a file ...it'll open a file in a program I didn't command it to. A good example are sound files I'll try to edit an audio file name but the single click causes QUICKTIME to open the file and play it...very annoying when you are try to navigate your files. Thanks

    yes but the problem exists even going back to the old mouse with wire. I need to reiterate that the problem didn';t exist in early summer when I was using the LOGITECH mouse only sometime during June I began to notice the trouble and it's there with the (wireless) LOGITECH and/or APPLE mouse (wired USB). Mystery unsolved. Thanks for responding.

  • Change color on mouse over

    Hi, how can i change the color of column heading during mouse over a particular column.?
    Does anyone know any html code for this?

    Hi, how can i change the color of column heading during mouse over a particular column.?
    Does anyone know any html code for this?

Maybe you are looking for

  • How do I get one to one classes at a store other than where I  purchased it?

    I purchased my macbook pro in Cerritos. I live in Fresno. Their schedule for classes so far, is not convenienet. I was told I could take the classes at any store.  But when I try to check alternatives I get a short list of stores all in the L.A. area

  • Can I install iLife, iMovie on external hard drive

    I have a powerbook and way too many photos/video cuts-have run out of hard drive space on my powerbook, have much stored on an extrernal hard drive (LaCie). But can't do much movie editing on the powerbook due to HD space limitations. Can I install i

  • Import issue with Lightroom

    I upgraded to LR5.2 2 weeks ago from 4.3. Install went fine, but I'm now having issues when importing my photos, Lightroom hangs partially through the import.  The only choice I have then is to force quit the program, which then freezes my computer. 

  • Tag Query - History 12.0.2

    Has anyone run into a problem with using the History mode of a Tag Query? I am connected to an IP21 data source.  I can get HistoryEvent data and Current data back, but when I run in History mode, I get a blank HTML.  Running in XML mode, I receive t

  • Who and when di the job get dropped?

    Is there a log of sorts that can tell me who and/or when a job got dropped from the schedule ? I use to see it in my query against user_jobs but now its gone. thanks