急求 java 钟表 带定时闹钟功能 源代码 100
rt是java源代码不是软件!带定时功能的!!!闹钟不是随便画一个圈就OK乐界面最好完整一点3Q~~~...
rt
是java源代码 不是软件!
带 定时 功能的!!!闹钟 不是随便画一个圈就OK乐
界面最好完整一点
3Q~~~ 展开
是java源代码 不是软件!
带 定时 功能的!!!闹钟 不是随便画一个圈就OK乐
界面最好完整一点
3Q~~~ 展开
展开全部
import javax.swing.JFrame;
public class Example9_11 extends JFrame {
Example9_11()
{
Clock clock=new Clock();
add(clock);
}
public static void main(String[] args)
{
Example9_11 f=new Example9_11();
f.setTitle("时钟");
f.setSize(300,250);
f.setLocation(400,300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JPanel;
import javax.swing.Timer;
public class Clock extends JPanel implements ActionListener
{
private int hour;
private int minute;
private int second;
Clock()
{
Timer timer=new Timer(1000,this);
timer.start();
}
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
setCurrentTime();
int clockRadius=(int)(Math.min(getWidth(), getHeight())*0.4);
int xCenter=getWidth()/2;
int yCenter=getHeight()/2;
g.drawOval(xCenter-clockRadius, yCenter-clockRadius, 2*clockRadius, 2*clockRadius);
g.drawString("12", xCenter-5, yCenter-clockRadius+12);
g.drawString("9", xCenter-clockRadius+3, yCenter+5);
g.drawString("3",xCenter+clockRadius-10,yCenter+3);
g.drawString("6",xCenter-3,yCenter+clockRadius-3);
int sLength=(int)(clockRadius*0.8);
int xSecond=(int)(xCenter+sLength*Math.sin(second*(2*Math.PI/60)));
int ySecond=(int)(yCenter-sLength*Math.cos(second*(2*Math.PI/60)));
g.setColor(Color.RED);
g.drawLine(xCenter,yCenter,xSecond,ySecond);
int mLength=(int)(clockRadius*0.65);
int xMinute=(int)(xCenter+mLength*Math.sin(minute*(2*Math.PI/60)));
int yMinute=(int)(yCenter-mLength*Math.cos(minute*(2*Math.PI/60)));
g.setColor(Color.BLUE);
g.drawLine(xCenter, yCenter, xMinute, yMinute);
int hLength=(int)(clockRadius*0.5);
int xHour=(int)(xCenter+mLength*Math.sin((hour%12+minute/60.0)*(2*Math.PI/12)));
int yHour=(int)(yCenter-hLength*Math.cos((hour%12+minute/60.0)*(2*Math.PI/12)));
g.setColor(Color.BLACK);
g.drawLine(xCenter,yCenter,xHour,yHour);
}
public void actionPerformed(ActionEvent e)
{
repaint();
}
public void setCurrentTime()
{
Calendar cal=new GregorianCalendar();
this.hour=cal.get(Calendar.HOUR_OF_DAY);
this.minute=cal.get(Calendar.MINUTE);
this.second=cal.get(Calendar.SECOND);
}
}
public class Example9_11 extends JFrame {
Example9_11()
{
Clock clock=new Clock();
add(clock);
}
public static void main(String[] args)
{
Example9_11 f=new Example9_11();
f.setTitle("时钟");
f.setSize(300,250);
f.setLocation(400,300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JPanel;
import javax.swing.Timer;
public class Clock extends JPanel implements ActionListener
{
private int hour;
private int minute;
private int second;
Clock()
{
Timer timer=new Timer(1000,this);
timer.start();
}
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
setCurrentTime();
int clockRadius=(int)(Math.min(getWidth(), getHeight())*0.4);
int xCenter=getWidth()/2;
int yCenter=getHeight()/2;
g.drawOval(xCenter-clockRadius, yCenter-clockRadius, 2*clockRadius, 2*clockRadius);
g.drawString("12", xCenter-5, yCenter-clockRadius+12);
g.drawString("9", xCenter-clockRadius+3, yCenter+5);
g.drawString("3",xCenter+clockRadius-10,yCenter+3);
g.drawString("6",xCenter-3,yCenter+clockRadius-3);
int sLength=(int)(clockRadius*0.8);
int xSecond=(int)(xCenter+sLength*Math.sin(second*(2*Math.PI/60)));
int ySecond=(int)(yCenter-sLength*Math.cos(second*(2*Math.PI/60)));
g.setColor(Color.RED);
g.drawLine(xCenter,yCenter,xSecond,ySecond);
int mLength=(int)(clockRadius*0.65);
int xMinute=(int)(xCenter+mLength*Math.sin(minute*(2*Math.PI/60)));
int yMinute=(int)(yCenter-mLength*Math.cos(minute*(2*Math.PI/60)));
g.setColor(Color.BLUE);
g.drawLine(xCenter, yCenter, xMinute, yMinute);
int hLength=(int)(clockRadius*0.5);
int xHour=(int)(xCenter+mLength*Math.sin((hour%12+minute/60.0)*(2*Math.PI/12)));
int yHour=(int)(yCenter-hLength*Math.cos((hour%12+minute/60.0)*(2*Math.PI/12)));
g.setColor(Color.BLACK);
g.drawLine(xCenter,yCenter,xHour,yHour);
}
public void actionPerformed(ActionEvent e)
{
repaint();
}
public void setCurrentTime()
{
Calendar cal=new GregorianCalendar();
this.hour=cal.get(Calendar.HOUR_OF_DAY);
this.minute=cal.get(Calendar.MINUTE);
this.second=cal.get(Calendar.SECOND);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
深圳市兴威帆电子技术有限公司
2023-08-24 广告
2023-08-24 广告
实时时钟模块可以选择许多不同的制造商和型号,具体选择取决于您的应用需求和预算。一些流行的实时时钟模块品牌包括DS1302、MA电商平台6925和MCP7941。这些模块都具有精度高、稳定性好、功耗低等优点,并具有不同的功能和特性,可以满足各...
点击进入详情页
本回答由深圳市兴威帆电子技术有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询