importjava.text.*;importjava.awt.*;importjavax.swing.*;importjava.awt.geom.*;importjava.util.*;importjava.awt.event.*;/** ScreenTest.java
*
* Created on 2006年7月6日, 下午5:23
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.*//***
*@authorlbf*/publicclassScreenTestextendsJPanelimplementsRunnable{/**Creates a new instance of ScreenTest*/privateString time;privateRectangle2D rd;privateintx,y,a,b;//座标值和方向值privateintrgb=0;//颜色的值privateColor color;//字体的颜色privateintwidth,height;//屏幕的大小publicScreenTest(intwidth,intheight) {this.width=width;this.height=height;
initWindow();
}privatevoidinitWindow(){
x=(int)(Math.random()*300);
y=(int)(Math.random()*500);
a=1;
b=1;this.setBackground(Color.BLACK);this.setOpaque(true);
rd=newRectangle2D.Double(10,10,101,10);
color=Color.YELLOW;
}privatevoiddoColor(){
rgb=(int)(Math.random()*0xFFFFFF);
color=newColor(rgb);
}publicvoidpaintComponent(Graphics g){
g.setColor(Color.BLACK);
g.fillRect(0,0,width,height);
g.setColor(color);
g.setFont(newFont("楷书",Font.BOLD,150));
FontMetrics fm=g.getFontMetrics();
rd=fm.getStringBounds(time,g);
g.drawString(time,x,(int)(y+rd.getHeight()));
}privatevoiddoTime(){
Calendar cal=Calendar.getInstance();
DateFormat df=DateFormat.getTimeInstance(DateFormat.MEDIUM);
Date date=cal.getTime();
time=df.format(date);
x+=a;
y+=b;doublewidth1=rd.getWidth();doubleheight1=rd.getHeight();
rd.setRect(x,y,width1,height1);if(rd.intersectsLine(width,0,width,height)){
doColor();
a=-1;
}elseif(rd.intersectsLine(0,0,0,height)){
doColor();
a=1;
}elseif(rd.getY()<=-80){
doColor();
b=1;
}elseif(rd.intersectsLine(0,height,width,height)){
doColor();
b=-1;
}
}publicvoidrun(){while(true){try{
Thread.sleep(2);
doTime();
repaint();
}catch(InterruptedException ie){
ie.printStackTrace();
}
}
}publicstaticvoidmain(String arsg[]){
GraphicsDevice gd=GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
DisplayMode dm=gd.getDisplayMode();intwidth=dm.getWidth();intheight=dm.getHeight();
System.out.println("width="+width+"\nheight="+height);
ScreenTest st=newScreenTest(width,height);finalJFrame jf=newJFrame();
jf.getContentPane().add(st,BorderLayout.CENTER);
jf.setUndecorated(true);
gd.setFullScreenWindow(jf);newThread(st).start();
jf.addKeyListener(newKeyAdapter(){publicvoidkeyReleased(KeyEvent ke){if(ke.getKeyCode()==KeyEvent.VK_NUMPAD0)
System.exit(0);
}
});
}
}