1. java语言程序 时钟类的设计和对象的创建
你是要设计一个 类 还是要编写一个时钟程序
类的话 没什么实际意义 timer 和 date 一起用就是时钟了
要模仿 个时钟的 话 要写 JS样式就可以 要这个类的话 打开jdK的date类 就能看到 时间类是怎么设计的
2. 编写一个类实现秒表的功能。要求至少实现开始计时、停止计时、分针秒针归零、获得分针示数、获得秒针示数
c++还是JAVA?c++可以帮你写用clock函数就可以
3. 用java编写一个类实现秒表的功能
java System.currentTimeMillis() 就是获取当前的毫秒数
开始时记录 istart= System.currentTimeMillis();
结束时 记录 iend= System.currentTimeMillis();
分钟就是 Math.round((iend-istart)/(60*1000));
那 秒数 就是 Math.round((iend-istart)/1000)%60
再开启一个定时器,定时获取 itmp= System.currentTimeMillis();计算分钟和秒数 显示出来
显示动态在跳得秒和分
4. 用java实现 一个计时器, 最后窗口是以一个时钟的图像显示,旁边年月日小时分钟秒
简单的方式有两种:
1. 定时器类timer.schedule做事件驱动。指定每隔多少时间触发事件。函数的参数如下:schedule(TimerTask task, Date firstTime, long period) 安排指定的任务在指定的时间开始进行重复的固定延迟执行。
2. 用一个死循环,把时间更新写在循环里,然后用thread.sleep函数让循环每隔多长时间休息一下。
剩下的就是界面部分的事情了
5. 寻找java编程高手写一个闹钟的程序
自己之前做过的一个:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
public class Clock extends JFrame implements ActionListener {
public final int HEIGTH = 200, L0 = 50, T0 = 50,N=8;
public final double RAD = Math.PI / 180.0;
int x, y, old_X, old_Y, r, x0, y0, w, h, ang;
int sdo, mdo, hdo, old_M, old_H, hh, mm, ss;
int delay = 1000;
Calendar now;
String st, alarm, Items1, Items2,str[];
JButton jb;
JComboBox jc1, jc2, jc3;
JLabel jl1, jl2, jl3, jl4;
JMenu jm1, jm2, jm3, jm4;
JMenuBar jmb;
JMenuItem jmi1, jmi2, jmi3, jmi4, jmi5, jmi6, jmi7, jmi8, jmi9,jmi10;
JTextField jtf1, jtf2, time;
JPanel jp1, jp2, jp3;
Timer timer;
TimeZone tz = TimeZone.getTimeZone("JST");
Toolkit toolkit=Toolkit.getDefaultToolkit();;
/**
*
* 方法说明:实现ActionListener类必须过载的方法
*/
public static void main(String[] args) {
Clock cp = new Clock();
cp.setVisible(true);
}
Clock() {
super("Java闹钟!");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(550, 700);
setVisible(true);
Container contentPane = getContentPane();
jp2 = new JPanel();
jmb = new JMenuBar();
jm1 = new JMenu("背景颜色设置 ", true);
jmi1 = new JMenuItem("外圈颜色");
jmi1.addActionListener(this);
jmi1.setActionCommand("color1");
jm1.add(jmi1);
jmi2 = new JMenuItem("闹钟边线颜色");
jmi2.addActionListener(this);
jmi2.setActionCommand("color2");
jm1.add(jmi2);
jmi3=new JMenuItem("底盘颜色");
jmi3.addActionListener(this);
jmi3.setActionCommand("color3");
jm1.add(jmi3);
jmi4=new JMenuItem("系统时间背静颜色");
jmi4.addActionListener(this);
jmi4.setActionCommand("color4");
jm1.add(jmi4);
jmb.add(jm1);
jm2 = new JMenu("指针颜色设置 ", true);
jmi5 = new JMenuItem("秒针颜色");
jmi5.addActionListener(this);
jmi5.setActionCommand("color5");
jm2.add(jmi5);
jmi6 = new JMenuItem("分针颜色");
jmi6.addActionListener(this);
jmi6.setActionCommand("color6");
jm2.add(jmi6);
jmi7 = new JMenuItem("时针颜色");
jmi7.addActionListener(this);
jmi7.setActionCommand("color7");
jm2.add(jmi7);
jmb.add(jm2);
jm3 = new JMenu("闹铃声音设置 ", true);
jmi8 = new JMenuItem("响铃1");
jmi8.addActionListener(this);
jmi8.setActionCommand("ring1");
jm3.add(jmi8);
jmi9 = new JMenuItem("静音");
jmi9.addActionListener(this);
jmi9.setActionCommand("ring2");
jm3.add(jmi9);
jmb.add(jm3);
jm4 = new JMenu("帮助 ", true);
jmi10=new JMenuItem("使用说明");
jmi10.addActionListener(this);
jmi10.setActionCommand("help");
jm4.add(jmi10);
jmb.add(jm4);
jp2.add(jmb);
contentPane.add(jp2, BorderLayout.NORTH);
jp3 = new JPanel();
jl1 = new JLabel("闹铃时间");
jl1.setFont(new Font("楷体_GB2312", Font.BOLD, 18));
time = new JTextField("00:00", 5);
alarm = time.getText();
jb = new JButton("修改闹铃时间");
jb.addActionListener(this);
jb.setActionCommand("CC");
jp3.add(jl1);
jp3.add(time);
jp3.add(jb);
contentPane.add(jp3, BorderLayout.SOUTH);
ClockPanel clock = new ClockPanel();
contentPane.add(clock, BorderLayout.CENTER);
// 窗体添加事件监听,监听秒表的触发
ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
repaint();
}
};
new Timer(delay, taskPerformer).start();
}
/**
*
* 方法说明:绘制图形
*/
Color C1 = Color.lightGray;// 外圈颜色
Color C2 = Color.black;// 边线颜色
Color C3 = Color.magenta;// 内盘颜色
Color C4 = Color.blue;// 背景颜色
Color C5 = Color.yellow;// 秒针颜色
Color C6 = Color.green;// 分针颜色
Color C7 = Color.red;//时针颜色
public class ClockPanel extends JPanel {
public void paint(Graphics g) {
h = getSize().height - 200;
// 绘制圆形
g.setColor(C1);
g.fillOval(L0 + 30, T0 + 30, h - 60, h - 60);
g.setColor(C2);
g.drawOval(L0 + 31, T0 + 31, h - 62, h - 62);
g.setColor(C3);
g.fillOval(L0 + 50, T0 + 50, h - 100, h - 100);
g.setColor(C2);
g.drawOval(L0 + 51, T0 + 51, h - 102, h - 102);
r = h / 2 - 30;
x0 = 30 + r - 5 + L0;
y0 = 30 + r - 5 - T0;
ang = 60;
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.drawString("" + i, x, h - y);
ang -= 30;
}
x0 = 30 + r + L0;
y0 = 30 + r + T0;
g.drawString("指针式时钟", 215, 200);
// 获取时间
now = Calendar.getInstance();
hh = now.get(Calendar.HOUR_OF_DAY);// 小时
mm = now.get(Calendar.MINUTE);// 分钟
ss = now.get(Calendar.SECOND);// 秒
g.setColor(C4);
g.fillRect(5, 550, 150, 30);// 填充的矩形
g.setColor(C6);
if (hh < 10)
st = "0" + hh;
else
st = "" + hh;
if (mm < 10)
st = st + ":0" + mm;
else
st = st + ":" + mm;
if(alarm.equals(st))
{
if(toolkit!=null)
toolkit.beep();
else {}
}
if (ss < 10)
st = st + ":0" + ss;
else
st = st + ":" + ss;
{
g.setFont(new Font("华文楷体", Font.BOLD, 16));
g.drawString("系统时间:" + st, 10, 570);
}
// 计算时间和图形的关系
sdo = 90 - ss * 6;
mdo = 90 - mm * 6;
hdo = 90 - hh * 30 - mm / 2;
// 擦除秒针
if (old_X > 0) {
g.setColor(C3);
} else {
old_M = mdo;
old_H = hdo;
}
// 绘制秒针
g.setColor(C5);
x = (int) ((r - 26) * Math.cos(RAD * sdo) + x0);
y = (int) ((r - 26) * Math.sin(RAD * sdo) + y0) - 2 * T0;
g.drawLine(x0, y0, x, (h - y));
old_X = x;
old_Y = y;
// 擦除分针和时针
if (mdo != old_M) {
g.setColor(C3);
old_M = mdo;
}
if (hdo != old_H) {
g.setColor(C3);
old_H = hdo;
}
// 绘制分针
g.setColor(C6);
x = (int) ((r - 50) * Math.cos(RAD * mdo) + x0);
y = (int) ((r - 50) * Math.sin(RAD * mdo) + y0) - 2 * T0;
g.drawLine(x0, y0, x, (h - y));
// 绘制时针
g.setColor(C7);
x = (int) ((r - 90) * Math.cos(RAD * hdo) + x0);
y = (int) ((r - 90) * Math.sin(RAD * hdo) + y0) - 2 * T0;
g.drawLine(x0, y0, x, (h - y));
} // end paint
}
// 闹铃时间的判断及实现
// 闹铃声音的实现
public void actionPerformed(ActionEvent e) {
// JMenuItem m = (JMenuItem) e.getSource();
if (e.getActionCommand() == "CC") {
int newHou, newMin;
char c;
String getTime = JOptionPane.showInputDialog(this, "请输入闹铃时间格式如:", "00:00");
repaint();
//如果撤消设置时间,就什么打印null
if(getTime==null)
System.out.println(getTime);
// dispose();
judge: if (getTime != null) {
//打印输入的设置的时间
System.out.println(getTime);
// 判断输入的是不是5位字符
if (getTime.length() != 5) {
JOptionPane.showMessageDialog(time, "格式错误\n请按格式输入5位数字", "Error",
JOptionPane.ERROR_MESSAGE);
repaint();
break judge;
}
// 判断输入的是不是数字
for (int i = 0; i < (getTime.length()); i++) {
c = getTime.charAt(i);
if (i == 2 && !Character.isDigit(c))
continue;
// 判断当前字符,如果不是数字则跳出该事件
if (i != 2 && !Character.isDigit(c)) {
JOptionPane.showMessageDialog(this, "格式错误\n请按格式输入5位数字",
"Error",JOptionPane.ERROR_MESSAGE);
repaint();
break judge;
}
}
char[] hour = { getTime.charAt(0), getTime.charAt(1) };
char[] minute = { getTime.charAt(3), getTime.charAt(4) };
newHou = Integer.parseInt(String.valueOf(hour));
newMin = Integer.parseInt(String.valueOf(minute));
if (newHou >= 24 || newHou < 0) {
JOptionPane.showMessageDialog(this, "格式错误\n小时应该是不小于0不大于23的正数",
"Error", JOptionPane.ERROR_MESSAGE);
repaint();
break judge;
}
if (newMin >= 60 || newHou < 0) {
JOptionPane.showMessageDialog(this, "格式错误\n分钟应该是小于60的正数", "Error",
JOptionPane.ERROR_MESSAGE);
repaint();
break judge;
}
new SetTime(newHou, newMin);
}
}
if (e.getActionCommand() == "ring1") {
toolkit=Toolkit.getDefaultToolkit();
}
if(e.getActionCommand() == "ring2"){
System.out.println("静音");
toolkit=null;
}
if (e.getActionCommand() == "color1") {
String color;
Color c;
System.out.println("color1");
color = JOptionPane.showInputDialog(this, "请输入喜欢的外圈颜色(0--255)", "128");
if (color == null) {
} else {
if (Integer.parseInt(color) < 0
|| Integer.parseInt(color) > 255)
JOptionPane.showInputDialog(this, "请输入喜欢的外圈颜色(0--255)", "128");
else {
c = new Color(Integer.parseInt(color));
C1 = c;
}
}
}
if(e.getActionCommand() == "color2"){
String color;
Color c;
System.out.println("color2");
color = JOptionPane.showInputDialog(this, "请输入喜欢的边线颜色(0--255)", "128");
if(color==null){}
else{if (Integer.parseInt(color) 255)
JOptionPane.showInputDialog(this, "请输入喜欢的边线颜色(0--255)", "128");
else {
c = new Color(Integer.parseInt(color));
C2 = c;
}
}
}
if(e.getActionCommand() == "color3"){
String color;
Color c;
System.out.println("color3");
color = JOptionPane.showInputDialog(this, "请输入喜欢的内盘颜色(0--255)", "128");
if(color==null){}
else{if (Integer.parseInt(color) 255)
JOptionPane.showInputDialog(this, "请输入喜欢的内盘颜色(0--255)", "128");
else {
c = new Color(Integer.parseInt(color));
C3 = c;
}
}
}
if(e.getActionCommand() == "color4"){
String color;
Color c;
System.out.println("color4");
color = JOptionPane.showInputDialog(this, "请输入喜欢的背景颜色(0--255)", "128");
if(color==null){}
else{if (Integer.parseInt(color) 255)
JOptionPane.showInputDialog(this, "请输入喜欢的背景颜色(0--255)", "128");
else {
c = new Color(Integer.parseInt(color));
C4 = c;
}
}
}
if(e.getActionCommand() == "color5"){
String color;
Color c;
System.out.println("color5");
color = JOptionPane.showInputDialog(this, "请输入喜欢的秒针颜色(0--255)", "128");
if(color==null){}
else{if (Integer.parseInt(color) 255)
JOptionPane.showInputDialog(this, "请输入喜欢的秒针颜色(0--255)", "128");
else {
c = new Color(Integer.parseInt(color));
C5 = c;
}
}
}
if(e.getActionCommand() == "color6"){
String color;
Color c;
System.out.println("color6");
color = JOptionPane.showInputDialog(this, "请输入喜欢的分针颜色(0--255)", "128");
if(color==null){}
else{if (Integer.parseInt(color) 255)
JOptionPane.showInputDialog(this, "请输入喜欢的分针颜色(0--255)", "128");
else {
c = new Color(Integer.parseInt(color));
C6 = c;
}
}
}
if(e.getActionCommand() == "color7"){
String color;
Color c;
System.out.println("color7");
color = JOptionPane.showInputDialog(this, "请输入喜欢的时针颜色(0--255)", "128");
if(color==null){}
else{if (Integer.parseInt(color) 255)
JOptionPane.showInputDialog(this, "请输入喜欢的时针颜色(0--255)", "128");
else {
c = new Color(Integer.parseInt(color));
C7 = c;
}
}
}
if(e.getActionCommand() == "help"){
String help;
help = JOptionPane.showInputDialog(this, "输入quit退出该闹钟的使用", "这是运行在Java中的指针式时钟");
if(help.equals("quit"))
dispose();
else {}
// timer.restart();
}
}
class SetTime {
String Hour;
String Minute;
public SetTime() { }
public SetTime(int hour, int minute) {
// 当时间参数小于10的时候在前面添加字符0
if (hour < 10) {
Hour = "0" + String.valueOf(hour);
} else {
Hour = "" + String.valueOf(hour);
}
if (minute < 10) {
Minute = "0" + String.valueOf(minute);
} else {
Minute = "" + String.valueOf(minute);
}
alarm = Hour + ":" + Minute;
time.setText(alarm);
repaint();
}
}
}
6. 时针分针秒针怎么分
1、时针:指示小时,形状最短,走一圈12小时;
2、分针指示分钟,形状宽属于第二长,走一圈1小时;
3、秒针,指示秒钟,最细最长,走一圈1分钟。
时针上两个指针夹角度数=(m=分钟数,h=小时数)注:必须采用12小时计时制,凡是满12:00必须将小时数减掉12。
12:00→0:00
20:30→8:30
例如:4:30时两针夹角大小=
扩展资料:
1分钟秒针转了一周,即360°
分针转了360°×1/60=6°
时针转了(360°/12)×(1/60)=0.5°
时针之所以“顺时针”转动,是源自其前身日晷。时针首先出现于北半球,其作用与日晷投射在地上的“影子指针”相似。
太阳由东边升起西边落下,它投射在日晷上的影子之运行方向相反,是由西向东,所以日晷上代表时间的数字排列也是如此,现代时钟表面数字沿用了这种排列方式。
物体是顺时针转动或是逆时针转动,与观察角度有关。例如地球的自转,从北极正上方观看,是逆时针,从南极正上方看,则是顺时针。
分针在钟表上每走一小格是1分钟,旋转角度为六度,每走一个数字为5分钟,旋转角度为30度。
7. java时钟设计
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.util.Calendar;
import java.util.GregorianCalendar;
class Clock extends JFrame implements ActionListener{
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 Clock(){
super("Clock by kikiwawa");
setDefaultCloseOperation(3);
setSize(200,200);
setBackground(Color.BLACK);
setLocation(300,150);
setResizable(false);
setVisible(true);
int delay = 1000;
ActionListener drawClock = new ActionListener(){
public void actionPerformed(ActionEvent evt){
repaint();
}
};
new Timer(delay,drawClock).start();
}
public void actionPerformed(ActionEvent e){
}
public void paint(Graphics g){
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(4.0f));
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;
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.drawString(""+i,x,h-y);
ang-=30;
}
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;
if(nowh<10) st="0"+nowh;else st=""+nowh;
if(nowm<10) st+=":0"+nowm;else st+=":"+nowm;
if(nows<10) st+=":0"+nows;else st+=":"+nows;
g.setColor(Color.pink);
g.fillRect(L,T,50,28);
g.setColor(Color.blue);
g.drawString(st,L+2,T+26);
ss=90-nows*6;
mm=90-nowm*6;
hh=90-nowh*30-nowm/2;
x0=r+40+L;
y0=r+40+T;
if(olds_x>0){
g.setColor(getBackground());
g.drawLine(x0,y0,olds_x,h-olds_y);
}
else{
old_m = mm;
old_h = hh;
}
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.4f));
if(old_h!=hh){
g.setColor(getBackground());
g.drawLine(x0,y0,oldh_x,h-oldh_y);
}
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){
Clock c = new Clock();
} }
8. “时针,分针,秒针”各表达的含义是什么?
“时针” 最短,最粗,走的最慢,历史最久,意义最大,算是领导。
“分针”中等,意义一般,小部门主管。
“秒针”最细,最长,跑的最快,工作最多,意义最小,基层员工。但在一些特殊场合下还必须得用他。
1、以前是钟,正所谓晨钟暮鼓,就是早上敲钟,傍晚打鼓,都是报时用的。
2、直到近代才出现了挂钟,然后工艺进步了,出现了怀表,后来有人嫌往怀里掏麻烦,弄根绳绑手上就成了手表了。
3、与时间有关的成语:
光阴似箭:形容时间过的很快,好像飞箭一样快速。
一刻千金:比喻时间非常宝贵。
日月如梭:形容时间过的很快。
白驹过隙:形容光阴消逝的很快。
石火光阴:形容光阴的迅速,一眨眼就过去了。
寸金难买村光阴:形容光阴是无价之宝,引申为爱惜光阴。
弹指之间:比喻时间极短。
岁不与我:指时间不待人,比喻时间的可贵。