用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

时钟

2012-09-16 作者: 牛牛举报

[java]代码库

	
	import java.awt.BorderLayout; 
	import java.awt.Graphics; 
	import java.util.Calendar; 
	  
	import javax.swing.JApplet; 
	import javax.swing.JPanel; 
	  
	public class JApplet_Clock extends JApplet implements Runnable { 
	  
	    /** 
	     *  
	     */
	    private static final long serialVersionUID = 1L; 
	    private JPanel jContentPane=null; 
	    private Thread thread=null; 
	    private int hour; 
	    private int minute; 
	    private int second; 
	    @Override
	    public void start() { 
	        // TODO Auto-generated method stub 
	        super.start(); 
	        if(this.thread==null){ 
	            this.thread=new Thread(this); 
	            this.thread.start(); 
	        } 
	    } 
	  
	    @Override
	    public void paint(Graphics arg0) { 
	        // TODO Auto-generated method stub 
	        super.paint(arg0); 
	        int x,y,r=80; 
	        arg0.fillOval(94, 94, 12, 12); 
	        for(int i=0;i<60;i++){ 
	            x=(int) (100+r*Math.sin(Math.PI/30*i)); 
	            y=(int) (100-r*Math.cos(Math.PI/30*i)); 
	            if(i%5==0){ 
	                arg0.fillOval(x-5, y-5, 10, 10); 
	            } 
	            else{ 
	                arg0.fillOval(x-1, y-1, 2, 2); 
	            } 
	        } 
	          
	          
	    } 
	  
	
	    @Override
	    public void run() { 
	        // TODO Auto-generated method stub 
	        Graphics g=this.jContentPane.getGraphics(); 
	        while(true){ 
	            this.play(this.getCodeBase(), "1"); 
	            g.setColor(this.jContentPane.getBackground()); 
	            drawHMS(g); 
	            Calendar c=Calendar.getInstance(); 
	            hour=c.get(Calendar.HOUR); 
	            minute=c.get(Calendar.MINUTE); 
	            second=c.get(Calendar.SECOND); 
	              
	            //String str; 
	            //str=hour+":"+minute+"" 
	            g.setColor(this.jContentPane.getForeground()); 
	            drawHMS(g); 
	            g.fillOval(94, 94, 12, 12); 
	            try{ 
	                Thread.sleep(1000); 
	            }catch(InterruptedException e){ 
	                e.printStackTrace(); 
	            } 
	              
	        } 
	  
	    } 
	  
	    private void drawHMS(Graphics g) { 
	        int x; 
	        int y; 
	        double cita; 
	          
	        cita=(hour+minute/60.0+second/3600.0)/12*2*Math.PI; 
	        x=(int)(100+55*Math.sin(cita)); 
	        y=(int)(100-55*Math.cos(cita)); 
	        g.drawLine(100, 100, x, y); 
	          
	        cita=(hour+minute/60.0)/60.0*2*Math.PI; 
	        x=(int)(100+68*Math.sin(cita)); 
	        y=(int)(100-68*Math.cos(cita)); 
	        g.drawLine(100, 100, x, y); 
	          
	        cita=second/60.0*2*Math.PI; 
	        x=(int)(100+72*Math.sin(cita)); 
	        y=(int)(100-72*Math.cos(cita)); 
	        g.drawLine(100, 100, x, y); 
	    } 
	    public JApplet_Clock(){ 
	        super(); 
	    } 
	    public void init(){ 
	        this.setSize(300, 200); 
	        this.setContentPane(getJContentPane()); 
	          
	    } 
	    private JPanel getJContentPane(){ 
	        if(jContentPane==null){ 
	            jContentPane=new JPanel(); 
	                  
	            jContentPane.setLayout(new BorderLayout()); 
	        } 
	        return jContentPane; 
	          
	    } 
	  
	}


[代码运行效果截图]


时钟


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...