⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fourclocks.java

📁 一个JAVA编的一个时钟..不同国家的时钟.还有国家的国旗
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        g.drawLine(xcenter3, ycenter3-1, clockxh3, clockyh3);        g.drawLine(xcenter3-1, ycenter3, clockxh3, clockyh3);//3end                //---------------------------第四个钟-----------------------                g.setColor(handColor4);        g2d.setStroke(new BasicStroke( 4.0f ) );         g.drawArc(xcenter4-55, ycenter4-55, 110, 110, 0, 360);        g2d.setStroke(new BasicStroke( 2.0f ) );         g.setColor(numberColor);        g.drawString("9", xcenter4-45, ycenter4+3);         g.drawString("3", xcenter4+40, ycenter4+3);        g.drawString("12", xcenter4-5, ycenter4-37);        g.drawString("6", xcenter4-3, ycenter4+45);        g.setColor(numberColor);        g.drawString(lastdate4, 175, 420);            g.drawLine(xcenter4, ycenter4, clockxs4, clockys4);        g.setColor(handColor);        g.drawLine(xcenter4, ycenter4-1, clockxm4, clockym4);        g.drawLine(xcenter4-1, ycenter4, clockxm4, clockym4);        g.drawLine(xcenter4, ycenter4-1, clockxh4, clockyh4);        g.drawLine(xcenter4-1, ycenter4, clockxh4, clockyh4);// 4end                //----------------按钮按下后的时间信息-------------------                g.setColor(numberColor);        g.setFont( new Font( "Serif", Font.BOLD, 30 ) );        g.drawString( date, 50, 450 );	}		public void start()	{		timer.start();	}		public void run()	{				try		{			while(true)			{				if(Thread.currentThread()==timer)				{			        int s = 0, m = 10, h = 10;			        			        //------------------------第一个钟----------------------						        currentDate = new Date();			        			        formatter.applyPattern("s");			        try {			            s = Integer.parseInt(formatter.format(currentDate)); //取得秒的数值			        } catch (NumberFormatException n) {			            s = 0;			        }			        formatter.applyPattern("m");			        try {			            m = Integer.parseInt(formatter.format(currentDate)); //取得分钟的数值			        } catch (NumberFormatException n) {			            m = 10;			        }    			        formatter.applyPattern("h");			        try {			            h = Integer.parseInt(formatter.format(currentDate)); //取得小时的数值			        } catch (NumberFormatException n) {			            h = 10;			        }			        clockxs = (int) (Math.cos(s * Math.PI / 30 - Math.PI / 2) * 45 + xcenter);			        clockys = (int) (Math.sin(s * Math.PI / 30 - Math.PI / 2) * 45 + ycenter);//计算秒针除了圆心以外的那点的坐标			        clockxm = (int) (Math.cos(m * Math.PI / 30 - Math.PI / 2) * 40 + xcenter);			        clockym = (int) (Math.sin(m * Math.PI / 30 - Math.PI / 2) * 40 + ycenter);//计算分针除了圆心以外的那点的坐标			        clockxh = (int) (Math.cos((h*30 + m / 2) * Math.PI / 180 - Math.PI / 2) * 30			                   + xcenter);			        clockyh = (int) (Math.sin((h*30 + m / 2) * Math.PI / 180 - Math.PI / 2) * 30			                   + ycenter);													//计算时针除了圆心以外的那点的坐标			    			         //设置时钟下方的数字时钟的格式			        formatter.applyPattern("                             MMM dd日 HH:mm:ss ");			        lastdate = formatter.format(currentDate);			        			        if( datenum == 1 ) //如果按钮要求是此时间 则刷新程序下方的时间信息			        {			        	formatter.applyPattern(" yyyy MMM dd EEE HH:mm:ss "); 			        	date = formatter.format(currentDate);			        }			        			        			        //---------------------------第二个钟----------------------------------			        					formatter2.applyPattern("s");			        try {			            s = Integer.parseInt(formatter2.format(currentDate));			        } catch (NumberFormatException n) {			            s = 0;			        }			        formatter2.applyPattern("m");			        try {			            m = Integer.parseInt(formatter2.format(currentDate));			        } catch (NumberFormatException n) {			            m = 10;			        }    			        formatter2.applyPattern("h");			        try {			            h = Integer.parseInt(formatter2.format(currentDate));			        } catch (NumberFormatException n) {			            h = 10;			        }			    			        // Set position of the ends of the hands			        clockxs2 = (int) (Math.cos(s * Math.PI / 30 - Math.PI / 2) * 45 + xcenter2);			        clockys2 = (int) (Math.sin(s * Math.PI / 30 - Math.PI / 2) * 45 + ycenter2);			        clockxm2 = (int) (Math.cos(m * Math.PI / 30 - Math.PI / 2) * 40 + xcenter2);			        clockym2 = (int) (Math.sin(m * Math.PI / 30 - Math.PI / 2) * 40 + ycenter2);			        clockxh2 = (int) (Math.cos((h*30 + m / 2) * Math.PI / 180 - Math.PI / 2) * 30			                   + xcenter2);			        clockyh2 = (int) (Math.sin((h*30 + m / 2) * Math.PI / 180 - Math.PI / 2) * 30			                   + ycenter2);			    			        // Get the date to print at the bottom			        formatter2.applyPattern("                                                       MMM dd日 HH:mm:ss ");			        lastdate2 = formatter2.format(currentDate);			        			        if( datenum == 2 )			        {			        	formatter2.applyPattern(" yyyy MMM dd EEE HH:mm:ss ");			        	date = formatter2.format(currentDate);			        }			        			        //----------------------------第三个钟------------------------------			        			        formatter3.applyPattern("s");			        try {			            s = Integer.parseInt(formatter3.format(currentDate));			        } catch (NumberFormatException n) {			            s = 0;			        }			        formatter3.applyPattern("m");			        try {			            m = Integer.parseInt(formatter3.format(currentDate));			        } catch (NumberFormatException n) {			            m = 10;			        }    			        formatter3.applyPattern("h");			        try {			            h = Integer.parseInt(formatter3.format(currentDate));			        } catch (NumberFormatException n) {			            h = 10;			        }			    			        // Set position of the ends of the hands			        clockxs3 = (int) (Math.cos(s * Math.PI / 30 - Math.PI / 2) * 45 + xcenter3);			        clockys3 = (int) (Math.sin(s * Math.PI / 30 - Math.PI / 2) * 45 + ycenter3);			        clockxm3 = (int) (Math.cos(m * Math.PI / 30 - Math.PI / 2) * 40 + xcenter3);			        clockym3 = (int) (Math.sin(m * Math.PI / 30 - Math.PI / 2) * 40 + ycenter3);			        clockxh3 = (int) (Math.cos((h*30 + m / 2) * Math.PI / 180 - Math.PI / 2) * 30			                   + xcenter3);			        clockyh3 = (int) (Math.sin((h*30 + m / 2) * Math.PI / 180 - Math.PI / 2) * 30			                   + ycenter3);			    			        // Get the date to print at the bottom			        formatter3.applyPattern("                                 MMM dd日 HH:mm:ss ");			        lastdate3 = formatter3.format(currentDate);			        			        if( datenum == 3 )			        {			        	formatter3.applyPattern(" yyyy MMM dd EEE HH:mm:ss ");			        	date = formatter3.format(currentDate);			        }			        			        //----------------------------------第四个钟---------------------			        			        formatter4.applyPattern("s");			        try {			            s = Integer.parseInt(formatter4.format(currentDate));			        } catch (NumberFormatException n) {			            s = 0;			        }			        formatter4.applyPattern("m");			        try {			            m = Integer.parseInt(formatter4.format(currentDate));			        } catch (NumberFormatException n) {			            m = 10;			        }    			        formatter4.applyPattern("h");			        try {			            h = Integer.parseInt(formatter4.format(currentDate));			        } catch (NumberFormatException n) {			            h = 10;			        }			    			        // Set position of the ends of the hands			        clockxs4 = (int) (Math.cos(s * Math.PI / 30 - Math.PI / 2) * 45 + xcenter4);			        clockys4 = (int) (Math.sin(s * Math.PI / 30 - Math.PI / 2) * 45 + ycenter4);			        clockxm4 = (int) (Math.cos(m * Math.PI / 30 - Math.PI / 2) * 40 + xcenter4);			        clockym4 = (int) (Math.sin(m * Math.PI / 30 - Math.PI / 2) * 40 + ycenter4);			        clockxh4 = (int) (Math.cos((h*30 + m / 2) * Math.PI / 180 - Math.PI / 2) * 30			                   + xcenter4);			        clockyh4 = (int) (Math.sin((h*30 + m / 2) * Math.PI / 180 - Math.PI / 2) * 30			                   + ycenter4);			    			        // Get the date to print at the bottom			        formatter4.applyPattern("                                                        MMM dd日 HH:mm:ss ");			        lastdate4 = formatter4.format(currentDate);			        			        if( datenum == 4 )			        {			        	formatter4.applyPattern(" yyyy MMM dd EEE HH:mm:ss ");			        	date = formatter4.format(currentDate);			        }			        			        currentDate = null;										repaint();//重画										Thread.sleep( 1000 );//延迟一秒				}				}		}		catch(InterruptedException e){}	}		public static void main(String args[])	{		FourClocks c = new FourClocks();				c.start();	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -