導航:首頁 > 源碼編譯 > timer源碼

timer源碼

發布時間:2022-02-09 07:47:21

『壹』 VB如何使用Timer1計時來切換image1的圖片切換多張.求源代碼!

Private Sub Form_Load() Timer1.Interval = 1000 '這里是換圖的間隔 End Sub Private Sub Timer1_Timer() Static i As Integer i = i + 1 Image1.Picture = LoadPicture(App.Path & "\" & i & ".jpg") If i = 5 Then '有多少張就改多少 i = 0 End If End Sub 代碼如上,注釋也寫了,還有不懂的再問我。 追問: 請問下定義 數組 是怎麼定義的? 回答: 數組 一樣的,只不過更簡單化一點: dim a(1,2) as ingeter 這裡面有六個數,即(0,0)、(0,1)、(0,2)、(1,0)、(1,1)、(1,2)。 當然你也可以這樣定義: dim a(4) as ingeter 這裡面有五個數,即0、1、2、3、4。 數組一般是從0開始的,如果你要從1開始的話,可以這樣定義: dim a(1 to 5) as ingeter 這樣就有1、2、3、4、5五個數。 追問: 謝了,方便留下你的QQ么?以後有不懂再請教你 回答: 可以,243303453

『貳』 用vb做的時鍾程序源代碼

你要的程序代碼來了,已經驗證OK!!!

Private Sub Form_Load()
Timer1.Interval = 1000
Label1.AutoSize = True
Label1.Caption = ""
End Sub

Private Sub Timer1_Timer()
Label1.Caption = Now
End Sub

你在窗體上添加一個timer控制項和一個label標簽,把上面的代碼復制進去看結果吧!以後共同努力!!!

『叄』 守護線程如何退出Timer源碼所得

近日要做定時任務,看了看java.util.Timer源碼,Timer類中有以下三個變數:�0�2private TaskQueue queue = new TaskQueue(); /** * The timer thread. */ private TimerThread thread = new TimerThread(queue); /** * This object causes the timer's task execution thread to exit * gracefully when there are no live references to the Timer object and no * tasks in the timer queue. It is used in preference to a finalizer on * Timer as such a finalizer would be susceptible to a subclass's * finalizer forgetting to call it. */ private Object threadReaper = new Object() { protected void finalize() throws Throwable { synchronized(queue) { thread.newTasksMayBeScheled = false; queue.notify(); // In case queue is empty. } } };�0�2�0�2�0�2�0�2�0�2 其中thread變數在timer初始化後開始啟動,其start就是一個while(true)循環,不斷取得queue中任務進行判斷。。那麼thread線程退出就是個問題了,當然Timer提供了cancel方法。�0�2�0�2�0�2�0�2 當quene變為了空,而這個timer類沒有再被引用,那麼如果不執行cancel則這個線程一直運行狀態。當垃圾回收的時候,while(true)一直運行,所以不會退出。因此當timer進行回收時候,threadReaper 對象回收了,其finalize方法將queue清空,標識變數false,這樣while循環中的判斷break條件為真,退出循環,函數執行完畢了,線程也會退出了。

『肆』 怎麼用VB做個坦克大戰游戲裡面自動移動和打炮彈的敵方坦克timer控制還是隨機事件啊求源代碼。

源碼網http://www.codesky.net/ 屌絲軟體多得是

『伍』 我有萬年歷和時鍾的java源代碼,但不知道怎麼把他們在一個程序中顯示出來知道的請回復

/**
* @(#)AidyCalender.java
*
*
* @author
* @version 1.00 2008/7/19
*/
import java.awt.*;
import java.awt.event.*;
import java.lang.StringBuffer;
import javax.swing.*;
import java.util.*;
import javax.swing.Timer;
import javax.swing.border.*;

public class AidyCalender extends JFrame implements ActionListener,ItemListener{

Date date = new Date();
private GregorianCalendar gregorianCalendar = new GregorianCalendar();
//定義中英文字元數組存儲星期信息,用於轉換顯示
private String[] stringWeekEn = new String[] { "SUN", "MON", "TUE", "WED",
"THU", "FRI", "SAT" };
private String[] stringWeekCn = new String[] { "星期日", "星期一", "星期二", "星期三",
"星期四", "星期五", "星期六" };
//定義存儲月份的信息數組,用於轉換顯示方示
private String[] stringMonthEn = new String[] { "Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" };
private String[] stringMonthCn = {"一月","二月","三月","四月","五月","六月",
"七月","八月","九月","十月","十一月","十二月"};

private String[] sysNowTime = new String[6];//sysNowTime 用於存儲系統時間的變數
private String[] sysRunTime = new String[6];
private JLabel []labelWeek = new JLabel[7];
private JLabel []labelDay = new JLabel[42];
private JLabel labelTime = new JLabel();

private JPanel panel1 = new JPanel();
private JPanel panel2 = new JPanel();
private JPanel panel3 = new JPanel();
private JComboBox combo1 = new JComboBox();
private JComboBox combo2 = new JComboBox();
private JButton buttonToday = new JButton();

private Border border = BorderFactory.createRaisedBevelBorder();
private Border border1 = BorderFactory.createLineBorder(Color.cyan,3);

public AidyCalender(String title) {
super(title);

for (int y = 1900; y < 2101; y++) {
combo1.addItem(" " + new Integer(y).toString()+"年");
}
for (int m = 0;m<12;m++){
combo2.addItem(" "+stringMonthCn[m]);
}
buttonToday.setText("今 天");
setLayout(new FlowLayout());
add(panel1);
add(panel2);
add(panel3);
panel1.setLayout(new GridLayout(1,3,10,0));
panel1.add(combo1);
combo1.addItemListener(this);
panel1.add(combo2);
combo2.addItemListener(this);
panel1.add(buttonToday);
buttonToday.addActionListener(this);
labelTime.setFont(new Font("宋體",Font.PLAIN,16));
labelTime.setForeground(Color.MAGENTA);
panel1.add(labelTime);
Timer time = new Timer(1000,new TimerListener());
time.addActionListener(new TimerListener());
//time.setRepeats(true);
time.start();

//labelTime.addAncestorListener(new TimerListener());

panel2.setLayout(new GridLayout(7,7,0,10));
panel2.setBackground(Color.white);

for(int i=0;i<7;i++){
labelWeek[i] = new JLabel();
labelWeek[i].setHorizontalAlignment(0);
if(i==0||i==6){
labelWeek[i].setBackground(Color.blue);
labelWeek[i].setForeground(Color.RED);
labelWeek[i].setFont(new Font("黑體",Font.BOLD,14));
}

else{
labelWeek[i].setForeground(Color.BLACK);
labelWeek[i].setFont(new Font("新宋體",Font.PLAIN,14));
}

labelWeek[i].setText(stringWeekCn[i]);
panel2.add(labelWeek[i]);

}
for(int i= 0;i<42;i++){
labelDay[i] = new JLabel();
labelDay[i].setHorizontalAlignment(0);
labelDay[i].setText("");
panel2.add(labelDay[i]);
}

addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});

setSize(300,300);
setBounds(250, 200, 400, 360);
setVisible(true);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

getSysDate();
setNowDate();
}

public void actionPerformed(ActionEvent ae){
if(ae.getSource()==buttonToday){
setNowDate();
}

}
public void itemStateChanged(ItemEvent aa){
setChangeDate();

}

public int turnWeek(String week){
int i;
for(i=0;i<7;i++)
if(week.equalsIgnoreCase(stringWeekEn[i]))
break;
return i;
}

public int turnMonth(String month){
/**
*int turnMonth(String month)
*@month 系統日期中的月,諸如Jan\Feb
*@return int
*返回一個整數值,用於尋找stringMonthCn[]數組中對應的中文月份
*/
int i;
for(i=0;i<12;i++)
if(month.equalsIgnoreCase(stringMonthEn[i]))
break;
return i;
}
/**
*setNowDate()
*設置當前系統日期
*/
public void setNowDate(){

setSysDate(getNowYear(),getNowMonth());
getSysRunDate();
setDateNull();
combo1.setSelectedIndex(getShowYear() - 1900);
combo2.setSelectedIndex(getShowMonth());
setDays(getMonthDays(getNowYear(),getNowMonth()),getInitWeek(sysRunTime[0]),getNowDay());
//labelTime.setText(sysNowTime[3]);
//labelTime.setHorizontalAlignment(0);
}

/**Integer getShowYear()
*獲取組合框中應該顯示的年份
*/

public void setSysDate(int year,int month){
gregorianCalendar.set(year,month,1);
}
public void setDateNull(){
for(int i=0;i<42;i++){
labelDay[i].setText("");
}
}
public void setChangeDate(){
setSysDate(getComboYear(),getComboMonth());
getSysRunDate();
setDateNull();
setDays(getMonthDays(getComboYear(),getComboMonth()),getInitWeek(sysRunTime[0]),-1);

}
public int getMonthDays(int year, int month) {
/**
*返回所選年月的天數,因為數組中的數值從0開始,所以3\5\8\10分別代表4\6\9\11幾個小月.
*而1代表2月,經過是否為閏年判斷,選擇返回28或29天.
*其餘月份為大月,返回31天.
**/
switch (month) {
case 3:
case 5:
case 8:
case 10:
return 30;//小月返回30天
case 1:
if (gregorianCalendar.isLeapYear(year)) {
//isLeapYear(year)確定當前紀元中的指定年份是否為閏年。
return 29;
} else {
return 28;
}//閏年的二月返回29天,平年返回28天
default:
return 31;
//大月返回31天
}
}
/**
*int getComboYear()
*獲取組合框中的年份
*/
public void getSysDate(){
date = gregorianCalendar.getTime();
sysNowTime = (date.toString()).split(" ");
}
public void getSysRunDate(){
date = gregorianCalendar.getTime();
sysRunTime = (date.toString()).split(" ");
}
public int getComboYear(){
return combo1.getSelectedIndex()+1900;
}

/**
*int getComboMonth()
*獲取月組合框中的整數值,
*/
public int getComboMonth(){
return combo2.getSelectedIndex();
}

public int getInitWeek(String initWeek){
/**
*getWeekNow(String initWeek)
*@para nowWeek 系統日期中的星期
*返回當月中的1號是從星期幾開始
*/
int nowWeek = 0 ;
for(int i = 0;i<7;i++){
if(initWeek.equalsIgnoreCase(stringWeekEn[i])){

nowWeek = i;
break;
}
}
return nowWeek;
}
public int getNowYear(){
return Integer.parseInt(sysNowTime[5]);
}
public int getNowMonth(){
int nowMonth=0;
for(int i=0;i<12;i++){
if(sysNowTime[1].equalsIgnoreCase(stringMonthEn[i]));
nowMonth=i;
break;
}
return nowMonth;
}
public int getNowDay(){
return Integer.parseInt(sysNowTime[2]);

}
public Integer getShowYear(){
return Integer.parseInt(sysNowTime[5]);
}

public Integer getShowMonth(){
/**
*Integer getShowMonth()
*獲取在組給框中顯示的中文格式月份:如七月\八月等
*/
return turnMonth(sysNowTime[1]);
}

public void setDays(int monthDays,int initWeek,int day){
/**
*void setDays(int monthDays,int initWeek,int day)
*@para monthDays 本月天數
*@para initWeek 初始星期
*@para day 今天日
*設置月歷
*/
setDateNull();
for(int i=initWeek;i<initWeek+monthDays+1;i++){
if((i-initWeek+1)==day){
labelDay[i].setBorder(border1);
labelDay[i].setForeground(Color.BLUE);
labelDay[i].setFont(new Font("黑體",Font.BOLD,20));
}else if((i%7==0)||(i%7==6))
labelDay[i].setForeground(Color.RED);
else{
labelDay[i].setForeground(Color.BLACK);
}
labelDay[i].setText(String.valueOf(i-initWeek+1));
}
for(int i=initWeek+monthDays;i<42;i++)
labelDay[i].setText("");
}

class TimerListener implements ActionListener{
//AdapterDemo var=new AdapterDemo("萬年歷程序--Aidy");

public void actionPerformed(ActionEvent e) {

GregorianCalendar g = new GregorianCalendar();
String clock = new String((g.getTime().toString().split(" "))[3]);
labelTime.setText(clock);
}

}
public static void main(String args[])
{
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e){
throw new RuntimeException(e);
}
AidyCalender var=new AidyCalender("萬年歷程序--Aidy");

}

}

本文來自CSDN博客,轉載請標明出處:

『陸』 求幾個演示Timer類用法的java源代碼各位大蝦幫忙

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.*;
import java.awt.*;
public class Text extends JFrame
{
private BorderLayout layout;
JTextField txa=new JTextField();
JTextField txa1=new JTextField();
JTextField txa2=new JTextField();
JButton button=new JButton("START");
MyJPanel panel = new MyJPanel();
String a,b;
// set up GUI
public Text()
{
super( "Using a JDesktopPane" );
// create new panel
// add panel
layout=new BorderLayout();
setLayout(layout);
add(txa1,BorderLayout.NORTH);
add(txa,BorderLayout.SOUTH);
add(txa2,BorderLayout.EAST);

add(button,BorderLayout.WEST);
add(panel, BorderLayout.CENTER );
pack();
button.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{

panel.startAnimation();
}
});
//

} // end class DesktopFrame

class MyJPanel extends JPanel
{
private Timer t;
private int i=0;
private final Color colors[] = { Color.BLACK, Color.BLUE, Color.CYAN,
Color.DARK_GRAY, Color.GRAY, Color.GREEN, Color.LIGHT_GRAY,
Color.MAGENTA, Color.ORANGE, Color.PINK, Color.RED, Color.WHITE,
Color.YELLOW };
private String text[]={"A","B","C","D","E","F","G"};
// private int currentImage;
public MyJPanel()
{

// currentImage=Integer.parseInt(b);

setVisible( true );
}

public void paintComponent( Graphics g )
{
super.paintComponent( g );

panel.setBackground(Color.WHITE);

}
public void paintComponent1( Graphics g )
{
super.paintComponent( g );
if(t.isRunning())
{

panel.setBackground(colors[0]);
txa1.setText(text[i]);
i++;
if(i==4)
i=0;
}
}
public void startAnimation()
{
if ( t == null )
{
// currentImage = 0;
a=txa.getText();
b=txa1.getText();

t=new Timer(Integer.parseInt(a),new TimerHandler());

t.start();
}
else
{
if ( ! t.isRunning() )
t.restart();
}
}
public void stopAnimation()
{
t.stop();
}
private class TimerHandler implements ActionListener
{
public void actionPerformed( ActionEvent actionEvent )
{
Graphics g=panel.getGraphics();
paintComponent1( g );
a=txa.getText();
int c=Integer.parseInt(a);
t.setDelay(c);
Timer t1=new Timer(t.getDelay(),new TimerHandler());
}
}
}
}
//////////////////////////////////////////
import javax.swing.JFrame;

public class Test
{
public static void main( String args[] )
{
Text desktopFrame = new Text();
desktopFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
desktopFrame.setSize( 400, 380 ); // set frame size
desktopFrame.setVisible( true ); // display frame
} // end main
} // end class DesktopTest

『柒』 請問VB里CDate(Timer)是什麼意思啊源代碼是定義變數t,然後t=CDate(Timer)

Timer,是從本次開機以來的秒數,含有小數
CDate是一個函數,用來把一個數值轉變成日期時間格式(其中整數為從1899年12月31日起算的日數;小數表示從0:0開始的時間【12小時為0.5,以此類推】,格式為hh:mm:ss)
綜合起來看本意就是表達本次開機以來的時間,但可能不會正確。因為單位不對。

補充回答:
timer,在這里是一個系統值,並不是你加入的控制項。加入的控制項默認名稱是timer1、timer2之類。
其一,在這里你要是將timer1改成timer會出錯的。
其二,控制項名除了極個別場活使用外,一般不單獨使用(除默認屬性外)。如果要使用控制項名則要使用例如:timer1.name;控制項的其他屬性也必須寫出屬性名的。

『捌』 vb一小時倒計時源代碼,格式00:00:00

給一個自己寫的,篇幅更短,代碼更簡潔易懂的,允許自行指定24小時之內的倒計時。指定時,hh是小時數,賦值0-23,mm是分鍾數,賦值0-59,ss是秒數,賦值0-59,但mm和ss通常為0。點擊倒計時的按鈕即可開始。

'窗體內需要建立Command1控制項和Timer1控制項

Dim timeall As Long '計算倒計時的總秒數

Private Sub Command1_Click()
Timer1.Enabled = True
End Sub

Sub Timer1_Timer()
If timeall = 0 Then
Command1.Caption = "00:00:00"
MsgBox "倒計時結束!"
Timer1.Enabled = False
Else
Command1.Caption = Format(timeall \ 3600, "00") & ":" & Format((timeall \ 60) Mod 60, "00") & ":" & Format(timeall Mod 60, "00")
timeall = timeall - 1
End If
End Sub

Private Sub Form_Activate()
Dim hh%, mm%, ss%
hh = 1: mm = 0: ss = 0 '指定倒計時的時間長度
Command1.Caption = Format(hh, "00") & ":" & Format(mm, "00") & ":" & Format(ss, "00")
timeall = hh * 3600& + mm * 60& + ss - 1
Timer1.Enabled = False
Timer1.Interval = 1000
End Sub

『玖』 c#中timer控制項的源碼 以及如何修改源碼使得timer精確度為1毫秒

首先拖一個timer控制項到窗體,名稱為timer1,在窗體的load事件裡面寫:
timer1.Start();//timer1記時開始
timer1.Interval = 1;//即使得timer1精確度為1毫秒
在timer1的tick事件中寫:(選中拖進來的timer控制項,雙擊就出現timer1_Tick事件)
private void timer1_Tick(object sender, EventArgs e)
{
//這里寫每一毫秒做的事
}
試試吧

『拾』 在VS2005(C#)開發環境中,如何用TImer控制項在winfrom窗體上顯示當前日期和時間,源代碼是什麼

timer1.Interval=1000;主要是設置timer1_Tick事件的時間,單位為毫秒

private void timer1_Tick(object sender, System.EventArgs e){
this.Label1.Text=DateTime.Now.DateTime.Now.ToShortTimeString();//得到現在的時間
}

閱讀全文

與timer源碼相關的資料

熱點內容
travelboast安卓怎麼設置路線 瀏覽:51
播放解壓的圖 瀏覽:228
新建一個名為hux的文件夾 瀏覽:532
橋水基金加密貨幣 瀏覽:196
還有什麼好app 瀏覽:152
微軟最慘的源碼 瀏覽:40
上海靈意壓縮機 瀏覽:415
泰拉瑞亞2020最新伺服器ip地址 瀏覽:563
安卓機玩吃雞什麼畫質 瀏覽:873
徒步緩解壓力的視頻 瀏覽:238
圖像演算法口訣 瀏覽:860
人踩什麼解壓 瀏覽:921
php語法檢查命令 瀏覽:330
如何重設伺服器網關 瀏覽:866
世界經濟pdf 瀏覽:110
異或演算法找缺失的數 瀏覽:328
單片機flagt1 瀏覽:487
單片機清理 瀏覽:660
東風景逸空調壓縮機 瀏覽:158
天津程序員炒股 瀏覽:230