2023-05-12 23:57
Java程序:
import?java.awt.Graphics;
import?javax.swing.JFrame;
import?javax.swing.JPanel;
public?class?Exercise12_10?extends?JFrame?{
private?static?final?long?serialVersionUID?=?1L;
private?CanvasPanel?pnlCanvas?=?null;
public?Exercise12_10(){
super("Exercise12_10");
pnlCanvas?=?new?CanvasPanel();
this.add(pnlCanvas);
this.setSize(250,?250);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public?static?void?main(String[]?args)?{
new?Exercise12_10();
}
}
class?CanvasPanel?察并蠢extends?JPanel{
private?static?final?long?serialVersionUID?=?1L;
public?void?paint(Graphics?g){
int?W?=?this.getWidth();
int?H?=?this.getHeight();
int?i,?j;
int?width?=?W?/?8;
int?height?=?H?/?8;
int?x,?y;
for(i=0;?i9;?i++){
for(j=0;?j8;?j++){
x?=?j?*?width;
y?=?i?*?height;
if((i+j)%2?==?0){//画矩形
g.drawRect(x,?蔽肆y,?width,?height);
}
else{//填充矩形败陪
g.fillRect(x,?y,?width,?height);
}
}
}
}
}
运行结果如图所示:
这个可以稍微转换岁冲一下思路,歼余只要获取一乎改歼下目标时间,再减去当前时间,获取间隔T
然后再调用 Timer中的schedule 隔T时间运行,一切搞定。
直接老蔽定义两个接口学生接口里面定义一段大个学费的变量,老师接口里面定义一个工资变量,
eclipse里面可以自动帮你添加侍燃州相关变量的getterhe
setter方法的。