Results 1 to 2 of 2
Thread: [SOLVED] [newbie]
- 05-20-2009, 05:54 PM #1
[SOLVED] [newbie]
I'm trying to implement an inner class, however, I'm a bit stuck...
:confused:
Compilation errors:Java Code:TalkingClock.java package homenetwork.bkr.training; import java.awt.Toolkit; import java.awt.event.*; //required for ActionListener import java.util.Date; import javax.swing.Timer; public class TalkingClock { /** A talking clock * @param interval: the interval between messages (milliseconds) * @param beep: true if the clock should beep */ public TalkingClock (int interval, boolean beep) { this.interval = interval; this.beep = beep; } /** * Starts the clock */ public void start() { ActionListener listener = new TimePrinter(); //error: ActionListener cannot be resolved Timer t = new Timer(interval, listener); t.start(); } //the inner class public class TimePrinter 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(); } } private int interval; //this is interval private boolean beep; //this is beep } Test.java package homenetwork.bkr.training; import javax.swing.JOptionPane; public class Test { /** * @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); } }
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
interval cannot be resolved or is not a field
beep cannot be resolved or is not a field
interval cannot be resolved
Syntax error, insert "}" to complete ClassBody
at homenetwork.bkr.training.TalkingClock.<init>(Talki ngClock.java:16)
at homenetwork.bkr.training.Test.main(Test.java:11)Last edited by jon80; 05-20-2009 at 06:29 PM. Reason: update #3
- 05-20-2009, 06:31 PM #2
Similar Threads
-
Another newbie
By PhHein in forum IntroductionsReplies: 0Last Post: 04-22-2009, 01:26 PM -
Newbie Help
By mattkid in forum New To JavaReplies: 4Last Post: 03-25-2009, 04:55 AM -
I am newbie
By Seoplanner in forum IntroductionsReplies: 0Last Post: 11-11-2008, 01:22 PM -
:) newbie...........
By Somitesh Chakraborty in forum IntroductionsReplies: 1Last Post: 08-19-2008, 09:00 AM -
newbie newbie newbie
By krislogy in forum New To JavaReplies: 9Last Post: 08-15-2008, 12:28 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks