import java.awt.Color; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.Window; public class ScreenCenter { public static final int WIDTH = 5 ; public static final int HEIGHT = 5 ; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub
Window window = new Window(null); window.setBounds((getScreenWidth()-WIDTH)/2, (getScreenHeight()-HEIGHT)/2, WIDTH, HEIGHT); window.setBackground(Color.red); window.setVisible(true); } /** * 得到屏幕的宽度 * @return */ public static int getScreenWidth(){ Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); return (int)dim.getWidth(); } /** * 得到屏幕的高度 * @return */ public static int getScreenHeight(){ Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); return (int)dim.getHeight(); } }问题是怎么让 这个 window 始终在前段显示 显示在穿越火线 游戏之前
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.Window;
public class ScreenCenter {
public static final int WIDTH = 5 ;
public static final int HEIGHT = 5 ;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Window window = new Window(null);
window.setBounds((getScreenWidth()-WIDTH)/2, (getScreenHeight()-HEIGHT)/2, WIDTH, HEIGHT);
window.setBackground(Color.red);
window.setVisible(true);
}
/**
* 得到屏幕的宽度
* @return
*/
public static int getScreenWidth(){
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
return (int)dim.getWidth();
}
/**
* 得到屏幕的高度
* @return
*/
public static int getScreenHeight(){
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
return (int)dim.getHeight();
}
}问题是怎么让 这个 window 始终在前段显示 显示在穿越火线 游戏之前
这个只能 在普通窗口的前段显示 我试过了
但是不能在游戏 前段显示 怎么解决
Thread.sleep(50);
window.toFront();
}
}加上这样一段代码后 能正常显示
但是 游戏会提示我发现 非法模块然后把我T 出去