How to use 'Wait'/'Delay' in Swing

Hi all,
I want to simulate an interation between two peers,
that exchange information among each other.
The idea is to have a JPanel where JLabel("Text") are
added in a fixed but consecutive intervals. Something like
<Add label>; <Delay/wait a second>;<Add other label>; <Delay>;.....
Is there an easy/simpler way to do this without using
threads?
Does Swing have a simple way to do what I want?
Can you recomend a link for this?
Pls note that I don't want to block my entire application.
Thanks in advance for the help,
Jorge

Here is a link to the Swing tutorial on "How to Use Timers":
http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html
And here is a link to to thread that uses a Timer to 'continuously scroll text':
http://forum.java.sun.com/thread.jsp?forum=57&thread=291161

Similar Messages

  • How to use Transport Delay VI? Please show me some example.

    I want to delay signal with my selection delay time(example:second,period,number of sample). I saw in LabVIEW have,it have three delay function are 1.Transport Delay 2.Delay Value 3.Unit Delay .Now I take look for Transport Delay VI.I think this function can delay signal with specific time which I want.I tested it by use it to delay sine wavefrom(number of sample=1000,sampling rate =1000Hz),for Transport Delay,I set initize=TRUE,Delay=500. I think the result may sine waveform which same shape of original sine waveform but delay 500 sample after it but the result different from my think. Everyone please recommend me,How to use it?Show me some example.Or please tell me how to delay signal.If can not post picture on the board,mail to me.
    [email protected]
    [email protected]

    Hi TOTSAPORN!
    It sounds like you are trying to alter the timing of a waveform. What I would suggest to you is to look at the Waveform palette to explore the different ways of manipulating the waveform datatype. Also, I put together a small example (written in LV 7.1) to delay the waveform graph by 500 samples (500*dt seconds).
    Hope this helps!
    Travis H.
    National Instruments
    Travis H.
    LabVIEW R&D
    National Instruments
    Attachments:
    Waveform Offset.vi ‏64 KB

  • How to use wait/nofity in socket server

    Dear all
    that is one of sample code from a book which's use mutil connection with socket program , but i if it is possible to use wait and nofity to controle client activety by wait and notify in this sample code ?
    some idea hope someone give me a help please
    import java.net.*;
    import java.io.*;
    * Threaded Echo Server, pre-allocation scheme.
    * Each Thread waits in its accept() call for a connection; this synchronizes
    * on the serversocket when calling its accept() method.
    * @author Ian F. Darwin.
    public class EchoServerThreaded2 {
         public static final int ECHOPORT = 7;
         public static final int NUM_THREADS = 4;
         /** Main method, to start the servers. */
         public static void main(String[] av)
              new EchoServerThreaded2(ECHOPORT, NUM_THREADS);
         /** Constructor */
         public EchoServerThreaded2(int port, int numThreads)
              ServerSocket servSock;
              Socket clientSocket;
              try {
                   servSock = new ServerSocket(ECHOPORT);
              } catch(IOException e) {
                   /* Crash the server if IO fails. Something bad has happened */
                   System.err.println("Could not create ServerSocket " + e);
                   System.exit(1);
                   return;     /*NOTREACHED*/
              // Create a series of threads and start them.
              for (int i=0; i<numThreads; i++) {
                   new Thread(new Handler(servSock, i)).start();
         /** A Thread subclass to handle one client conversation. */
         class Handler extends Thread {
              ServerSocket servSock;
              int threadNumber;
              /** Construct a Handler. */
              Handler(ServerSocket s, int i) {
                   super();
                   servSock = s;
                   threadNumber = i;
                   setName("Thread " + threadNumber);
              public void run()
                   /* Wait for a connection. Synchronized on the ServerSocket
                    * while calling its accept() method. */
                   while (true){
                        try {
                             System.out.println( getName() + " waiting");
                             Socket clientSocket;
                             // Wait here for the next connection.
                             synchronized(servSock) {
                                  clientSocket = servSock.accept();
                             System.out.println(getName() + " starting, IP=" +
                                  clientSocket.getInetAddress());
                             DataInputStream is = new DataInputStream(
                                  clientSocket.getInputStream());
                             PrintStream os = new PrintStream(
                                  clientSocket.getOutputStream(), true);
                             String line;
                             while ((line = is.readLine()) != null) {
                                  os.print(line + "\r\n");
                                  os.flush();
                             System.out.println(getName() + " ENDED ");
                             clientSocket.close();
                        } catch (IOException ex) {
                             System.out.println(getName() + ": IO Error on socket " + ex);
                             return;
    }if i add end of my code like this and then the error message indicat that
    java.lang.IllegalMonitorStateException: current thread not owner
    try{
                        clientSocket.wait();
                 }catch(InterruptedException e){
                                              clientSocket.close();
                                              clientSocket.notify();
                                            }

    Why? Closing the socket will cause the client to return from reading the socket with a null or zero or EOFException. You don't need anything else.
    In any case notifying the clientSocket will only wakeup threads in the current JVM that are waiting on it. This mechanism isn't magic, and it can't wake up another JVM.

  • How to use wait for delay

    Hi
    I need to use the sentence wait for delay, somebody has reference on this
    Thank's

    When posting questions remember that only you know what products and versions you are using. You must share this information in order for anyone to offer any valuable answers to your questions.
    That said, you can find information about the "WAIT" function throughout the Oracle documentation and the Internet.
    http://www.google.com/search?q=oracle+wait+function
    You can also create a pause with something like this:
    DBMS_LOCK.SLEEP(1);

  • How can I wait until a Swing.Timer has finished?

    I have a Swing.Timer runing which displays some animated text (more precisely it fades out a text with a delay of 50 until all characters are erased.
    Afterwards a time consuming operation shall begin. How can I achieve that this operation waits to start until the text has been faded out? The time to fade out the text depends on the length of the text, of course.
    So, how can I make the operation waiting until the Timer has finished its work?
    Thanks,
    Dirk

    dirku wrote:
    I have a Swing.Timer runing which displays some animated text (more precisely it fades out a text with a delay of 50 until all characters are erased.
    Afterwards a time consuming operation shall begin. How can I achieve that this operation waits to start until the text has been faded out? The time to fade out the text depends on the length of the text, of course.
    So, how can I make the operation waiting until the Timer has finished its work?I gave you an answer to this with sample code yesterday:
    [http://forum.java.sun.com/thread.jspa?threadID=5294087&messageID=10244564#10244564|http://forum.java.sun.com/thread.jspa?threadID=5294087&messageID=10244564#10244564]
            public void actionPerformed(ActionEvent e)
                if (sb.length() > 0)
                    sb.deleteCharAt(0);
                    label.setText(sb.toString());
                else
                    label.setForeground(color);
                    label.setText(text);
                    Timer timer = (Timer)e.getSource();
                    timer.stop();
                    // ***** start process here ***
            }The timer here continues until a condition is satisfied (here it's where the Stringbuffer that holds the text that is sent to the JLabel is empty). So all you have to do is place any code that needs to happen when the Timer ends in the else block. It's so simple as to be trivial.

  • How to use multiple threads and swing for displaying status/interaction

    I have a Swing-app which have to show progress and allow userinteraction for these tasks:
    * First:
    retrieve a list of IDs(String) from the database (single thread running)
    * Second:
    some work on the id-list and list written to hd (same thread as above)
    * Third:
    retrieve Objects (based on the id-list) from different sources (Multiple Threads are running)
    To show the status I have a JProgressBar (indeterminate while task1&2 running) and
    a JTextArea showing the current status (connect,retrieve list, sort, ...)
    When task3 is starting the JTextArea have to disappear and be replaced by a ScrollPane
    with an array of Labels/TextAreas showing the status of each thread.
    While theses threads are working, the ID-list will be consumed and the JProgressBar
    shows the remaining precentage of the hole progress.
    Everything is working so far (excepts UI :) , the problem(s) I have:
    I need the threads to interacts with the user through the ui. e.g: "Connection to db-xyz lost! reconnect?"
    But I don&#180;t know how to do this correctly.
    I think one way would be to send an event to the ui... but how?
    (the ui must know which thread is calling to unpause it after user answered)
    I know that threads should NOT change the swing(-container) - How do I notify the ui that a thread has a question?
    Since these threads are really time-consuming the UI is not updated frequently,
    how can I increase this? (perhaps using another thread-priority?)
    thanks for help!

    if/when your threads need to interact with the UI, they can create a Runnable & send it to SwingUtilities.invokeLater or invokeAndWait. This Runnable can popup a message to the user, and act on the choice of the user (reconnect, cancel, ...). This action could be something which "unpauses" the task thread.
    You may need to do synchronisation between the code in the Runnable & the Thread to which it is related - so the latter Thread knows when the user has made the choice.

  • How to use/add  transparency to Swing?

    hello
    I just have Finnishing an small Swing Form, I Have menus, Panels, sliders, etc.. How I can make the menus transparents or If i use the JdesktopPane how i can make JInternalFrames transparents??
    someOne have a tutorial or some help??
    Im lost in the JDK Doc.
    Tnks

    component.setOpaque( false )
    is the closest Swing comes to supporting transparency.
    The background of the component will not be painted,
    which means it will inherit the background of its
    parent.--
    Can i control the level of transparency?? How ??
    Tnks

  • How to use wait for event step

    Hi,
    I need to trigger wait for event step for my workflow but I am not able to trigger that .
    Can anyany one of you tell me in detail what are the necessary config.and bindings i need to do for that .
    Also i need to pass data from my report program(where i am triggering the event for the wait activity) to the workflow through event triggering for the wait step.
    Please tell me how can I do that .
    Thanks in advance.
    Anand

    Hi,
    I think you can use the function module "SAP_WAPI_CREATE_EVENT" to trigger an event. Make sure that the instance data is same in both ends. To send data from your report, you can populate the event container using the container related macros.
    Check this link for more information
    http://help.sap.com/saphelp_nw2004s/helpdata/en/c5/e4af4a453d11d189430000e829fbbd/frameset.htm
    Regards
    <i><b>Raja Sekhar</b></i>

  • How to use Wait Screen and Thread?

    Greetings,
    I was wondering If I could ask a question...
    Here it goes:
    How can I use a Wait Screen in a MIDlet so that I can do the Following:
    1.- Create and Open an Http Connection[b[i]](using an Object which extends Thread) in a Form by pressing an OKCommand.
    2 .- Show the Wait Screen Until the Thread Object finishes execution(finishes whatever is inside run() method)
    3.- Finally show the Result(s) of the Connection(bytes obtained from URL) in another Form.
    First of all, Is what I ask even possible? and more importantly...
    Can a Wait Screen actually Detect when a Thread finished execution? so that only when the thread finishes the program proceeds to the next statement?
    Thank you very much in advance!
    Sincerely, your friend,
    Jose

    Thank you very much Sir, I suppose that narrows it down a bit,
    Because I definitely need my applications as standard as possible.
    But good to know there's a way to do it.
    Well, Thank you very much as usual!
    Sincerely,
    Keep up with the fantastic job you do every day!
    God Bless.
    J

  • How to use hardware acceleration in Swing?

    Hi,
    I searched in net and could not find anything clear on hardware acceleration using Swing.
    To use the hardware acceleration, do I need to specify
    -Dsun.java2d.opengl=true ? Is this must?
    Without specifying this, Java 2D calls wont use hardware acceleration?
    Kindly clarify. I could not able to find anything in net for this.
    I am having ATI Radeon AGP card and using Linux as OS. I have installed the ATI driver. Now I need to know how to interact with hardware using Swing.
    Regards,
    fedorabee

    Hi,
    I searched in net and could not find anything clear
    on hardware acceleration using Swing.
    To use the hardware acceleration, do I need to
    specify
    -Dsun.java2d.opengl=true ? Is this must?No. I've never seen that before. My assumption is that you'd do that if you wanted to make sure you're using OpenGL and not DirectX. Swing will make use of 2D hardware acceleration on it's own. Don't specify anything special.

  • How to use wait.for() /wait() commands for MAC? Not working...

    I am trying to run an external application on mac using runtime.exec() and it runs fine but after it runs it suddenly terminates the program. I have a waitFor() command after the runtime.exec() waiting for that program to end. If i comment out the waitFor() then the program terminates by going through the run command. The waitFor() worked fine for PC but doesnt work for MAC... anyone know what i did wrong or alternative way of listening for it? thanks!

    On the PC i have the following:
    Process p = Runtime.getRuntime().exec("C:\\program Files\\QuickTime\\QuickTimePlayer.exe "
    +file.getPath());
    p.waitFor();
    It basically creates a process of QuicktimePlayer and runs the file specified. I then have p.waitFor() used to wait for the user to close the application so i can do listener stuff for it- it worked for PC.
    On Mac
    String b= "open"+ tempFile.getPath();
    Process p= Runtime.getRuntime().exec(b);
    System.out.println("before wait");
    p.waitFor(); .
    System.out.println("app. terminated");
    output:*
    "before wait".
    Program terminates before System.out.println("app. terminated"); but the application (quicktime) starts.
    if I do this:
    String b= "open"+ tempFile.getPath();
    Process p= Runtime.getRuntime().exec(b);
    System.out.println("before wait");
    // p.waitFor(); .
    System.out.println("app. terminated");
    output:*
    before wait
    app.terminated
    program terminates "normally" and I see "app.terminated".
    I used Eclipse so the "red square" turns red when running it and suddenly grays out when the player appears. So to me the program terminated before the p.waitFor(); If i commented out p.waitFor() then the program goes to the System.out statement and everything goes "fine". I tried using thread.wait(), this.wait() p.wait() etc. but i get errors saying they are not owner of the thread.
    hope this helps. thanks

  • How to generate a delayed retriggerable pulse using only one counter with PXI 6070E card

    Hi
    I have a problem in generating a retriggerable delayed pulse with a single counter(triggered through a signal at gate) using PXI 6070E card. VI was developed in NI LabVIEW traditional DAQ Ver.7.1. I have used the "delayed pulse generator config" VI and a "Start counter" & "Stop counter" VIs for the purpose. But there is no output seen at the out terminal of counter. So I introduced a "wait" VI and set it to 1 sec. Now the pulse output appears but some pulses are missing mometarily after every 1 sec interval. (any solution for this)
    I have gone through a few similar requests in the forum but they suggest either to use two counters or to generate a finite pulse train which does'nt fit my application. Moreover PXI 6070E has only 2 counter timers. I am already using one counter to measure the frequency of a pulse train(signal 1). The application requires to generate a delayed retriggerable pulse for every pulse in signal 1. So I have only one counter left.
    Can I measure the frequency of signal 1 by analog means.? so that I can use two counters for pulse generation. (Signal 1 is a TTL signal).
    Request some help.
    Thanks in Advance
    Regards

    A finite pulse train (N_Pulses >= 2) does require the use of 2 counters on most of our older hardware including your 6070E.  If you're just talking about generating a single retriggerable pulse, you would only need one counter.
    Here's an example in Traditional DAQ that shows you how to set a retriggerable pulse generation (it also allows you to adjust the characteristics of the pulse on-the-fly).
    If you're writing a new program, you might consider switching to DAQmx as it supports NI's latest hardware and recent OSes should you ever need to upgrade.  Traditional NI DAQ is no longer in active development.  Here's an example of how to implement a retriggerable pulse generation in DAQmx.  You should take note that you can't use the two drivers to simultaneously talk to the same piece of hardware, although you should be able to go back and forth by resetting the Traditional DAQ driver before switching to DAQmx.
    Best Regards,
    John Passiak

  • How and when to use WAIT parameter in BAPI_TRANSACTION_COMMIT? Help!

    Hi Experts,
       In the BAPI_TRANSACTION_COMMIT function module there is an input parameter "WAIT".
      What is the significance or use of WAIT?
      How do we use it? What values does it take?
      For which case do we use WAIT and for which not?
    KIndly help me understand this.
    Thanks
    Gopal

    Hi,
    This method executes a COMMIT WORK command. It is required for transactions developed externally to the R/3 System  that change data in the R/3 System via BAPI calls.
    When you call BAPIs in your program that change data in the R/3 System, afterwards you must call this method to write the changes to the database.
    The default value of this parameter is SPACE. If the parameter contains the value SPACE or it does not contain a value at all, then a simple COMMIT WORK is executed.
    If the parameter WAIT contains a value other than SPACE, a COMMIT WORK AND WAIT command is executed.
    The result is that the data within a Logical Unit of Work (LUW), changed by one or more BAPIs after the BAPI 'BapiService.TransactionCommit' has been called, is immediately available in the database.
    The following values are possible:
    The command 'COMMIT WORK' is executed - the program does not wait, until COMMIT WORK is completed. When the database is next accessed directly, all the old data may still be able to be read.
    'X'
    The command 'COMMIT WORK AND WAIT' is executed - the program waits until the COMMIT WORK is completed. When the database is next accessed, the updated data is read.
    reference : function module documentation.
    thanx.
    Edited by: Dhanashri Pawar on Sep 18, 2008 6:41 AM

  • How to use the discrete unit delay function with the simulate signal as the input?

    Hi there,
    I want to use the simulate signal as the input. First, i downsample the input with the downsampler.vi. Then I want to feed the output of the downsampled signal to the discrete unit delay block and display the delayed signal on the graph.
    Somehow I can't use the delay block properly, do anyone know how to fix that?T_T
    thanks!!!!
    Ivy
    please see the attachment
    Attachments:
    test.vi ‏164 KB

    Hi nozombie,
    In your VI the Delay VI only delays the measurment for one interation of your simulation loop.  What are the results that you hope to see?
    Regards,
    Mike Altmann
    LabVIEW Platform PSE
    National Instruments

  • How to use no wait in adf

    hi jdev experts,
    am using jdev 11.1.1.5.0 - adfbc-oracle db10g.
    here my code.
    SELECT GlLvlAccountsEO.GLAL_BU,
           GlLvlAccountsEO.GLAL_LVL1,
           GlLvlAccountsEO.GLAL_LVL2,
           GlLvlAccountsEO.GLAL_LVL3,
           GlLvlAccountsEO.GLAL_LVL4,
           GlLvlAccountsEO.GLAL_ACCT,
           GlLvlAccountsEO.GLAL_OPT_TYPE,
           GlLvlAccountsEO.GLAL_CRE_BY,
           GlLvlAccountsEO.GLAL_CRE_DATE,
           GlLvlAccountsEO.GLAL_UPD_BY,
           GlLvlAccountsEO.GLAL_UPD_DATE,
           GlLvlAccountsEO.GLAL_DESC1,
           GlLvlAccountsEO.GLAL_DESC2,
           GlLvlAccountsEO.GLAL_STATUS,
           GlLvlAccountsEO.GLAL_SENT_FLAG,
           GlLvlAccountsEO.GLAL_TITLE_ID,
           GlLvlAccountsEO.GLAL_FBT_PCT,
           GlLvlAccountsEO.GLAL_FBT_CAT,
           GlLvlAccountsEO.GLAL_BUD_FLAG,
           GlLvlAccountsEO.GLAL_PLANT,
           GlLvlAccountsEO.GLAL_CL_ID,
           GlLvlAccountsEO.GLAL_PAR_LVL1,
           GlLvlAccountsEO.GLAL_PAR_LVL2,
           GlLvlAccountsEO.GLAL_PAR_LVL3,
           GlLvlAccountsEO.GLAL_PAR_LVL4,
           GlLvlAccountsEO.GLAL_PAR_ACCT
    FROM GL_LVL_ACCOUNTS GlLvlAccountsEO
    where GlLvlAccountsEO.GLAL_BU = :pbu
    and GlLvlAccountsEO.GLAL_STATUS  IN ('E') for update nowaiterror
    some parenthesis is missing.if i remove the for update nowait means it's perfectly working.
    i know how to use sql statement
    eg:
    select * from dept
    where deptno =10
    for update nowait ;here i can able to understud.
    but,
    In adf why its doesnt supports ah?
    please anyone help me.

    hi john,
    nice to see you here ;)
    in this blog. i read out the how to use for update no wait.
    http://radio-weblogs.com/0118231/stories/2004/03/24/whyDoIGetOraclejborowinconsistentexception.html
    ok. my question is :
    am unable to use the for update no wait statement in query as like as they said.?
    I'll not comment about the use of pessimistic locking like this in a web-based app.ok. am not use pessimistic locking.
    (although I have just implied that there could be some issues - ADF is not Forms).
    ADF is not Forms.
    from this what i understood means.
    some issues - ADF technology
    not in forms technology. are you mean like this. is it so?
    http://jdeveloperfaq.blogspot.com/2010/02/faq-12-how-to-disable-query-wrapping.html could help you
    how does helps me.
    this blogs deals something about advanced stuff operator (union,unionall...)
    i cant your undertud the previous post fully.
    sorry for misunderstanding from your post..
    Edited by: ADF 7 on Jan 30, 2012 12:16 AM

Maybe you are looking for

  • Satellite A660 - touch pad on/off and other buttons don't work

    Dear People on this forum, Recently, around 3 weeks ago i opened up my computer and i cleaned it, took the dust out because it was overheating. around 2 weeks before I noticed that my touch pad is not working and the top buttons are not working, ther

  • Does Time Machine save my songs from itunes?

    I am trying to buy a new MacBook but want to make sure everything important is saved from my Old Mac I backed up everything on Time Machine Using an external hardrive I just want to make sure all of my Itunes songs are backed up as well. Can anyone h

  • Print issues when printing a muse page from internet explorer and opera

    When I try to print a page on my muse site in internet explorer or opera it goes a little crazy.  Everything is huge and thrown all over the place.  When printing the same pages in firefox or safari it is fine.  Any help?

  • MSI NX6600 Diamond VGA

    Hi, I have NX6600 Diamond TD 128E VGA that I just bought. This GVA has vivo future. In ?ts box ?t comes with Svideo cables and in and out cables. My question is whatever I did, I couldn't bring the wiew of  PS2 game consoule on the screen that I conn

  • After closing iTunes 6 it's still hogging CPU

    I had no problems installing the latest iTunes 6 and Quicktime. It all looked as if it was running OK. However I noticed that each time I closed iTunes my PC (P4 2.4ghz/1024Mb RAM/XP Home SP2) was running extremely slow. Using Task Manager, I looked