易截截图软件、单文件、免安装、纯绿色、仅160KB

Java Timer 对象创建后使用Timer更改其属性!!!

首先来个简单那的实例:
package cn.vicky;
import java.util.Timer;
import java.util.TimerTask;
public class MyTimer {

private int i = 1;

private void change(long time){
System.out.println("one : " + i);
final Timer timer = new Timer();
timer.schedule(new TimerTask(){
@Override
public void run() {
System.out.println("run " + i++);
if (i != 5) {
timer.cancel();
}
}

}, 10000,1);
System.out.println("two : " + i);
}
public static void main(String[] args) {
MyTimer mytimer = new MyTimer();
mytimer.change(0);
}
}

我们以一个实例思考,车站,每辆车只能停靠10分钟就必须出站.传统方式,我们是以车站为单位,通过多线程来控制每辆车的出站情况!
package cn.vicky;
import java.util.Date;
/**
*
* @author Vicky
* 公交汽车
*/
public class Bus {

private String name = "";

private boolean inStation = true;
/**
* 公交汽车在车站中只可能呆10分钟,然后公交就开走,相对于公交车站,公交10分钟后就为空!
*/
public Bus(String carName) {
this.name = carName;
System.out.println(new Date() + " : a car["+ name +"] into the bus station !");
}
public void setInStation(boolean inStation) {
this.inStation = inStation;
}
public boolean isInStation() {
return inStation;
}

public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Bus other = (Bus) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
@Override
public String toString() {
return "Bus [" + name + "] :: " + (inSta


相关文档:

JNA实现Java调用Fortran

在成功实现Java调用C++之后,接下来想到能否通过JNA实现Java调用Fortran,今天试验了一下,还是比较容易的。
网上有一个Java调用F95的例子,但是我考虑不仅要实现F95的调用,还要实现F77的调用,所以费了一些周折。
问题的关键在于F77为过程名自动添加了一个尾部的下划线,所以sub1这个过程,到Java一端,就变成了sub1_, ......

Java解惑3 26在循环中

下面的程序计算了一个循环的迭代次数,并且在该循环终止时将这个计数值打印了出来。那么,它打印的是什么呢?
public class InTheLoop {
public static final int END = Integer.MAX_VALUE;
public static final int START = END - 100;
public static void main(String[] args) {
int count = 0 ......

java 容器类 小结 troy

JAVA的容器---List,Map,Set
Collection
├List
│├LinkedList
│├ArrayList
│└Vector
│ └Stack
└Set
Map
├Hashtable
├HashMap
└WeakHashMap
Collection接口
  Collection是最基本的集合接口,一个Collection代表一组Object,即Collection的元素(Elements)。一些 Collection允许相 ......

Java Native Method[还没来得及翻译]

The goal for this chapter is to introduce you to Java's native methods. If you are new to Java, you may not know what native methods are, and even if you are an experienced Java developer, you may not have had a reason to learn more about native methods. At the conclusion of this chapter you should ......

Java解惑3 31循环者的鬼魂

请提供一个对i的声明,将下面的循环转变为一个无限循环:
while (i != 0) {
i >>>= 1;
}
回想一下,>>>=是对应于无符号右移操作符的赋值操作符。0被从左移入到由移位操作而空出来的位上,即使被移位的负数也是如此。
这个循环比前面三个循环要稍微复杂一点,因为其循环体非空。在其循环题中, ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号