本文整理汇总了Java中java.awt.Toolkit.getScreenSize方法的典型用法代码示例。如果您正苦于以下问题:Java Toolkit.getScreenSize方法的具体用法?Java Toolkit.getScreenSize怎么用?Java Toolkit.getScreenSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Toolkit
的用法示例。
在下文中一共展示了Toolkit.getScreenSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.awt.Toolkit; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Frame frame = new Frame();
Robot robot = new Robot();
final Toolkit toolkit = Toolkit.getDefaultToolkit();
final GraphicsEnvironment graphicsEnvironment =
GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice graphicsDevice =
graphicsEnvironment.getDefaultScreenDevice();
final Dimension screenSize = toolkit.getScreenSize();
final Insets screenInsets = toolkit.getScreenInsets(
graphicsDevice.getDefaultConfiguration());
final Rectangle availableScreenBounds = new Rectangle(screenSize);
availableScreenBounds.x += screenInsets.left;
availableScreenBounds.y += screenInsets.top;
availableScreenBounds.width -= (screenInsets.left + screenInsets.right);
availableScreenBounds.height -= (screenInsets.top + screenInsets.bottom);
frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,
availableScreenBounds.width, availableScreenBounds.height);
frame.setVisible(true);
robot.waitForIdle();
Rectangle frameBounds = frame.getBounds();
frame.setExtendedState(Frame.MAXIMIZED_BOTH);
robot.waitForIdle();
Rectangle maximizedFrameBounds = frame.getBounds();
frame.dispose();
if (maximizedFrameBounds.width < frameBounds.width
|| maximizedFrameBounds.height < frameBounds.height) {
throw new RuntimeException("Maximized frame is smaller than non maximized");
}
}
示例2: ClientApp
import java.awt.Toolkit; //导入方法依赖的package包/类
public ClientApp() {
imagepanel = new ImagePanel();
// layout UI View
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(imagepanel, BorderLayout.CENTER);
this.getContentPane().add(createMenus(), BorderLayout.NORTH);
// size
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension d = toolkit.getScreenSize();
setSize(d.width-100, d.height - 80);
}
示例3: setLocation
import java.awt.Toolkit; //导入方法依赖的package包/类
/**
*
* @Title: setLocation
* @Description: set component's location
* @param @param c
* @return void
* @throws
*/
public static void setLocation(Component c)
{
int winWidth = c.getWidth();
int winHeight = c.getHeight();
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int screenWidth = screenSize.width;
int screenHeight = screenSize.height;
c.setLocation(screenWidth / 2 - winWidth / 2, screenHeight / 2 - winHeight / 2);
}
示例4: checkConfigs
import java.awt.Toolkit; //导入方法依赖的package包/类
private static GraphicsDevice checkConfigs(GraphicsDevice[] devices) {
GraphicsDevice correctDevice = null;
if (devices.length < 2) {
return correctDevice;
}
Toolkit toolkit = Toolkit.getDefaultToolkit();
Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
int halfScreen = screenBounds.height/2;
for(int i = 0; i < devices.length; i++) {
if(devices[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
GraphicsConfiguration conf =
devices[i].getDefaultConfiguration();
Rectangle bounds = conf.getBounds();
if (bounds.y >= halfScreen) {
// found
correctDevice = devices[i];
break;
}
}
}
return correctDevice;
}
示例5: printScreen
import java.awt.Toolkit; //导入方法依赖的package包/类
/**
* Salva uma imagem .png com o printscreen da tela atual
*
* @param file local a ser salva a imagem
* @return {@code true} para imagem salva. {@code false} para erro ao salvar
* imagem.
*/
public static boolean printScreen(File file) {
try {
Robot robot = new Robot();
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension d = toolkit.getScreenSize();
BufferedImage bi = robot.createScreenCapture(new Rectangle(0, 0, d.width, d.height));
ImageIO.write(bi, "PNG", file);
return true;
} catch (Exception ex) {
return false;
}
}
示例6: getY
import java.awt.Toolkit; //导入方法依赖的package包/类
public int getY(int y) {
int divy = y / 2;
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension dim = kit.getScreenSize();
int height = dim.height / 2;
y = height - divy;
return y;
}
示例7: showCreate
import java.awt.Toolkit; //导入方法依赖的package包/类
/**
* 屏幕中间显示对话窗口
*
* @param i_JDialog
*/
public void showCreate(JDialog i_JDialog)
{
Toolkit v_Toolkit = Toolkit.getDefaultToolkit();
int v_X = (v_Toolkit.getScreenSize().height - i_JDialog.getHeight()) / 2;
int v_Y = (v_Toolkit.getScreenSize().width - i_JDialog.getWidth() ) / 2;
i_JDialog.setLocation(v_Y ,v_X);
i_JDialog.setVisible(true);
}
示例8: getDeviceDimension
import java.awt.Toolkit; //导入方法依赖的package包/类
private Dimension getDeviceDimension() {
Dimension deviceDimension = null;
try {
Toolkit tool = Toolkit.getDefaultToolkit();
deviceDimension = tool.getScreenSize();
} catch (AWTError e) {
System.out.println(CLASS_NAME+": ERROR! "+ e.getMessage());
e.printStackTrace();
}
return deviceDimension;
}
示例9: getBestSize
import java.awt.Toolkit; //导入方法依赖的package包/类
private void getBestSize(){
Toolkit toolkit = Toolkit.getDefaultToolkit();
screenSize = toolkit.getScreenSize();
canvasWidth = GAME_WIDTH*1;
scale = canvasWidth/GAME_WIDTH;
canvasHeight = scale*GAME_HEIGHT;
}
示例10: setHomeLocation
import java.awt.Toolkit; //导入方法依赖的package包/类
private void setHomeLocation()
{
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;
setSize(screenWidth / 3, screenHeight / 3);
setLocation((screenWidth - getWidth()) / 2, (screenHeight - getHeight()) / 2);
}
示例11: getCenterPoint
import java.awt.Toolkit; //导入方法依赖的package包/类
private Point getCenterPoint() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
int x = (screenSize.width - getWidth() - getInsets().left - getInsets().right) / 2;
int y = (screenSize.height - getHeight() - getInsets().top - getInsets().bottom) / 2;
return new Point(x, y);
}
示例12: getX
import java.awt.Toolkit; //导入方法依赖的package包/类
public int getX(int x) {
int divx = x / 2;
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension dim = kit.getScreenSize();
int width = dim.width / 2;
x = width - divx;
return x;
}
示例13: _addPair
import java.awt.Toolkit; //导入方法依赖的package包/类
/** Add a label and a widget to the panel.
* @param name The name of the entry.
* @param label The label.
* @param widget The interactive entry to the right of the label.
* @param entry The object that contains user data.
*/
protected void _addPair(
String name,
JLabel label,
Component widget,
Object entry) {
// Surely there is a better layout manager in swing...
// Note that Box and BoxLayout do not work because they do not
// support gridded layout.
_constraints.gridwidth = 1;
_constraints.insets = _leftPadding;
_grid.setConstraints(label, _constraints);
_entryPanel.add(label);
_constraints.insets = _noPadding;
if (_columns > 1 && ((_entries.size() + 1) % _columns != 0)) {
_constraints.gridwidth = 1;
} else {
_constraints.gridwidth = GridBagConstraints.REMAINDER;
}
_grid.setConstraints(widget, _constraints);
_entryPanel.add(widget);
_entries.put(name, entry);
_labels.put(name, label);
_previous.put(name, getStringValue(name));
Dimension preferredSize = _entryPanel.getPreferredSize();
// Add some slop to the width to take in to account
// the width of the vertical scrollbar.
preferredSize.width += 25;
// Applets seem to need this, see CT/SigmaDelta
_widgetsHeight += widget.getPreferredSize().height;
preferredSize.height = _widgetsHeight;
Toolkit tk = Toolkit.getDefaultToolkit();
if (preferredSize.height > tk.getScreenSize().height) {
// Fudge factor to keep this window smaller than the screen
// height. CGSUnitBase and the Code Generator are good tests.
preferredSize.height = (int) (tk.getScreenSize().height * 0.75);
_entryScrollPane.setPreferredSize(preferredSize);
}
_entryScrollPane.setPreferredSize(preferredSize);
// Call revalidate for the scrollbar.
_entryPanel.revalidate();
}
示例14: setExecutePageLocation
import java.awt.Toolkit; //导入方法依赖的package包/类
private void setExecutePageLocation()
{
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;
setSize(screenWidth / 2, screenHeight / 2);
setLocation((screenWidth - getWidth()) / 2, (screenHeight - getHeight()) / 2);
}
示例15: setHomeLocation
import java.awt.Toolkit; //导入方法依赖的package包/类
private void setHomeLocation()
{
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;
setSize(screenWidth / 3, screenHeight / 3);
setLocation((screenWidth - getWidth())/ 2, (screenHeight - getHeight() )/ 2);
}