[java]代码库
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package calc;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JFrame;
/**
*
* @author xiao
*/
public class Ui {
private Ui() { };
//修改窗体的图标
public static void setFrameIamge(JFrame jf){
//获取工具类对象
Toolkit tk = Toolkit.getDefaultToolkit();
//获取图片
Image i = tk.getImage("src\\resource\\timg.jpg");
jf.setIconImage(i);
}
//设置程序窗体居中
public static void setFrameCenter(JFrame jf) {
//获取工具对象
Toolkit tk = Toolkit.getDefaultToolkit();
//获取屏幕size
Dimension d = tk.getScreenSize();
double screenWidth = d.getWidth();
double screenHeight = d.getHeight();
//获取窗体size
int frameWidth = jf.getWidth();
int frameHeight = jf.getHeight();
//计算实际位置
int Width = ((int)screenWidth + frameWidth)/2;
int Height = ((int)screenWidth + frameHeight)/2;
//设置窗体坐标
jf.setLocation(500,400);
// jf.setLocation(Width,Height);
}
}
初级程序员
by: 慕容雪儿 发表于:2016-11-25 20:14:54 顶(0) | 踩(0) 回复
回复评论