简体   繁体   English

屏幕分辨率java代码

[英]Screen resolution java code

I would like to know how to fix the browser resolution for a pc of settings 1280X720 so that the web application developed in java using gwt doesnt looked stretched.I have tried 我想知道如何修复一个设置为1280X720的设备的浏览器分辨率,以便使用gwt在java中开发的Web应用程序看起来没有拉伸。我试过了

int width= windows.getClientWidth();
int height= windows.getClientHeight();
RootPanel.get().setHeight(height   + "px");
RootPanel.get().setWidth(width + "px");

You sure have some main component which is added to the RootPanel . 您确实有一些主要组件添加到RootPanel A DockPanel or LayoutPanel or whatever you use as top component. DockPanelLayoutPanel或您用作顶部组件的任何内容。 Just fix the size of this panel and there you go. 只需修改此面板的大小即可。 RootPanel.get() gives you a handle to the body element, changing the size of a sites body element does not make sense. RootPanel.get()为您提供了body元素的句柄,更改了body元素的大小没有意义。

Ok I was looking into doing something along what you're looking into with a game I've been working on. 好的,我一直在研究你正在研究的东西。 And I found that there is a much better way to handle it. 我发现有一种更好的方法来处理它。 Once you get it worked out it will work with any resolution 一旦你得到它,它将适用于任何分辨率

example, I was trying to display items in an inventory. 例如,我试图在库存中显示项目。 but with using integer values in the x, y for the images they would move around depending on what resolution the user was using. 但是使用x,y中的整数值,它们会根据用户使用的分辨率移动。

so I baselined some x, y values like so 所以我将一些x,y值基准化

g.drawImage(inventory, width - 499, height / 2 - 20, null);
int ixt = width - 499;
int iyt = height / 2 - 20;
g.drawImage(broadsword, ixt + 10, iyt + 10, null);

this way it starts out at the 0,0 of the inventory image, and moves over and down 10 pixels and places the item image. 这样,它从库存图像的0,0开始,并上下移动10个像素并放置项目图像。

so no matter what resolution you'r in, it shows up in the same place every time. 所以无论你处于何种分辨率,它每次都出现在同一个地方。

Hopefully you can work something like that into your program. 希望你可以在你的程序中运行这样的东西。

You can change the browser size with 您可以使用更改浏览器大小

Window.resizeBy(500, 400);

however the window has to be opened with window.open . 但是窗口必须用window.open打开。

http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/Window.html#resizeBy(int , int) http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/Window.html#resizeBy(int,int

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM