真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

包含時(shí)鐘系統(tǒng)java源代碼的詞條

怎樣用java 程序?qū)懸粋€(gè)時(shí)鐘程序

面向?qū)ο笏枷雽懗桑?/p>

巧家網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)建站,巧家網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為巧家數(shù)千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的巧家做網(wǎng)站的公司定做!

下面是一個(gè)顯示器類

public?class?Display?{

private?int?value;//現(xiàn)在的值

private?int?limit;//上限值

Display(?int?limit)?{

this.limit?=?limit;

}

public?void?increase()?{

value++;

if(value?==?limit)?{

value?=?0;

}

}

public?int?getValue()?{

return?value;

}

public?static?void?main(String[]?args)?{

Display?d?=?new?Display(24);

for(;;)?{

d.increase();

System.out.println(d.getValue());

}

}

}

下面創(chuàng)建一個(gè)時(shí)鐘對(duì)象:

public?class?Clock?{

private?Display?h?=?new?Display(24);

private?Display?min?=?new?Display(60);

private?Display?s?=?new?Display(60);

public?void?start?()?{

for(;;)?{

s.increase();

if(s.getValue()?==?0){//如果分重置,小時(shí)+1

min.increase();

if(min.getValue()?==?0){//如果分重置,小時(shí)+1

h.increase();

}

}

System.out.printf("%02d:%02d:%02d\n",h.getValue(),?min.getValue(),s.getValue());//格式輸出

}

}

public?static?void?main(String[]?args)?{

Clock?clock?=?new?Clock();

clock.start();

}

java程序 時(shí)鐘 整點(diǎn)報(bào)時(shí)代碼

import java.awt.*;

import java.util.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.Timer;

public class Test extends JFrame implements ActionListener{

Timer t=new Timer(1000,this);

GregorianCalendar calendar=new GregorianCalendar();

JLabel label1=new JLabel(new Date().toString()),

label2=new JLabel("

");

public Test(){

super("TIME");

Container c=this.getContentPane();

c.setLayout(new FlowLayout());

c.add(label1);c.add(label2);

t.start();

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setBounds(200,200,200,100);

this.setVisible(true);

}

public void actionPerformed(ActionEvent e){

Date date=new Date();

calendar.setTime(date);

if(e.getSource()==t){

label1.setText(date.toString());

if(calendar.get(Calendar.MINUTE)==0)//當(dāng)分鐘為0報(bào)時(shí)

if(calendar.get(Calendar.SECOND)=5){//持續(xù)5秒報(bào)時(shí)

if(calendar.get(Calendar.SECOND)%2==0)

label2.setText("現(xiàn)在是北京時(shí)間"+calendar.get(Calendar.HOUR_OF_DAY)+"點(diǎn)整。");

if(calendar.get(Calendar.SECOND)%2==1)

label2.setText("

");

}

}

}

public static void main (String[] args) {

new Test();

}

}

JAVA畫時(shí)鐘代碼

import?java.awt.*;

import?java.awt.event.*;

import?javax.swing.*;

import?sun.util.calendar.Gregorian;

import?java.util.Calendar;

import?java.util.GregorianCalendar;

public?class?ClockPointer?extends?JFrame{

int?x,?y,?x0,?y0,?r,?h,?olds_x,?olds_y,?oldm_x,?oldm_y,?oldh_x,?oldh_y,?

ss,mm,?hh,?old_m,?old_h,?ang;

final?double?RAD?=?Math.PI/180;

public?ClockPointer(){

super("Java時(shí)鐘");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Image?image?=?getToolkit().getImage("clock.gif");

setIconImage(image);

setSize(400,400);

setBackground(Color.white);

//setLocation(300,150);

this.setLocationRelativeTo(null);

setResizable(true);

int?delay?=?1000;

//創(chuàng)建一個(gè)監(jiān)聽事件

setVisible(true);

ActionListener?drawClock?=?new?ActionListener(){

public?void?actionPerformed(ActionEvent?evt){

repaint();

}

};

//創(chuàng)建一個(gè)時(shí)間計(jì)數(shù)器,每一秒觸發(fā)一次

new?Timer(delay,?drawClock).start();

}

java.text.SimpleDateFormat?fmTime?=?new?java.text.SimpleDateFormat("HH:mm:ss");

//繪制圖形

public?void?paint(Graphics?g){

super.paint(g);

g.setFont(null);

Graphics2D?g2D?=?(Graphics2D)g;

Insets?insets?=?getInsets();

int?L?=?insets.left/2,?T?=?insets.top/2;

h?=?getSize().height;

g.setColor(Color.white);

//畫圓

g2D.setStroke(new?BasicStroke(2.0f));

g.setColor(Color.gray);

g.drawOval(L+40,?T+40,?h-80,?h-80);

r?=?h/2?-?40;

x0?=?40?+?r?-?5?+?L;

y0?=?40?+?r?-?5?-?T;

ang?=?60;

//繪制時(shí)鐘上的12個(gè)字

for(int?i?=?1;i?=?12;i?++){

x?=?(int)((r+10)*Math.cos(RAD*ang)+x0);

y?=?(int)((r+10)*Math.sin(RAD*ang)+y0);

g.setColor(Color.black);

g.drawString(""+i,?x,?h-y);

ang?-=30;

}

//獲得現(xiàn)在的時(shí)間

Calendar?now?=?new?GregorianCalendar();

int?nowh?=?now.get(Calendar.HOUR_OF_DAY);

int?nowm?=?now.get(Calendar.MINUTE);

int?nows?=?now.get(Calendar.SECOND);

String?st=fmTime.format(now.getTime());

//在窗體上顯示時(shí)間

g.setColor(Color.pink);

g.fillRect(L,?T,?50,?28);

g.setColor(Color.blue);

g.drawString(st,L+2,T+26);

//計(jì)算時(shí)間與度數(shù)的關(guān)系

ss?=?90?-?nows*6;

mm?=?90?-?nowm*6;

hh?=?90?-?nowh*30?-?nowm/2;

x0?=?r+40+L;

y0?=?r+40+T;

g2D.setStroke(new?BasicStroke(1.2f));

//擦除秒針

//if(olds_x??0){

//????g.setColor(getBackground());

//????//?g.setColor(Color.gray);

//????g.drawLine(x0,?y0,?olds_x,?h-olds_y);?//?(?)

//}

//繪制秒針

x?=?(int)(r*0.9*Math.cos(RAD*ss))+x0;

y?=?(int)(r*0.9*Math.sin(RAD*ss))+y0-2*T;

g.setColor(Color.yellow);

g.drawLine(x0,?y0,?x,?h-y);

olds_x?=?x;

olds_y?=?y;

g2D.setStroke(new?BasicStroke(2.2f));

//擦除分針

//if(old_m!=mm){

//????g.setColor(getBackground());

//????g.drawLine(x0,y0,oldm_x,h-oldm_y);

//}

//繪制分針

x?=?(int)(r*0.7*Math.cos(RAD*mm))+x0;

y?=?(int)(r*0.7*Math.sin(RAD*mm))+y0-2*T;

g.setColor(Color.green);

g.drawLine(x0,y0,x,h-y);

oldm_x?=?x;

oldm_y?=?y;

old_m?=?mm;

g2D.setStroke(new?BasicStroke(3.2f));

//擦除時(shí)針

//if(old_h!=hh){

//????g.setColor(getBackground());

//????g.drawLine(x0,y0,oldh_x,h-oldh_y);

//}

//繪制時(shí)針

x?=?(int)(r*0.5*Math.cos(RAD*hh))+x0;

y?=?(int)(r*0.5*Math.sin(RAD*hh))+y0-2*T;

g.setColor(Color.red);

g.drawLine(x0,y0,x,h-y);

oldh_x?=?x;

oldh_y?=?y;

old_h?=?hh;

}

public?static?void?main(String[]?args){

new?ClockPointer();

}

}

//整理一下


網(wǎng)站標(biāo)題:包含時(shí)鐘系統(tǒng)java源代碼的詞條
文章起源:http://weahome.cn/article/hdjioc.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部