首页>代码>毕设 基于java swing的泡泡堂游戏>/H2003032025-泡泡堂网络游戏的设计与实现/Game/src/net/jeson/game/component/CenterShowDialog.java
package net.jeson.game.component; import java.awt.Dialog; import java.awt.Dimension; import java.awt.Frame; import java.awt.Toolkit; import javax.swing.JFrame; /** * 描述:进入参数Dialog,使显示的图形界面显示居中 * */ public class CenterShowDialog { // public CenterShowFrame(Frame frame) { // 若为frame改所有dialog字段为frame public CenterShowDialog(Dialog dialog) {//目标显示为对话框 dialog.setResizable(false);//不准最大化 //Center the window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension dialogSize = dialog.getSize(); if (dialogSize.height > screenSize.height) { dialogSize.height = screenSize.height; } if (dialogSize.width > screenSize.width) { dialogSize.width = screenSize.width; } dialog.setLocation((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2); } public CenterShowDialog(JFrame dialog) {//目标显示为对话框 dialog.setResizable(false);//不准最大化 //Center the window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension dialogSize = dialog.getSize(); if (dialogSize.height > screenSize.height) { dialogSize.height = screenSize.height; } if (dialogSize.width > screenSize.width) { dialogSize.width = screenSize.width; } dialog.setLocation((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2); } public CenterShowDialog(Frame dialog) {//目标显示为对话框 dialog.setResizable(false);//不准最大化 //Center the window Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension dialogSize = dialog.getSize(); if (dialogSize.height > screenSize.height) { dialogSize.height = screenSize.height; } if (dialogSize.width > screenSize.width) { dialogSize.width = screenSize.width; } dialog.setLocation((screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2); } }