#sound
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
import java.awt.Toolkit;
public class Main {
public static void main(String[] args) {
Toolkit.getDefaultToolkit().beep();
}
}
Detected code, here are some useful tools:
import java.awt.Toolkit;
public class Main {
public static void main(String[] args) {
Toolkit.getDefaultToolkit().beep();
}
}
The program might close before it gets the chance to. Try adding a Thread.sleep call afterwards and see if that works
import java.awt.Toolkit;
public class Main {
public static void main(String[] args) {
Thread thread = new Thread(() -> {
Toolkit.getDefaultToolkit().beep();
});
thread.start();
}
}```
Detected code, here are some useful tools:
import java.awt.Toolkit;
public class Main {
public static void main(String[] args) {
Thread thread = new Thread(() -> {
Toolkit.getDefaultToolkit().beep();
}
);
thread.start();
}
}
Is that so?
import java.awt.Toolkit;
public class Main {
public static void main(String[] args) {
Thread thread = new Thread(() -> {
Toolkit.getDefaultToolkit().beep();
});
try {
thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Detected code, here are some useful tools:
import java.awt.Toolkit;
public class Main {
public static void main(String[] args) {
Thread thread = new Thread(() -> {
Toolkit.getDefaultToolkit().beep();
}
);
try {
thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
?
Don't create a thread
How do I use thread.sleep without creating a thread?
By just calling it?
.
Yes?
anyway
Your main method also runs on a thread
so you can make it sleep
I'm sorry, I'm not British, I'm translating what you said from translation, and the translation makes a lot of ridiculous meanings, I wonder if you can just throw the code?
Thread.sleep(1000)
Just do that
public class Main {
public static void main(String[] args) throws InterruptedException {
Toolkit.getDefaultToolkit().beep();
Thread.sleep(1000);
}
}
Detected code, here are some useful tools:
import java.awt.Toolkit;
public class Main {
public static void main(String[] args) throws InterruptedException {
Toolkit.getDefaultToolkit().beep();
Thread.sleep(1000);
}
}
then it's probably a setting in your operating system
e.g. I see here from an old stackoverflow post that windows sounds needs to be on for this to work
thank you