This article describes the method of Java programming to obtain the current screen resolution. Share it for your reference, as follows:
/** * This class implements the functionality of fetching the size of the screen */ package ; /** * @author Leo Share * @since 07/16/2007 * @version 1.0 */ class ScreenSize{ private int screenWidth; private int screenHeight; public void setScreenWidth(int screenWidth){ = screenWidth; } public void setScreenHeight(int screenHeight){ = screenHeight; } public int getScreenWidth(){ setScreenWidth((int)().getScreenSize().width); return screenWidth; } public int getScreenHeight(){ setScreenHeight((int)().getScreenSize().height); return screenHeight; } }
In Java GUI design, it is often necessary to display Frame or Dialog in the center of the screen. You can first obtain the screen resolution and then use the following code to implement it:
int screenWidth = ((int)().getScreenSize().width); int screenHeight = ((int)().getScreenSize().height); JFrame myFrame = new JFrame(); (800, 600)//Set the size of the frame((screenWidth-800)/2, (screenHeight-600)/2);//Set the Frame to display in the center of the screen
PS: Here I recommend an online tool with similar functions for your reference:
Online browser information detection tool:
http://tools./aideddesign/browser_info
For more information about Java algorithms, please check out the topic of this site:Summary of Java mathematical operation skills》、《Java Data Structure and Algorithm Tutorial》、《Summary of Java operating DOM node skills》、《Summary of Java files and directory operation skills"and"Summary of Java cache operation skills》
I hope this article will be helpful to everyone's Java programming.