반응형
Beep
- java.awt.Toolkit;
- Toolkit을 임포트 받아 사운드를 출력한다.
Beep 예제1
package D11;
import java.awt.Toolkit;
public class BeepEx {
public static void main(String[] args) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
for(int i=0; i<5; i++) {
toolkit.beep();
try {
Thread.sleep(500);
}catch(Exception e) {
}
}
for(int i=0; i<5; i++) {
System.out.println("띵");
try {
Thread.sleep(500);
}catch(Exception e) {
}
}
}
}
Beep 예제2
package D11;
public class BeepEx1 {
public static void main(String[] args) {
Runnable beepTask = new BeepTask();
Thread thrad = new Thread(beepTask);
thrad.start();
for(int i=0; i<5; i++) {
System.out.println("띵");
try {
Thread.sleep(500);
}catch(Exception e) {
}
}
}
}
Beep 예제3
package D11;
import java.awt.Toolkit;
public class BeepEx2 {
public static void main(String[] args) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
for(int i=0; i<5; i++) {
toolkit.beep();
try {
Thread.sleep(500);
}catch(Exception E) {
}
}
}
});
thread.start();
for(int i=0; i<5; i++) {
System.out.println("띵");
try {
Thread.sleep(500);
}catch(Exception e) {
}
}
}
}
Beep 예제4
package D11;
import java.awt.Toolkit;
public class BeepTask implements Runnable{
public void run() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
for(int i=0; i<5; i++) {
toolkit.beep();
try {
Thread.sleep(500);
}catch(Exception e) {
}
}
}
}
반응형
'JAVA' 카테고리의 다른 글
[JAVA] input, output Stream and file input, output (0) | 2023.07.19 |
---|---|
[JAVA] 예외처리(try - catch) (0) | 2023.07.19 |
[JAVA] Thread (0) | 2023.07.19 |
[JAVA] Collection(Map) (0) | 2023.07.19 |
[JAVA] Collection(Stack) (0) | 2023.07.18 |