您的位置:首页 > 编程语言 > Java开发

java学习笔记

2016-03-15 18:56 411 查看
方法传参

如果某个方法的参数是基本数据类型,那么传参方式是赋值方式。如果参数是类,那么就相当于C的地址传值

public class hello {

public static void main(String[] args) {
helloi a=new helloi(10);
name(a);
System.out.println(a.m);
}
public static void name(helloi i) {
System.out.println(9);
i.m=42;
}
}
class helloi
{
int m=0;
public helloi(int m) {
this.m=m;
}
}

判断时间先后

/**
* 判断传入时间是否在当前时间之前
*
* @param time
*            传入时间,格式---周:时:分
* @return 传入时间早于当前时间返回false,否则返回true
* @throws IllegalAccessException
*/
public static boolean isAfter(String time) throws IllegalAccessException {

String times[] = time.split(":");
Calendar c = Calendar.getInstance();
if (times.length < 3) {
throw new IllegalAccessException("时间格式不正确:" + time);
}
// 如果传入星期数大于当前星期数,返回true
if (c.get(Calendar.DAY_OF_WEEK) - 1 > Integer.parseInt(times[0])) {
return false;
} else if (c.get(Calendar.DAY_OF_WEEK) - 1 < Integer.parseInt(times[0])) {
return true;
}
if (c.get(Calendar.HOUR_OF_DAY) > Integer.parseInt(times[1])) {
return false;
} else if (c.get(Calendar.HOUR_OF_DAY) < Integer.parseInt(times[1])) {
return true;
}
if (c.get(Calendar.MINUTE) >= Integer.parseInt(times[2])) {
return false;
} else if (c.get(Calendar.MINUTE) < Integer.parseInt(times[2])) {
return true;
}
return true;
}


监听窗口大小改变
this.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
if (ii != null) {
changeSize();
}
 }
});


监听窗口状态改变

this.addWindowStateListener(new WindowStateListener() {
public void windowStateChanged(WindowEvent e) {
int m = e.getNewState();
if (m == JFrame.ICONIFIED) {
KillView.this.setVisible(false);
}
}
});


操作注册表,实现开机启动

/**
* Reg 参数说明 /v 所选项之下要添加或删除的值名 /t RegKey 数据类型(reg_sz字符串) /d 要分配给添加的注册表
* ValueName 的数据 /f 不用提示就强行删除
*/
public void changeStart(boolean isStartAtLogon) throws IOException {
String regKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
String myAppName = "MyApp";
String exePath = "F:\\成果\\自动关机\\定时任务.exe";
Runtime.getRuntime()
.exec("reg " + (isStartAtLogon ? "add " : "delete ") + regKey
+ " /v " + myAppName
+ (isStartAtLogon ? " /t reg_sz /d " + exePath : " /f"));
}


jtable实现文字居中

DefaultTableCellRenderer   r   =   new   DefaultTableCellRenderer();
r.setHorizontalAlignment(JLabel.CENTER);
table.setDefaultRenderer(Object.class,   r);


部分内容为网上找到的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: