[填空题] 请完善程序(程序文件名:Java

[填空题] 请完善程序(程序文件名:Java,第1张

[填空题] 请完善程序(程序文件名:Java

[填空题] 请完善程序(程序文件名:Java_3.java)并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。

题目要求:

程序运行的窗口(如下图所示)。

并在命令行窗口中每隔1秒显示一下当前时间,类似:

At the tone, the time is Tue Dec 29 11:40:12 CST 2009

At the tone, the time is Tue Dec 29 11:40:13 CST 2009

At the tone, the time is Tue Dec 29 11:40:14 CST 2009

在单击“确定”按钮时自动退出程序。

源程序:

import java.awt.*;

import java.awt.event.*;

import java.util.*;

import javax.swing.*;

import javax.swing.Timer;

public class Java_3

public static void main(String[]args)

ActionListener listener=new (1) ();

Timer t=new Timer(1000, listener);

t.start();

JOptionPane.showMessageDialog(null, "Quit program");

System.exit(0);

class

正确答案:

TimePrinter

参考解析:

本程序主要考查Timer构件的事件监听器接口的实现。 由程序看出listener是ActionListener的对象,而后面又定义了实现ActionListener接口的类TimePrinter,所以此处通过TimePrinter的构造方法创建listener。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5470692.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-12
下一篇 2022-12-12

发表评论

登录后才能评论

评论列表(0条)

保存