导航:首页 > 源码编译 > 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源码相关的资料

热点内容
安卓手机怎么下老版本抖音 浏览:89
新轩逸经典如何安装安卓应用 浏览:18
php大流量网站 浏览:149
买车app哪个是正规的 浏览:171
python中的class是什么 浏览:202
安卓导航屏如何接灯光线 浏览:691
哪个app能查天津违章 浏览:431
预订汽车票在哪个app 浏览:704
五菱宏光压缩机安装 浏览:460
苹果电脑怎么编译vlc 浏览:107
多传感数据融合算法 浏览:213
access2010压缩 浏览:152
安卓最旧系统是什么 浏览:709
草根到百万程序员 浏览:699
学员招聘app哪个好 浏览:451
感到解压就拍拍手 浏览:113
php404页面代码 浏览:719
php唯一编号 浏览:602
硬盘文件夹没法打开 浏览:446
访问外网的svn服务器地址 浏览:880