How to make a method run 25 times in 1 second?

I have a JPanel that implements Runnable and that has animation on it. I need to update the screen 25 times per second. I have a vague idea that I need to call function run() 25 times a second, but how do I do that? Thank you!!!

Hi how are you ?
I noticed that you have some duke dollars for this questions:)
Here is the answer.
You won't want to call the run method 25 times by the way. Within your run method you can call a method that is going to do the animation 25 times .
Example:
void doAnimation(Graphics g){
for(int i = 0 ; i < 25 ; i++){
g.drawImage(yourimages,x,x);
try{
Thread.sleep(250);//or whatever the interval is
}catch(InterruptedException e){}
g.drawImage(clearscreenimage,x,x);
let me know how that works for you ?
however, the exact timing depends on the monitor being used and the OS being used. it's a bit more involved. but the answer above is a basic one.
stephen

Similar Messages

  • How to make a loop run for specific period of time ?

    hello !
    i'm new to labview and could'nt found how to make a loop run for 2 sec for example, and then to exit.
    Solved!
    Go to Solution.

    Hi Hookso,
    You can do it using the different loops like While loop and For Loop. Roderic has already stated how to do it using a for loop. I have illustrated in the attached vi how to do it using a while loop and Elapsed Time function. Take a look.
    Regards,
    Nitzz
    (Give kudos to good Answers and Mark it as a Solution if your problem is Solved) 
    Attachments:
    Untitled 2.vi ‏36 KB

  • How can I test the running time of a method?

    c.What is the running time of your method smallest, as a function of n, the number of elements in the list? Use big-Oh notation.
    I quoated from a java problem..
    Anyone can tell me how I can test the running time? Thanks ! :D

    it depends on what is in the method. For example a for loop executed n times would have a O(n). A double for loop (each loopp run n times) will have O(n^2). Do this: determine how many times each loop in the method is run. This is the first term in your runtime equation. Do this for all other loops in the method and add them all together. Most other statements that are not iterative should have a constant runtime so O(1). For conditional statements, the runtime depends on the most time consuming portion of the statement. Once all these are added together, take the O(equation) which should just leave the biggest term. i.e. O(5n^2+3n+8) = O(n^2). Hope this helps.
    note: this does not apply to recursive methods

  • How to make a JApplet run in a Browser

    HI ALL:
    Can anyone tell me how to make a JApplet run in a IE.
    I am using JComponents and Visibroker for JAVA ORB for connecting to another ORB's which would in-turn connect to a C++ Server and finally to the SQL Server.
    I am getting a NoclassFoundException whenever I am running my JApplet.
    My code is >>
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    <html>
    <head>
    <meta http-equiv="Content-type" Content="text/html;charset=iso-8859-1">
    <title>
    ORB ISSUE TRACKING SYSTEM
    </title>
    </head>
    <body>
    <Applet
         CODE="file://D:/IssueTrackingSystem/IssueTrackingSystem.class"
         Width=700
         Height=700
         Align=middle
    >
    <param name="CABBASE" value="IssueTest.cab">
    </Applet>
    </Body>
    </Html>
    >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    The Cabase file is a winzip file having all the ORB's compliant classes and my source classes to interact with the ORB Server.
    Help is urgent.
    Regards
    Ritesh

    I have been having exactly the same problems but I was using JDK 1.2.
    I discovred the problem could be resolved by using the Plug-in on navigaor or IE and bingo it was perfect.
    I also discovered that using the AppletViwer would allow me to see the applet. Then I upgraded to JDK1.3 or 2 or whatever it is and nothing.
    I recompiled the classes using the !.3 still nothing. The applet vewer don't work and the plug in don't work.
    I tried to recompile using the oldjavac ( I assume 1.2) and nothing I do will make this JApplet run. Ordinary a�pplets are OK. Applications with swing are OK, but JAPPLets are dead
    I have come to the conclusion SUN has screwed up big time and are frantically scrabbling about looking for a fix. I have reveert to javascript/DHTML as this is both consistent and stable and for considerably less effort and aggravation you can get 90% of the functioonality.

  • How to make a method sleep without affecting the responsiveness of the GUI

    Hi,
    I want to make a method sleep for a few second before executing the rest of its body. Apparently Thread.sleep(10000) doesn't do the job as it makes the GUI non-responsive.
    Any advice would be deeply appreciated.
    Thomas

    Here's an example:
    package tjacobs.ui.ex;
    import java.awt.Color;
    import javax.swing.Icon;
    import javax.swing.JLabel;
    import tjacobs.ui.util.WindowUtilities;
    * @author tjacobs
    public class Blink extends JLabel implements Runnable {
         public static final long DEFAULT_TIME_LENGTH = 1000;
         private long mTimeLength = DEFAULT_TIME_LENGTH;
         private String mLabel;
         private Icon mIcon;a
         public void run() {
              mLabel = getText();
              mIcon = getIcon();
              try {               
                   while (true) {
                        Thread.sleep(mTimeLength);
                        String current = getText();
                        if (current.equals(mLabel)) {
                             setText("");
                             setIcon(null);
                        else {
                             setText(mLabel);
                             setIcon(mIcon);
                        repaint();
              catch (InterruptedException ex) {
                   ex.printStackTrace();
              finally {
                   setText(mLabel);
                   setIcon(mIcon);
         public Blink() {
         public Blink(String arg0) {
              super(arg0);
         public Blink(Icon arg0) {
              super(arg0);
         public Blink(String arg0, int arg1) {
              super(arg0, arg1);
         public Blink(Icon arg0, int arg1) {
              super(arg0, arg1);
         public Blink(String arg0, Icon arg1, int arg2) {
              super(arg0, arg1, arg2);
         public void setBlinkTime(long time) {
              mTimeLength = time;
         public long getBlinkTime() {
              return mTimeLength;
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              Blink b = new Blink("Hello World");
              b.setBackground(Color.RED);
              WindowUtilities.visualize(b);
              b.setFont(b.getFont().deriveFont(24.0f));
              b.run();
    }

  • How to make a job run on a appointed node

    I have a problem. The database is Oracle 10g, RAC, two nodes
    There are some job which run on everyday night. Now, something happened, the job run on Node A can't work as normal, but if run on node B, It will work well.
    so I just want to submit the jobs on Node B, I submited the jobs on Node B, but the jobs always run on Node A.
    I want to know how to make a job run on a appointed node.

    the Job just transfer some procedure to add partitions for some table, to merge the records from some tables to one table and so on.
    the problem is when the job run on Node A, it is very very slow, the procedure would run hours and not success end, but if on Node B it will successfully end in seconds.
    restart the Node A would be a way for the problem, but may it will leave a hidden trouble. I want save the scene to find out the problem
    so can you help me

  • How to make tomcat still running after reboot

    hi all,
    i want ask about how to make tomcat still running after our computer reboot.
    so our server still can serve the the request without we start manualy the tomcat.
    please replies
    thank's before

    *nix or win32 or other?                                                                                                                                                                                                                                           

  • How to make Attribute Change run alignment & Hierarchy changes in Aggregat

    Hello
    I want to understand that How to make Attribute Change run alignment & Hierarchy changes in Aggregate?
    I posted previously the same question but there were not good answers and i was not able to understand clearly .....
    If there is Process chain XXY which makes Attribute change run for Master Data 0SPELLING ?
    Now there is Aggregate TRT which includes :
    0SPELLING , Fiscal Period , Purchase Product, Purchase Category ?
    Now pls answer following question ?
    1) Does the Process Chain XXY which makes only attribute change run alignment for 0SPELLING , Will this process chain automatically do the Change run alignment for 0SPELLING in Aggregate TRT ? YES or NO
    2) If Yes, then we are just suppose to do Roll up for Aggregate TRT after Process chian XXY completes and finish job ?
    3) If No, then what steps are suppose to be DONE so as to make sure that Aggregate TRT has new values and perfect values for 0SPELLING ?
    Please answer and coorect if i have any wrong question....

    for e.g.
    u have 0spelling whicha has attributes x,y and z on day 1 with 10 records
    so do ur aggregates on day1 with same values
    now on day2 u had new values of attributes y,z,s,d and new hierarchies and so u add new records
    with data load u will load the data with version M of modified and is not available for reporting
    If u do attribute change run then this modified version is activated to A i.e. active version .
    It will also do the change run alignment for Aggregate for new attribute values and new hierarchy values for aggregate.
    now in order for this data to be available for reporting u will need to do the roll up of aggregate.....
    if u roll up aggregate before attribute change run , new data is not avaialable for reporting
    if u roll up aggregate after attribute change run, then data is available for reporting
    if u dont roll up aggregate eventhough new data is in dataprovider, still new data will not be available for reporting.
    this is how it works

  • How to make Attribute Change run alignment & Hierarchy changes in Aggregate

    Hello
    I want to understand that How to make Attribute Change run alignment & Hierarchy changes in Aggregate?
    I posted previously the same question but there were not good answers and i was not able to understand clearly .....
    If there is Process chain XXY which makes Attribute change run for Master Data   0SPELLING ?
    Now there is Aggregate TRT which includes :
    0SPELLING , Fiscal Period , Purchase Product, Purchase Category ?
    Now pls answer following question ?
    1) Does the Process Chain XXY which makes only attribute change run alignment for 0SPELLING ,   Will this process chain automatically do the Change run alignment for 0SPELLING in Aggregate TRT ?         YES or NO
    2)  If Yes, then we are just suppose to do Roll up for Aggregate TRT after Process chian XXY  completes and finish job ?
    3) If No, then what steps are suppose to be DONE so as to make sure that  Aggregate TRT has new values and perfect values for  0SPELLING ?
    Please answer and coorect if i have any wrong question....

    for e.g.
    u have 0spelling whicha has attributes x,y and z on day 1 with 10 records
    so do ur aggregates on day1 with same values
    now on day2 u had new values of attributes y,z,s,d and new hierarchies and so u add new records
    with data load u will load the data with version M of modified and is not available for reporting
    If u do attribute change run then this modified version is activated to A i.e. active version .
    It will also do the change run alignment for Aggregate for new attribute values and new hierarchy values for aggregate.
    now in order for this data to be available for reporting u will need to do the roll up of aggregate.....
    if u roll up aggregate before attribute change run , new data is not avaialable for reporting
    if u roll up aggregate after attribute change run, then data is available for reporting
    if u dont roll up aggregate eventhough new data is in dataprovider, still new data will not be available for reporting.
    this is how it works

  • How to make keynote presentation run automatically

    how to make keynote presentation run automatically

    Keynote can enter play mode when the file is opened:
    Inspector > Document > Automatically play on opening

  • How to make mac desktop run faster . It is starting to freeze up in Safari sometimes.

    How to make IMAC desktop run faster.

    Mavericks is the Operating System, while you could call it a program it's the OS. We need to know:
    what year iMac you have including the amount of RAM installed, the capacity of the internal HD and how much is stored on it and under what conditions the computer runs slowly. Please CAREFULLY read Help us to help you on these forums

  • How to instantiate classes at run time with constructors having arguments?

    I have to instantiate some classes in the run-time because they are plugins. The name of the plugin (pluginClassName) comes from a configuration file.
    Currently I am doing this to achieve it:-
    UIPlugin plugin = (UIPlugin)Class.forName(pluginClassName).newInstance();However, there is a disadvantage. I can not pass arguments to the constructor of the plugin.
    public class RainyTheme extends UIPlugin {
      public RainyTheme() {
       // bla bla
      public RainyTheme(int x, int y , int width, int height) {
       // set co-ordinates
       // bla bla
      // bla bla bla bla
    }Now if I want to instantiate this plugin at runtime and at the same time I want to pass the 4 arguments as shown in the second constructor, how can I achieve this?

    I have no experience with JME and the limitations of its API, but looking at the API docs ( http://java.sun.com/javame/reference/apis.jsp ) it seems that there are two main versions, CLDC and CDC, of which CLDC is more limited in its API.
    The Class class does not contain the methods getConstructor(Object[]) or getConstructors() in this version ( http://java.sun.com/javame/reference/apis/jsr139/java/lang/Class.html ), so it seems that if you are using CLDC then there is no way to reflectively call a constructor with parameters. You'd have to find another way to do what you want, such as use the noarg constructor then initialise the instance after construction.

  • How to make this example run on IE ?

    for example below :
    * LunarPhasesRB.java requires the following files:
    *    images/image0.jpg
    *    images/image1.jpg
    *    images/image2.jpg
    *    images/image3.jpg
    *    images/image4.jpg
    *    images/image5.jpg
    *    images/image6.jpg
    *    images/image7.jpg
    * It is a modified version of LunarPhases.java that
    * uses radio buttons instead of a combo box.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.net.URL;
    public class LunarPhasesRB implements ActionListener {
        final static int NUM_IMAGES = 8;
        final static int START_INDEX = 3;
        ImageIcon[] images = new ImageIcon[NUM_IMAGES];
        JPanel mainPanel, selectPanel, displayPanel;
        JLabel phaseIconLabel = null;
        public LunarPhasesRB() {
            //Create the phase selection and display panels.
            selectPanel = new JPanel();
            displayPanel = new JPanel();
            //Add various widgets to the sub panels.
            addWidgets();
            //Create the main panel to contain the two sub panels.
            mainPanel = new JPanel();
            mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
            mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
            //Add the select and display panels to the main panel.
            mainPanel.add(selectPanel);
            mainPanel.add(displayPanel);
         * Get the images and set up the widgets.
        private void addWidgets() {
             * Create a label for displaying the moon phase images and
             * put a border around it.
            phaseIconLabel = new JLabel();
            phaseIconLabel.setHorizontalAlignment(JLabel.CENTER);
            phaseIconLabel.setVerticalAlignment(JLabel.CENTER);
            phaseIconLabel.setVerticalTextPosition(JLabel.CENTER);
            phaseIconLabel.setHorizontalTextPosition(JLabel.CENTER);
            phaseIconLabel.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createLoweredBevelBorder(),
                BorderFactory.createEmptyBorder(5,5,5,5)));
            phaseIconLabel.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createEmptyBorder(0,0,10,0),
                phaseIconLabel.getBorder()));
         //Create radio buttons with lunar phase choices.
         JRadioButton newButton = new JRadioButton("New");
         newButton.setActionCommand("0");
         newButton.setSelected(true);
         JRadioButton waxingCrescentButton =  new JRadioButton("Waxing Crescent");
         waxingCrescentButton.setActionCommand("1");
         JRadioButton firstQuarterButton = new JRadioButton("First Quarter");
         firstQuarterButton.setActionCommand("2");
         JRadioButton waxingGibbousButton = new JRadioButton("Waxing Gibbous");
         waxingGibbousButton.setActionCommand("3");
         JRadioButton fullButton = new JRadioButton("Full");
         fullButton.setActionCommand("4");
         JRadioButton waningGibbousButton = new JRadioButton("Waning Gibbous");
         waningGibbousButton.setActionCommand("5");
         JRadioButton thirdQuarterButton = new JRadioButton("Third Quarter");
         thirdQuarterButton.setActionCommand("6");
         JRadioButton waningCrescentButton = new JRadioButton("Waning Crescent");
         waningCrescentButton.setActionCommand("7");
         // Create a button group and add the radio buttons.
         ButtonGroup group = new ButtonGroup();
         group.add(newButton);
         group.add(waxingCrescentButton);
         group.add(firstQuarterButton);
         group.add(waxingGibbousButton);
         group.add(fullButton);
         group.add(waningGibbousButton);
         group.add(thirdQuarterButton);
         group.add(waningCrescentButton);
            // Display the first image.
            phaseIconLabel.setIcon(new ImageIcon("images/image0.jpg"));
            phaseIconLabel.setText("");
           //Make the radio buttons appear in a center-aligned column.
            selectPanel.setLayout(new BoxLayout(selectPanel, BoxLayout.PAGE_AXIS));
           selectPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
            //Add a border around the select panel.
            selectPanel.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createTitledBorder("Select Phase"),
                BorderFactory.createEmptyBorder(5,5,5,5)));
            //Add a border around the display panel.
            displayPanel.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createTitledBorder("Display Phase"),
                BorderFactory.createEmptyBorder(5,5,5,5)));
            //Add image and moon phases radio buttons to select panel.
            displayPanel.add(phaseIconLabel);
           selectPanel.add(newButton);
           selectPanel.add(waxingCrescentButton);
           selectPanel.add(firstQuarterButton);
           selectPanel.add(waxingGibbousButton);
           selectPanel.add(fullButton);
           selectPanel.add(waningGibbousButton);
           selectPanel.add(thirdQuarterButton);
           selectPanel.add(waningCrescentButton);
            //Listen to events from the radio buttons.
           newButton.addActionListener(this);
           waxingCrescentButton.addActionListener(this);
           firstQuarterButton.addActionListener(this);
           waxingGibbousButton.addActionListener(this);
           fullButton.addActionListener(this);
           waningGibbousButton.addActionListener(this);
           thirdQuarterButton.addActionListener(this);
           waningCrescentButton.addActionListener(this);
        // Load the selected image (lazy image loading).
        public void actionPerformed(ActionEvent event) {
           phaseIconLabel.setIcon(new ImageIcon("images/image"
                                  + event.getActionCommand()
                                  + ".jpg"));
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
        private static void createAndShowGUI() {
            //Create a new instance of LunarPhasesRB.
            LunarPhasesRB phases = new LunarPhasesRB();
            //Create and set up the window.
            JFrame lunarPhasesFrame = new JFrame("Lunar Phases");
            lunarPhasesFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            lunarPhasesFrame.setContentPane(phases.mainPanel);
            //Display the window.
            lunarPhasesFrame.pack();
            lunarPhasesFrame.setVisible(true);
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }i know run above example on command line while i don't how to make run on IE ?
    because mostly people are used to look at sth on IE ?
    so i think it's important to runs javacode on IE .
    who can help me ?
    thanks!

    If you want it to execute inside a web browser then you need to convert it to an applet. Alternatively you can investigate Java Web Start.

  • How can I delete a "Run Time Air" from my mac book pro

    how can I get rid of the "Run Time Air" on my Macbook Pro

    Welcome to the Apple Support Communities
    If you use Snow Leopard, open iTunes, go to iTunes Store in the iTunes sidebar and log out

  • How to design report at run time SSRS

    most of the time we point store procedure or table and then SSRS report designer show us field and we just drag drop those field on to report designer surface. after all we call those report programmatically and pass parameter and report shown on report
    viewer.
    now my company want that customer will customize the report who will see the report. they want to display all the fields in a form and just customer will select each field and place on report designer surface and give some input like filter condition like
    date range or employee id etc and report will be shown. also at run time if customer want they can add text or move existing field etc.
    i do not have any idea how could i do this with SSRS. if this is possible with SSRS then please guide me in such a way as a result i can start the job or if possible give me few relevant url of that kind from where i can get the idea. thanks

    You can also use report builder application to get most of these functionality. For that you'll just create and deploy a report model with required attributes from involved entities.
    Then use can consume the model within report builder and add required fields to report,filter etc
    see below videos for more details
    http://technet.microsoft.com/en-us/sqlserver/dd430326.aspx
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Maybe you are looking for

  • Oracle Application Server 10g thread stuck issue.

    We are having, Oracle Application Server 10g [10.1.3.1 + 10.1.3.4patch] along with Oracle Http Server 2.0 Now there is a issue of thread stuck [some application threads taking longer times] due to which the application server is unable to respond and

  • Corrupted Control Template, toolbar dissapear on SharePoint 2007

    Hi, we are having the following issue. On a site collection, all toolbars have dissapear, like the following, If you reset the webpart, site, it doesn't fix the issue. Any ideas? Thank you

  • Administrative Privilege

    I'm sure I'm missing something, but could anyone tell me exactly where in HTMLDB v 2.1.0.00.05 I would give a user Admin privilege? I seem to remember in an earlier version that when you brought up the user in workspace users, you had a "developer",

  • CC different in Color 1.5 vs FCP7

    When I send a clip from FCP7 to Color 1.5, the color correction on the clip is totally off. They're not even close. When I make a correct the clip in COlor and send it back to FCP it doesn't look anything like what the clip looked like in Color. Is t

  • Myrio how to use public folder

    Hi I have a My-Rio 1900, and i want to grap images from a usb cam, and show it on a web page that myrio will host. first i thout, easy just add a webservice that give you a jpeg picture when request the page. never got that to work, since i realised