当前位置: 代码迷 >> Java相关 >> Timer错误
  详细解决方案

Timer错误

热度:274   发布时间:2008-06-10 14:32:22.0
Timer错误
new java.util.Timer( 1000, new BasePanel_Timer_actionAdapter1( this ) ).start();
请问这条语句哪错了
搜索更多相关的解决方案: Timer  java  util  new  start  

----------------解决方案--------------------------------------------------------
贴出你的全部程序。。这句话看起来没什么问题。。
new BasePanel_Timer_actionAdapter1( this )。。我记得this都是在类里面使用的。。
----------------解决方案--------------------------------------------------------
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 );
    }
}
----------------解决方案--------------------------------------------------------
错误提示:
"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;
----------------解决方案--------------------------------------------------------
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]]
----------------解决方案--------------------------------------------------------
我问的是JAVA
----------------解决方案--------------------------------------------------------
兄弟我知道啊。。可是我电脑重装了。。只能写点c#看看了。。不好意思啊。。
----------------解决方案--------------------------------------------------------
在前面多加行
import java.util.Timer;
试试
貌似是你自己前面没有调用到这个包啊
----------------解决方案--------------------------------------------------------
是javax.swing包里的
----------------解决方案--------------------------------------------------------
  相关解决方案