| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1359 人关注过本帖
标题:Timer错误
只看楼主 加入收藏
北方孤狼
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2008-5-10
结帖率:75%
收藏
 问题点数:0 回复次数:8 
Timer错误
new java.util.Timer( 1000, new BasePanel_Timer_actionAdapter1( this ) ).start();
请问这条语句哪错了
搜索更多相关主题的帖子: Timer java util new start 
2008-06-10 14:32
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
贴出你的全部程序。。这句话看起来没什么问题。。
new BasePanel_Timer_actionAdapter1( this )。。我记得this都是在类里面使用的。。

学习需要安静。。海盗要重新来过。。
2008-06-10 15:37
北方孤狼
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2008-5-10
收藏
得分:0 
package com.

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.
import com.


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-06-10 17:15
北方孤狼
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2008-5-10
收藏
得分:0 
错误提示:
"BasePanel.java": cannot find symbol; symbol  : constructor Timer(int,com.), 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.
import com.
2008-06-10 17:21
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
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);
        }
    }
}

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

学习需要安静。。海盗要重新来过。。
2008-06-10 18:42
北方孤狼
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2008-5-10
收藏
得分:0 
我问的是JAVA
2008-06-10 22:38
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
兄弟我知道啊。。可是我电脑重装了。。只能写点c#看看了。。不好意思啊。。

学习需要安静。。海盗要重新来过。。
2008-06-10 22:59
Estudy
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2007-8-31
收藏
得分:0 
在前面多加行
import java.util.Timer;
试试
貌似是你自己前面没有调用到这个包啊

用程序说话
2008-06-12 22:58
北方孤狼
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2008-5-10
收藏
得分:0 
是javax.swing包里的
2008-06-28 15:28
快速回复:Timer错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018178 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved