1

i'm new in java programming language. I want to do some code after the application is opened for one minute. Please, how do i do this?

Hello, thanks for all that helped me! I will be more detailed now. What I want to do is a Bukkit plugin which after one minute, and if the player dropped something, the console displays an information message, like "Players are moving", but I just can make the first message appear: "Player dropped something" and I think that the error is on the boolean that I used. Please, can anyone help me with bukkit? This is my code:

public class HgCake extends JavaPlugin implements Listener{
boolean reference = false;
@Override
public void onEnable() {
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
}

@EventHandler
public void onDropItem (PlayerDropItemEvent e) {
    getLogger().info("Player dropped something");
    reference = true;

}

    public void onPlayerMove (PlayerMoveEvent e){
        if (reference = true){
            getLogger().info("Players are moving");


        }

}
 }
PinguCraft
  • 39
  • 1
  • 3
  • 3
    Welcome to StackOverflow! It looks like you want us to write some code for you. While many users are willing to produce code for a coder in distress, they usually only help when the poster has already tried to solve the problem on their own. A good way to demonstrate this effort is to include the code you've written so far, example input (if there is any), the expected output, and the output you actually get (console output, stack traces, compiler errors - whatever is applicable). The more detail you provide, the more answers you are likely to receive. – Henry Keiter Sep 10 '13 at 22:58
  • 1
    @HenryKeiter yet there are three answers, none of which are code. quite possible the asker is looking for the name of a library function rather than code – necromancer Sep 10 '13 at 23:00
  • @progenhard completely **freezing** a thread might not be an option (compared to scheduling), especially in swing applications – om-nom-nom Sep 10 '13 at 23:00

2 Answers2

2

One way is to use some type of Timer. If this is a Swing GUI then a Swing Timer (javax.swing.Timer), or if not, then a Utilities Timer (java.util.Timer) or a ScheduledThreadPoolExecutor.

Note that for more specific and "helpful" help, you will want to post what you've tried, including the pertinent code; explain how it isn't working, including showing all errors and exceptions; and then ask in as much detail as necessary very specific questions about just what it is you don't understand.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
1

Use the java.util.concurrent.ScheduledExecutorService see example within the documentation.

java.util.Timer is a simpler solution

necromancer
  • 23,916
  • 22
  • 68
  • 115