import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;import javax.swing.JOptionPane;
import javax.swing.Timer;public class innerclass { /**
* @param args
*/
public static void main(String[] args) {
TalkingClock clock = new TalkingClock(1000, true);
clock.start(); // keep program running until user selects "Ok"
JOptionPane.showMessageDialog(null, "Quit program?");
System.exit(0);
} class TalkingClock {
public TalkingClock(int timeouts, boolean beep) {
this.timeouts = timeouts;
this.beep = beep;
} public void start() {
ActionListener listener = new TimeListen();
Timer t = new Timer(timeouts, listener);
t.start();
} private int timeouts;
private boolean beep; private class TimeListen implements ActionListener {
public void actionPerformed(ActionEvent event) {
Date now = new Date();
System.out.println("At the tone, the time is " + now);
if (beep)
Toolkit.getDefaultToolkit().beep();
}
}
}}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;import javax.swing.JOptionPane;
import javax.swing.Timer;public class innerclass { /**
* @param args
*/
public static void main(String[] args) {
TalkingClock clock = new TalkingClock(1000, true);
clock.start(); // keep program running until user selects "Ok"
JOptionPane.showMessageDialog(null, "Quit program?");
System.exit(0);
} class TalkingClock {
public TalkingClock(int timeouts, boolean beep) {
this.timeouts = timeouts;
this.beep = beep;
} public void start() {
ActionListener listener = new TimeListen();
Timer t = new Timer(timeouts, listener);
t.start();
} private int timeouts;
private boolean beep; private class TimeListen implements ActionListener {
public void actionPerformed(ActionEvent event) {
Date now = new Date();
System.out.println("At the tone, the time is " + now);
if (beep)
Toolkit.getDefaultToolkit().beep();
}
}
}}
解决方案 »
- 求帮忙,java画图问题
- 如何设置JAVA中对话框的文字字体,颜色?
- 高分求解高挑战问题
- 请教一个多线程的问题
- G729/G723.1编码后的声音文件,用什么软件可以播放?
- 谁有张孝祥的java视频教程啊能否给小弟发一个~~~~~~~
- 汉字显示问题。在线等
- java网络中传递对象
- 高校计算机专业联盟论坛,欢迎您的加盟!http://tech.94ni.com
- jscrollpanel中放置了jtable,请问如何在程序中能够控制滚动条的位置,比如先setselectioninterval到下一屏的某一行中,然后滚动条也滚到相应位置?
- 请高手指导:struts跳转后的问题
- 关于appletviewer不能显示网页中的applet?
No enclosing instance of type innerclassTest is accessible. Must qualify the allocation with an enclosing instance of type innerclassTest (e.g. x.new A() where x is an instance of innerclassTest).
这是错误...
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;public class InnerClassTest
{
public static void main(String[] args)
{
TalkingClock clock = new TalkingClock(1000, true);
clock.start();
JOptionPane.showMessageDialog(null, "Quit program?");
System.exit(0);
}
}
class TalkingClock
{
public TalkingClock(int timeouts, boolean beep)
{
this.timeouts= timeouts;
this.beep = beep;
}
public void start()
{
ActionListener listener = new TimeListen ();
Timer t = new Timer(timeouts, listener);
t.start();
} private int timeouts;
private boolean beep; private class TimeListen implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
Date now = new Date();
System.out.println("At the tone, the time is " + now);
if (beep) Toolkit.getDefaultToolkit().beep();
}
}
}
这样会出错吗?
InnerClass outer =new InnerClass();
InnerClass.TalkingClock clock = outer.new TalkingClock(1000,true);
clock.start(); // keep program running until user selects "Ok"
或者不使用内部类 ,把TalkingClock拿到外面,OK
No enclosing instance of type innerclassTest is accessible. Must qualify the allocation with an enclosing instance of type innerclassTest (e.g. x.new A() where x is an instance of innerclassTest).
这是错误...就是这个 第一个报的 第二个正确运行