- 1). Create a new Java class to contain your code. You can easily generate the "main()" method first in order to test the beep generation feature. In the following example, the class is called MainClass containing a single main method:
public class MainClass {
public static void main(String[] args) { ... }
} - 2). Import the java.awt.toolkit package. This package provides the necessary libraries to call the codes to generate the beep sound. You can do this using the "import java.awt.Toolkit;" statement.
- 3). Create an instance of the Toolkit class. The following code will generate the default toolkit object for your system:
Toolkit tk = Toolkit.getDefaultToolkit(); - 4). Use the toolkit object to generate a beep sound. You can do this by calling the "beep()" method:
tk.beep();
SHARE