編程鬧鍾演算法
⑴ 用C#事件按鈕做一個數字時鍾 最好帶鬧鍾效果的 求代碼
求代碼~~
您說笑了
思路:
1.如果是圓形的鍾,需要在picturebox中用DRAW畫,用timer控制項隔一秒畫一次也就是1000ms
如果只是個時間,那麼直接獲取系統時間,用timer控制項隔一秒刷新一次即可,不涉及控制項圖畫,很簡單。
2.但如果是控制項怎麼畫?既然是個圖形,圍繞中心旋轉,那麼這是個方程,每秒刷新一次,重畫這個方程
3.鬧鍾~我的思路是把信息寫入xml或ini中,每隔一分鍾讀取一次,判斷是否到時間,是否做相應操作
所以表面上看功能很少,其實涉及c#的許多控制項操作和編程方法
您自己試試能學到很多東西
⑵ 編寫一個C語言鬧鍾程序
2樓說的創建一個線程查詢系統時間 ,就是一個查詢演算法,時間本來就是1~60秒排好序的,那就用2分法排序吧,快又簡單,然後當系統時間==鬧鍾事件【i】,就開始鬧
就這樣,2分演算法要是還不會就用冒泡法吧,嘿嘿
⑶ 用單片機做鬧鍾你是什麼思路
用單片機做鬧鍾,選一時鍾晶元,如DS1302,單片機用51或pic或其它系列都可,單片機和時鍾晶元用i/o連接好。顯示選LED,LCD都運行,加蜂鳴器用單片機控制。功能要求,編程序實現了。
⑷ 單片機設置兩次鬧鈴的鬧鍾編程怎麼寫
鬧鍾是根據時間來判斷的
所以
你先要在定時器中斷里設置
他的初值來判斷時間,然後在主程序中判斷
鬧鍾時間的標志
來使能蜂鳴器的動作
⑸ 用C語言編程數碼鬧鍾
這個應該是在dos下實現的吧。需要在dos上繪制。數字到數碼管的用查表法就可以了(很多講單片機的書里都有這個表的)。 然後多個鬧鍾,應該是用數據結構封裝,這樣才方便多個。等到定時時間到後,遍歷所有鬧鍾,將其時間顯示出來。菜單應該就是printf之類的dos菜單吧。 如果你的是用單片機實現,就當上面我沒說。這種程序一般網上能搜索到的,大同但是有小異。別指望別人能給出完整程序。沒那個功夫。
⑹ 圖形化編程鬧鍾怎麼編
文件選擇器, 自定義游標, HTML瀏覽器, 抖動文字, 陰影文字, 波浪文字, 飛行文字, 控制項的相互控制與消息傳遞, 伸展文字, 用Applet顯示圖片, 圖片火焰效果, 圖片百葉窗, 圖片倒影, 圖片翻折, 鬧鍾, 萬年歷, 計算器。
報時小鬧鍾匯編程序設計 基本功能:顯示一個精緻的圖形時鍾,時鍾表顯示的時間為本機系統的時間。並模擬出時針,分針,秒針的走動。按b鍵可擴大畫面 ;按s鍵可縮小畫面;按c鍵可改變顏色;按e鍵可聽音樂;按q鍵退出本程序。
⑺ 要做一個用C語言編程的數字鍾有鬧鍾和計時功能,求大神講解一下它的工作原理
一樓的說法有誤,C、C++都不支持多線程,
我之前寫過C#的,在csdn 搜 solief ,
C最好的方式像一樓說的,獲取時間和設置睡眠 可以實現鬧鍾功能,不過不能暫停或者取消
如果要實現計時,開始和結束獲取時間做差即可,與睡眠有沖突
或者你採用一直獲取系統時間,再和目標時間比較的方法,就不會有上面的缺點,不過效率差,系統消耗大
C入門不錯,但如果真想發展,學 python 、C++、C# 這類的吧
⑻ vb製作鬧鍾要怎麼做代碼(會響和的可以設置時間的)
鬧鍾在編程思維上有兩部分:計時和報警
大體思路如下:
用一個timer,每秒鍾檢測系統時間,用now()。(如果你只想精確到分鍾就每分鍾檢測一次,看你需要了)
當系統時間等於設定值時,用msgbox提醒用戶時間已到
如果msgbox不夠明顯,可以用「Shell App.Path & "\程序名1.EXE"啟動一個音樂播放器,播放事先設置好的音樂,或實現你自己想要的效果。
⑼ 求一個VC++關於定時鬧鍾的編程~~
這是我以前做的自動關機的程序,要鬧鍾的話把if (CurrentTime == SetTime)里邊的語句修改下就可以了。
void CAutoShutdown1Dlg::OnTimer(UINT nIDEvent)
{
CTime t = CTime::GetCurrentTime();
CString str = t.Format("溫馨提示:\r\n當前時間為 %Y年%m月%d日 %H:%M:%S");
m_static.SetWindowText(str);
CString str1 = t.Format("%H%M");
int CurrentTime;
int SetTime;
CurrentTime = atoi((LPSTR)(LPCTSTR)str1);
SetTime = atoi((LPSTR)(LPCTSTR)m_TimeSet);
if (CurrentTime == SetTime)
{
ExitWindowsEx(EWX_SHUTDOWN,NULL);
KillTimer(nIDEvent);
}
else
return;
CDialog::OnTimer(nIDEvent);
}
void CAutoShutdown1Dlg::OnButton1()
{
m_edit1.GetWindowText(m_TimeSet);
if (m_TimeSet =="")
{
MessageBox("請輸入時間");
}
else
{
int Hour1,Hour2,Minite1,Minite2;
CString i = m_TimeSet.GetAt(0);
CString j = m_TimeSet.GetAt(1);
CString k = m_TimeSet.GetAt(2);
CString l = m_TimeSet.GetAt(3);
Hour1 = atoi((LPSTR)(LPCTSTR)i);
Hour2 = atoi((LPSTR)(LPCTSTR)j);
Minite1 = atoi((LPSTR)(LPCTSTR)k);
Minite2 = atoi((LPSTR)(LPCTSTR)l);
if ((Hour1 < 3) && (Hour1 < 10) && (Minite1 < 6) && (Minite2 < 10))
{
if (MessageBox("確定這個時間關機?","信息提示",MB_YESNO | MB_ICONQUESTION) == IDYES)
{
MessageBox("您以成功設置關機時間!","信息提示",MB_ICONWARNING);
}
}
else
{
if ((MessageBox("輸入時間錯誤,請重新輸入!","信息提示",MB_RETRYCANCEL |MB_ICONWARNING)) == IDRETRY)
{
CString str = "";
m_edit1.SetWindowText(str);
}
else
CDialog::OnOK();
}
}
}
⑽ 尋找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();;
/**
* <br>
* 方法說明:實現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();
}
/**
* <br>
* 方法說明:繪制圖形
*/
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) < 0|| 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) < 0|| 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) < 0|| 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) < 0|| 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) < 0|| 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) < 0|| 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();
}
}
}