添加corejava第11版源码
日期:2019-5-22
This commit is contained in:
1 parent
e199db7c36
commit
af9d779c86
525 files changed
+91425
No files matched your search
@@ -0,0 +1,51 @@
|
||||
package anonymousInnerClass;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.time.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* This program demonstrates anonymous inner classes.
|
||||
* @version 1.12 2017-12-14
|
||||
* @author Cay Horstmann
|
||||
*/
|
||||
public class AnonymousInnerClassTest
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
var clock = new TalkingClock();
|
||||
clock.start(1000, true);
|
||||
|
||||
// keep program running until the user selects "OK"
|
||||
JOptionPane.showMessageDialog(null, "Quit program?");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A clock that prints the time in regular intervals.
|
||||
*/
|
||||
class TalkingClock
|
||||
{
|
||||
/**
|
||||
* Starts the clock.
|
||||
* @param interval the interval between messages (in milliseconds)
|
||||
* @param beep true if the clock should beep
|
||||
*/
|
||||
public void start(int interval, boolean beep)
|
||||
{
|
||||
var listener = new ActionListener()
|
||||
{
|
||||
public void actionPerformed(ActionEvent event)
|
||||
{
|
||||
System.out.println("At the tone, the time is "
|
||||
+ Instant.ofEpochMilli(event.getWhen()));
|
||||
if (beep) Toolkit.getDefaultToolkit().beep();
|
||||
}
|
||||
};
|
||||
var timer = new Timer(interval, listener);
|
||||
timer.start();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user