My code on flashing alarm

Hi,
please advise on why is that my code only shows red "omg" than to gray and it stopped.I would like to make it blink red, gray, red, gray, red, gray continuously.
Please give any comments and guide along.Thanks
public class Alarm extends JLabel
   private String text;
    private JLabel label;
    Timer time;
    public Alarm( JLabel label, String text)
       this.label = label;
      this.text=text;
triggerAlarm();
time = new Timer( 1000, new ActionListener() {
                    public void actionPerformed( ActionEvent e ) {
    triggerAlarm();
    trigger2();
time.start();
    public void triggerAlarm(){
       setForeground(Color.RED);
      setText(text);
      repaint();
    public void trigger2(){
         setForeground(Color.gray);
       setText(text);
        repaint();
  public class testAlarm {
public static void main(String[] args){
     String text= "omg";
JLabel test = new JLabel();
    JLabel label = new Alarm(test, text);
      JFrame frame = new JFrame();
       frame.add(label);
      frame.setSize(500,500);
      frame.setVisible(true);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

seah_ly wrote:
public class Alarm extends JLabel
time = new Timer( 1000, new ActionListener() {
                    public void actionPerformed( ActionEvent e ) {
triggerAlarm();
trigger2();
The code above will call trigger2() immediately after triggerAlarm. You're better off flipping a boolean variable between true and false in your timer and then setting the color based on the value of your boolean. Either that or if you want to use more than 2 colors, create a Color[] array and increment a class-level index variable, mod it by the array length and use this as the index to the color array to choose a color from the array, setting your label's text this way. For e.g.,
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class BlinkingLabel {
  private static final Color[] COLORS = {
    Color.gray, Color.red
  private static final int TIMER_DELAY = 300;
  private static int colorIndex = 0;
  private static void createAndShowUI() {
    final JLabel label = new JLabel("My Label", SwingConstants.CENTER);
    Timer time = new Timer(TIMER_DELAY, new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        colorIndex++;
        colorIndex %= COLORS.length;
        label.setForeground(COLORS[colorIndex]);
    time.start();
    JFrame frame = new JFrame("BlinkingLabel");
    frame.getContentPane().add(label);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  public static void main(String[] args) {
    java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
        createAndShowUI();
}

Similar Messages

  • How to connect my app interface with the code in flash builder?

    I'm a beginner and learning my way around actionscript,mxml and flash builder.So this may seem foolish but please bear with me,I'm creating a very simple ios app using flash builder,I have created a simple app interface (A background and a custom navigation bar)using photoshop for my app,now the question is how do i import it into flash builder so that i can connect it with the code i have written? or is there another simpler way to create a app interface using other products like fireworks or catalyst?
    In short, I want to know how is an app interface created(wt software) and how is it connected with its code using flash builder.Any help would be greatly appreciated, and tutorials would be swell
    Thanks!

    Can you use stage.width or stage.stageWidth?

  • How use flex sdk 3.5 Action Script-3 code in flash builder 4.5............???

    hiiiiiiiiiiiiiiiiii
    can i use my flax sdk 3.5 action script-3 code into flash builder 4.5 .....if yes so plz give me detail how??..with step....

    Ya i tried by keeping <fx:Declarations> part but still it is throwing error,
    In flex3 we are making a component ex: <mx:canvas> and changeing that component to
    <cairngorm:ServiceLocator xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:cairngorm="com.adobe.cairngorm.business.*">
    </cairngorm:ServiceLocator>
    if any one used 4.5 with cairngorm let me know
    thanks

  • How to embed html code in flash builder 4 ?

    How to embed html code in flash builder 4 ?

    Ya i tried by keeping <fx:Declarations> part but still it is throwing error,
    In flex3 we are making a component ex: <mx:canvas> and changeing that component to
    <cairngorm:ServiceLocator xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:cairngorm="com.adobe.cairngorm.business.*">
    </cairngorm:ServiceLocator>
    if any one used 4.5 with cairngorm let me know
    thanks

  • Error code 4002 flashes everytime I use itunes?

    Error code 4002 flashes everytime I open my library.  how do I fix It?

    Does this help?
    https://discussions.apple.com/message/19713445#19713445
    tt2

  • I need a Sample Code about flash++.h and swc.

    hi,help me !
    i need a Sample Code about flash++.h and swc.
    my Sample Code bitmapdata.cpp:
    #include <AS3/AS3.h>
    #include <Flash++.h>
    using namespace AS3::ui;
    void gettpoint() __attribute__((used,
    annotate(“as3sig:public function gettpoint(x:Number,y:Number):uint”),
    annotate(“as3package:MyLibrary”)));
    void gettpoint()
    double xx;
    double yy;
    inline_as3( “%0 = x;%1 = y\n” : “=r”(xx) : “r”(yy) );
    flash::geom::Point p=flash::geom::Point::_new();
    AS3_Return(xx);
    int main()
    AS3_GoAsync();
    return 0;
    the compile command is “$(FLASCC)/usr/bin/g++” $(BASE_CFLAGS) -O4 bitmapdata.cpp -emit-swc=MyLibrary -o bitmapdata.swc -lFlash++ -lAS3++
    It took me ten minutes to compile,but it can’t work.why?

    Compiling a SWC using Flash++ will result in poor compiler performance if you are using the Flex SDK to compile that SWC into a SWF.
    To get better performance try using the new version of mxmlc that is shipped in the Adobe Gaming SDK.  (Note that this new version of mxmlc doesn't support Flex)
    You will need to install the Gaming SDK and then extract the archive in the "AIR SDK" folder.  Once that archive is extracted you'll notice the new mxmlc compiler in the bin folder.
    Unfortunately compiling a SWF seems to be a little tricky.  You'll notice in the sample Makefile below project that it changes directory into the bin folder before calling ./mxmlc.  Ideally you wouldn't need to do this (like how it worked with the Flex mxmlc).  I'll investigate why that is the case.
    Makefile:
    # Path to your FlasCC SDK folder
    $?FLASCC=/Users/stshongr/builds/alchemy/1.0.0/sdk
    $?GAMINGSDK="/Applications/Adobe Gaming SDK 1.0/AIR SDK/air3-5_p4_sdk_asc2_mac_112112/bin"
    # The folder the source files are in
    $?SRC_FOLDER=$(PWD)
    all:
              "$(FLASCC)/usr/bin/g++" MyLibrary.c -emit-swc=MyLibrary -o MyLibrary.swc -lFlash++ -lAS3++
              cd $(GAMINGSDK) && ./mxmlc -library-path=$(SRC_FOLDER)/MyLibrary.swc $(SRC_FOLDER)/demo.as -o $(SRC_FOLDER)/demo.swf
    clean:
              rm -f *.swf *.swc *.bc *.exe
    MyLibrary.c:
    #include <AS3/AS3.h>
    #include <Flash++.h>
    using namespace AS3::ui;
    void gettpoint() __attribute__((used,
                                    annotate("as3sig:public function gettpoint(x:Number,y:Number):uint"),
                                    annotate("as3package:MyLibrary")));
    void gettpoint()
        double xx;
        double yy;
        inline_as3( "%0 = x;%1 = y\n" : "=r"(xx) : "r"(yy) );
        flash::geom::Point p=flash::geom::Point::_new();
        AS3_Return(xx);
    int main()
        AS3_GoAsync();   
        return 0;
    demo.as:
    package {
        import flash.display.Sprite;
        import flash.text.TextField;
              import flash.events.Event;
        import MyLibrary.CModule;
        public class demo extends Sprite {
                        private var tf:TextField;
            public function demo() {
                addEventListener(Event.ADDED_TO_STAGE, initCode);
            private function initCode(e:Event):void {
                tf = new TextField();
                addChild(tf);
                // start the FlasCC library
                MyLibrary.CModule.startAsync(this);
                // call the function
                                  tf.appendText("OUTPUT:" + MyLibrary.gettpoint(2,2));

  • Do you need to use Actionscript 3 code in Flash player 9 and above?

    Can anyone tell me if I need to use Actionscript 3 code instead of Actionscript 2 code in the following situation:
    I am running a swf file which is contained in a browser window (all files are contained on a CD and I have a 'trust' file set up to let them play properly).  Up until now, I have been using the following Actionscript 2 code to close the browser window (the Actionscript 2 code is on an 'Exit' button within the swf):
    on (release) {
    getURL("javascript:window.close()");
    This Actionscript 2 code has always worked and still works in Flash player 8 and lower.  However, it does nothing when played using Flash player 9.  Can anyone tell me if Flash player 9 won't recognize Actionscript 2 code?  Is it essential to use ONLY Actionscript 3 code if you are using Flash player 9?
    I am having the same problem when I try to launch another html page containing a swf (popped up from the swf contained in the main html window).  I have the following code on the button to launch the popup html window.  It always worked, but suddenly no longer works with Flash player 9.  Here is the code I am using:
    on (release) {
                getURL("javascript:launchWin2('webpage2.html');");
    I have all the necessary background code to launch 'webpage2.html'.  It works everywhere except in Flash player 9.  Can anyone tell me if it is essential to use Actionscript 3 code ONLY on these buttons in Flash player 9?  I am pretty new to Actionscript 3, so any help with syntax would be appreciated. 
    Please note that I don't want to use the projector.
    Thanks!

    You can use both AS2 and AS3 based applications in both Flash 9 and 10.
    As for the issues you describe - perhaps Flash General Forum is a better bet:
    http://forums.adobe.com/community/flash/flash_general

  • Using Flex Code in Flash

    Hi everyone,
    I really hope you can help me with this. Here's my
    situation...
    I've developed a flex application that connects to another
    java application using "BlazeDS". It works great!! The reason why I
    did this is because I'm developing (along with a Flash designer) a
    website of a music band, and I use java to connect to a database
    that has all the "gigs", news and subscribers to the website.
    Everything works great in Flex, my problem is I'm not a
    designer, I'm a developer. So I wanted to know if there's a way I
    can just give my designer friend a code so he can use it in Flash
    CS3?? (Like to send him objects containing the info. For example,
    give him a concerts object that contains the date and the location
    so he can build the datagrids for the concerts page in Flash)
    I think there must be a way to use Flex libraries in CS3, or
    maybe create some kind of Flex class that will work as a
    "communication interface" between the database and the flash code,
    I'm really not sure...
    In other words, I need to know how can my designer friend use
    (in Flash) what I've developed in Flex.
    Please let me know if there's a way...
    Just in case you need to know, I use Flex's Eclipse plug in
    (it's easier for me this way cause I have java and flex in the same
    place!)
    Thanks!!!!!!

    No need then to use the LocalConnection. In a listener
    function (add a listener function for the complete event of the
    SWFLoader) you can retrieve a reference to the loaded swf and get
    the two values from the swf if they are public and on frame 1 of
    the main timeline.
    private function onSWFLoaded():void
    //retrieve a reference to the loaded swf
    var loadedSWF:MovieClip = logn.content as MovieClip;
    <mx:SWFLoader autoLoad="true" id="logn" source="main.swf"
    horizontalCenter="8" verticalCenter="185" height="364" width="588"
    complete="onSWFLoaded()"></mx:SWFLoader>

  • How can I add advertisement code into flash game?

    hi mates,
    just want to ask about loading advertisement code!
    How do you add the advertisement code (adsense) into flash games??
    my site Funny Games have over 5k games but they are getting from others sites thus I have no original files. How can I add more code into the current files?

    Unless the games were pre-made to allow you to specify some variables in the page code or some external file, you won't be having any luck... you cannot add code to the games unless you have the source files, which you apparently don't have.

  • How to use this example code in Flash AS3?

    Hi,
    How can I use this AS3 code in my Flash CS4 document? The following code is in the below link:
    http://pv3d.org/2009/12/18/tweenmax-tweening-a-timeline-advanced-tweening/#
    Please help.
    Thanks.

    Hi,
    It is working quite nice. I want to use the same code but instead of as "Document Class" I want to put that code in a first key frame of my project. I tried the following but gets an error:
    The error is : 1131: Classes must not be nested.
    And the following code  I tried is:
        import com.greensock.TimelineMax;
        import com.greensock.TweenMax;
        import com.greensock.easing.Linear;
        import com.greensock.easing.Quart;
        import flash.display.Sprite;
         * @author John Lindquist
        [SWF(width="900", height="480", frameRate="31")]
        class EasingATimeline extends Sprite
            private var square:Sprite;
            private static const STEP_DURATION:Number = 1;
            public function EasingATimeline()
                square = new Sprite();
                square.graphics.beginFill(0xcc0000);
                square.graphics.drawRect(0, 0, 50, 50);
                square.graphics.endFill();
                square.x = 100;
                square.y = 50;
                addChild(square);
                //set all the eases of your steps to Linear.easeNone
                var step1:TweenMax = TweenMax.to(square, STEP_DURATION, {x: 700, y: 50, ease: Linear.easeNone});
                var step2:TweenMax = TweenMax.to(square, STEP_DURATION, {x: 700, y: 350, ease: Linear.easeNone});
                var step3:TweenMax = TweenMax.to(square, STEP_DURATION, {x: 100, y: 350, ease: Linear.easeNone});
                var step4:TweenMax = TweenMax.to(square, STEP_DURATION, {x: 100, y: 50, ease: Linear.easeNone});
                var timeline:TimelineMax = new TimelineMax();
                timeline.append(step1);
                timeline.append(step2);
                timeline.append(step3);
                timeline.append(step4);
                //pause your timeline
                timeline.pause();
                //tween your timeline with whatever ease you want
                TweenMax.to(timeline, timeline.totalDuration, {currentTime: timeline.totalDuration, ease: Quart.easeInOut, repeat: -1});
    Please help me to solve this problem.
    Thanks.

  • C7280 Error Code and Flashing Lights

    Hi my C7280 all in one printer keeps turning itself on and all of the lights flash, the error code displayed is B04952C6.
    Can anyone please help or is it beyond repair.
    Many thanks.

    The codes your getting are caused by fatal errors in the firmware of the printer. The printer you have will determine the steps you can try. What printer are you using? I'm sure it's the same one as the original poster, but I need to be sure.
    -------------How do I give Kudos? | How do I mark a post as Solved? --------------------------------------------------------

  • Link File Using Code in Flash Builder

    Is there any way  to link to a file on a local drive rather than a url by using action script in Flash builder? For example is there a type of "file request" instead of "url request"  command I can use?
    Thanks,
    SN

    Hello Susan;
    I don't know if this helps, but I was having code hint issues also, here is the link to the discussion.
    http://forums.adobe.com/thread/553610?tstart=0
    John

  • Problems installing code after flash upgrade

    I just upgraded a 2600 router from 8 MB flash to 16 MB flash (that came from a working 3600). I know for a fact that the firmware for the router with the upgrade is good - I was able to upgrade a different router with no problem. However, with the new flash, the transfer of the code errors out with
    File reception completed.
    TFTP copy: operation terminated due to bad checksum comparison.
    As best as I can tell, the flash is the same between the 2600 and 3600. Please let me know if anyone was able to successfuly do this. Thank you.

    I tftp'd the image for the 2600 into the flash when it was installed in the 3600, stuck the flash into the 2600, and it boots.

  • Help modifying a clock code in flash CS6.

    I have a flash file that has a built in clock.  I would like the clock to function on a 12 hour schedule instead of a 24 hour or military one. 
    Any help would be greatly appreciated! 
    Here is the code:
    onClipEvent (enterFrame) {
                     now = new Date();
    switch (now.getMonth()) {
                    case 0:
                    month = "January";
        break;
      case 1:
        month = "February";
        break;
      case 2:
        month = "March";
        break;
      case 3:
        month = "April";
        break;
      case 4:
        month = "May";
        break;
      case 5:
        month = "June";
        break;
      case 6:
        month = "July";
        break;
      case 7:
        month = "August";
        break;
      case 8:
        month = "September";
        break;
      case 9:
        month = "October";
        break;
      case 10:
        month = "November";
        break;
      case 11:
        month = "December";
        break;
      default:
        trace ("")
    switch (now.getDay()) {
                    case 0:
                    day = "Sunday";
        break;
      case 1:
        day = "Monday";
        break;
      case 2:
        day = "Tuesday";
        break;
      case 3:
        day = "Wednesday";
        break;
      case 4:
        day = "Thursday";
        break;
      case 5:
        day = "Friday";
        break;
      case 6:
        day = "Saturday";
        break;
      default:
        trace ("")
    minutes = now.getMinutes();
    if (minutes <=9 && minutes >=0)
                    minutes = "0"+now.getMinutes();
    seconds = now.getSeconds();
    if (seconds <=9 && seconds >=0)
                    seconds = "0"+now.getSeconds();
    date1 =day  +","+ month +","+ now.getDate();
    date2 =now.getHours() + ":" + minutes;
    Thanks!

    Replace:
    date2 =now.getHours() + ":" + minutes;
    With:
    var hour = now.getHours();
    if(hour == 0){
         hour = 12
    } else if(hour > 12){
         hour -= 12
    date2 =hour + ":" + minutes;

  • Html code in flash

    hi,
    i have the macromedia flash professional 8, and i'm building
    a web site in flash. Although i have some questions:
    1-
    I want to put a counter, a mp3 player and a mailing list code
    that is in HTML code how can i do it?
    example of the code of the counter:
    <!-- Start Bravenet.com Service Code -->
    <script language="JavaScript" type="text/javascript" src="
    http://pub8.bravenet.com/counter/code.php?id=395396&usernum=635540990&cpv=2">
    </script>
    <!-- END DO NOT MODIFY -->
    the other codes are similar to this.
    2-
    I want to put a scroll bar in my flash website how can i do
    it?
    let me know i'm realy newbie.
    thanks a lot

    davidrasta,
    > i have the macromedia flash professional 8, and i'm
    > building a web site in flash.
    Okay.
    > I want to put a counter, a mp3 player and a mailing list
    > code that is in HTML code how can i do it?
    Ah. Well, it's important to realize the difference between a
    browser
    and the Flash Player plug-in. Browsers download files and
    display them
    based on HTML. Most browsers have a JavaScript engine, which
    is required,
    of course, for interpreting JavaScript. In fact, having a
    JavaScript engine
    is a bit like having the Flash Player plug-in: without it,
    you can't
    display media of the relevant sort.
    The Flash Player does not provide a JavaScript engine.
    Flash's language
    is ActionScript. So code like this ...
    > example of the code of the counter:
    >
    > <!-- Start Bravenet.com Service Code -->
    > <script language="JavaScript" type="text/javascript"
    > src="
    http://pub8.bravenet.com/counter/code.php?id=395396&usernum=635540990&cpv=2
    > ">
    > </script>
    ... simply won't run in a Flash movie because there's nothing
    to run it.
    You'll either have to use one of the ActionScript solutions
    for posting
    variables (such as loadVariables() or the LoadVars class) --
    and even that
    may not work, because I'm guessing the bravenet.com PHP form
    returns data
    relevant to JavaScript -- or leave room in your HTML code for
    both a SWF
    file (your Flash movie) and such JavaScript snippets.
    > I want to put a scroll bar in my flash website how
    > can i do it?
    Look in your Components panel and use the ScrollPane
    Component.
    David
    stiller (at) quip (dot) net
    Dev essays:
    http://www.quip.net/blog/
    "Luck is the residue of good design."

Maybe you are looking for

  • Apex Collection- Tabular Form

    Hi is there anyway to make a tabular form depends on apex collections, for example i have a collection named "Orders" and i want to add member to this collection by tabular form , is it possible? Thanks in advance

  • Selection Steps greyed out for a Union Query - OBIEE 11g

    Hello, I did some research and could not find possible solution/explanation for the issue I am facing. For one of the report which is based on Union of 3 queries in OBIEE 11g, I recently added a calculated item which now I would like to remove. The b

  • How do you recommend apps...

    How do I recommend apps to be placed in the U.S. app store. I had owned a copy of the app on one of my older iPod device and now I want to use it again but I cant purchase it.

  • HFM Consolidations using Task Flow Automation

    I have created a task flow that has 5 stages (each stage having a success and a fail link). The first stage is set to consolidate (Impacted) our Actuals scenario for 6 years for 3 entity trees). The 2nd stage consolidates a different scenario for 3 y

  • T61 WinXP won't stay in Standby or Hibernate

    I have a T61 running WinXP that will not stay in Standby or Hibernate modes.  Any time I force the computer to go into Standby or Hibernate, it enters the sleep state then immediately resumes. Here is a list of things I have attempted: - Updated driv