| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付买域名,送MP3、MP4
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY买空间,免费送域名(厦门中资源)
共有 337 人关注过本帖
标题:Timer错误
收藏  订阅  推荐  打印 
北方孤狼
Rank: 1
等级:新手上路
帖子:13
积分:234
注册:2008-5-10
Timer错误

new java.util.Timer( 1000, new BasePanel_Timer_actionAdapter1( this ) ).start();
请问这条语句哪错了
搜索更多相关主题的帖子: Timer  java  util  new  start  
2008-6-10 14:32
sunkaidong
Rank: 12Rank: 12Rank: 12
来自:南京师范大学
等级:版主
威望:4
帖子:4131
积分:44881
注册:2006-12-28

贴出你的全部程序。。这句话看起来没什么问题。。
new BasePanel_Timer_actionAdapter1( this )。。我记得this都是在类里面使用的。。

学习需要安静。。海盗要重新来过。。
2008-6-10 15:37
北方孤狼
Rank: 1
等级:新手上路
帖子:13
积分:234
注册:2008-5-10

package com.qcw.netbar1.ui;

import java.text.SimpleDateFormat;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JOptionPane;
import javax.swing.JComboBox;
import java.util.Vector;
import java.util.Date;
import com.qcw.netbar1.MainFrame;
import com.qcw.netbar1.action.BuinessAction;


public class BasePanel extends JPanel{
    protected MainFrame mf;
    protected BuinessAction buinessAction;
    protected JTextField txtTime;
    public BasePanel( MainFrame mFrame ){
        this.mf = mFrame;
        setLayout( null );
    }
    public void startTime( JTextField txtTime ){
        this.txtTime = txtTime;
        new java.util.Timer( (int)1000, new BasePanel_Timer_actionAdapter( this ) ).start();
    }

    /**输出错误提示*/
    public void showError( Exception ex, String title ){
        JOptionPane.showMessageDialog( this, "错误代码:" + ex.getMessage(), title,
                                       JOptionPane.ERROR_MESSAGE );
    }

    /**初始化cobCompterId中的是否可用机器号列表*/
    public void panelInit( JComboBox cobComputerId, boolean is ){
        cobComputerId.removeAllItems();
        buinessAction = new BuinessAction();

        Vector vecComputerId = buinessAction.getUsebleComputerIds( is );
        for( int i = 0; i < vecComputerId.size(); i++ ){
            cobComputerId.addItem( vecComputerId.get( i ) );
        }
        cobComputerId.setSelectedIndex( 0 );
    }

    /**更新当前时间*/
    public void nowTime( ActionEvent e ){
        Date nowTime = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm" );

        String nowStr = sdf.format( nowTime );
        this.txtTime.setText( nowStr );
    }
}

class BasePanel_Timer_actionAdapter implements ActionListener{
    private BasePanel adatee;
    public BasePanel_Timer_actionAdapter( BasePanel adatee ){
        this.adatee = adatee;
    }

    public void actionPerformed( ActionEvent e ){
        adatee.nowTime( e );
    }
}
2008-6-10 17:15
北方孤狼
Rank: 1
等级:新手上路
帖子:13
积分:234
注册:2008-5-10

错误提示:
"BasePanel.java": cannot find symbol; symbol  : constructor Timer(int,com.qcw.netbar1.ui.BasePanel_Timer_actionAdapter), location: class java.util.Timer at line 26, column 9
"BasePanel.java": internal error; cannot instantiate java.util.Timer.<init> at java.util.Timer to () at line 26, column 9

自定义类有
import com.qcw.netbar1.MainFrame;
import com.qcw.netbar1.action.BuinessAction;
2008-6-10 17:21
sunkaidong
Rank: 12Rank: 12Rank: 12
来自:南京师范大学
等级:版主
威望:4
帖子:4131
积分:44881
注册:2006-12-28

using System;
using System.Collections.Generic;
using System.Text;
using System.Timers;
using System.Threading;
namespace ConsoleApplication4
{
    public class Timer1
    {
        public  void T()
        {
            System.Timers.Timer aTimer = new System.Timers.Timer();
            aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            aTimer.Interval = 200;
            aTimer.Enabled = true;
            Console.WriteLine("Press the Enter key to exit the program.");
            Console.ReadLine();
           GC.KeepAlive(aTimer);
        }

        private void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            Console.WriteLine("Hello World!");
        }
    }
    class Program
    {
        public static void Main (string[] args)
        {
            new Timer1().T();
            Thread.Sleep(10000);
        }
    }
}

[ 本帖最后由 sunkaidong 于 2008-6-10 18:57 编辑 ]

学习需要安静。。海盗要重新来过。。
2008-6-10 18:42
北方孤狼
Rank: 1
等级:新手上路
帖子:13
积分:234
注册:2008-5-10

我问的是JAVA
2008-6-10 22:38
sunkaidong
Rank: 12Rank: 12Rank: 12
来自:南京师范大学
等级:版主
威望:4
帖子:4131
积分:44881
注册:2006-12-28

兄弟我知道啊。。可是我电脑重装了。。只能写点c#看看了。。不好意思啊。。

学习需要安静。。海盗要重新来过。。
2008-6-10 22:59
Estudy
Rank: 2
等级:注册会员
帖子:38
积分:500
注册:2007-8-31

在前面多加行
import java.util.Timer;
试试
貌似是你自己前面没有调用到这个包啊

用程序说话
2008-6-12 22:58
北方孤狼
Rank: 1
等级:新手上路
帖子:13
积分:234
注册:2008-5-10

是javax.swing包里的
2008-6-28 15:28
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.108349 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved