We can use java.awt.Toolkit to communicate with the native toolkit system.
The Toolkit class provides a static getDefaultToolkit() factory method to get the toolkit object.
The Toolkit class contains useful methods to work with screen size and resolution, get access to the system clipboard, and to make a beeping sound, etc.
The following table lists a few of the methods of the Toolkit class.
ID | Method/Description |
---|---|
1 | abstract void beep() Makes a beeping sound. |
2 | static Toolkit getDefaultToolkit() Returns the current Toolkit instance used in the application. |
3 | int getScreenResolution() Returns the screen resolution in terms of dots per inch. |
4 | Dimension getScreenSize() Returns a Dimension object that contains the width and the height of the screen in pixels. |
5 | Clipboard getSystemClipboard() Returns an instance of the Clipboard class that represents a system clipboard. |
import java.awt.Dimension; import java.awt.Toolkit; public class Main { public static void main(String[] argv) throws Exception { Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); System.out.println(dim); } }
The code above generates the following result.