You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
929 B
38 lines
929 B
package flowershop.view;
|
|
|
|
import java.awt.Toolkit;
|
|
import java.awt.event.WindowAdapter;
|
|
import java.awt.event.WindowEvent;
|
|
|
|
import javax.swing.JFrame;
|
|
|
|
public class MyFrame extends JFrame {
|
|
//获得屏幕的宽度
|
|
private double ScreenWidth = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
|
|
//获得屏幕的高度
|
|
private double ScreenHeigth = Toolkit.getDefaultToolkit().getScreenSize().getHeight();
|
|
|
|
public MyFrame(String title,int width,int heigth) {
|
|
super(title);
|
|
|
|
//设置窗口大小
|
|
setSize(width,heigth);
|
|
//计算窗口居中的坐标
|
|
int x = (int)(ScreenWidth - width) / 2;
|
|
int y = (int)(ScreenHeigth - heigth) / 2;
|
|
//设置窗口的位置
|
|
setLocation(x,y);
|
|
|
|
//注册窗口事件
|
|
addWindowListener(new WindowAdapter(){
|
|
|
|
@Override
|
|
public void windowClosing(WindowEvent e) {
|
|
// 退出系统
|
|
System.exit(0);
|
|
}
|
|
|
|
});
|
|
}
|
|
}
|