Java常用代码段 - 未完待续

记录一些自己写项目常用的代码段。


格式化常用日期格式

 

Date date = new Date(System.currentTimeMillis());

DateFormat d3 = DateFormat.getTimeInstance();

messageShow.append("["+d3.format(date)+"]" + msg);

 

使用工具包,设置窗口在屏幕的正中间

 

Toolkit kit = Toolkit.getDefaultToolkit();    

Dimension screenSize = kit.getScreenSize();

width = screenSize.width/2-this.getWidth()/2;

height = screenSize.height/2-this.getHeight()/2;

this.setLocation(width,height);

//注意要放在PACK()或者SETSIZE()之后


 




 

你可能感兴趣的:(java)