Results 1 to 12 of 12
Thread: clock
- 03-28-2012, 09:05 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 6
- Rep Power
- 0
clock
Hi, I have been trying to get a java clock to work, but there is a problem with the number display and I don't know how to fix it. anybody who can help? BTW, I'm using BlueJ.
Here is the code:
public class NumberDisplay
{
private int limit;
private int value;
/**
* Constructor for objects of class NumberDisplay
*/
public NumberDisplay(int roll0verLimit)
{
limit = roll0verLimit;
value = 0;
}
public int getValue()
{
return value;
}
public void setValue(int replacementValue)
{
if((replacementValue >= 0) &&
(replacementValue < limit)){
Value = replacementValue;
}
}
public String getDisplayValue()
{
if(value < 10) {
return "0" + value;
}
else {
return "" + value;
}
}
public void increment()
{
value = (value + 1) % limit;
}
}
- 03-28-2012, 09:11 AM #2
Re: clock
what is the problem and what is Number Display in the above code?
- 03-28-2012, 09:23 AM #3
Member
- Join Date
- Mar 2012
- Posts
- 6
- Rep Power
- 0
Re: clock
Value = replacementValue; this is the problem,
I'm not sure what you mean by what is the number display, i copyed the code from a book. I have a clock display here though if that's what you are asking about:
public class ClockDisplay
{
private NumberDisplay hours;
private NumberDisplay minutes;
private String displayString; //simulate the actual display
public ClockDisplay()
{
hours = new NumberDisplay(24);
minutes = new NumberDisplay(60);
updateDisplay();
}
public ClockDisplay(int hour, int minute)
{
hours = new NumberDisplay(24);
minutes = new NumberDisplay(60);
SetTime(hour, minute);
}
public void timetick()
{
minutes.increment();
if(minutes.getValue() == 0) {//it just rolled over!
hours.increment();
}
updateDisplay();
}
public void setTime(int hour, int minute)
{
hours.setValue(hour);
minutes.setValue(minute);
updateDisplay();
}
public String getTime()
{
return displayString;
}
private void updateDisplay()
{
displayString = hours.getDisplayValue() + ":" +
minutes.getDisplayValue();
}
}
- 03-28-2012, 09:30 AM #4
Re: clock
I think your variable is "value" not "Value", right?
- 03-28-2012, 09:39 AM #5
Member
- Join Date
- Mar 2012
- Posts
- 6
- Rep Power
- 0
Re: clock
thank you, it worked now :D
- 03-28-2012, 09:41 AM #6
Member
- Join Date
- Mar 2012
- Posts
- 6
- Rep Power
- 0
Re: clock
I have an error in the clock display now,
public class ClockDisplay
{
private NumberDisplay hours;
private NumberDisplay minutes;
private String displayString; //simulate the actual display
public ClockDisplay()
{
hours = new NumberDisplay(24);
minutes = new NumberDisplay(60);
updateDisplay();
}
public ClockDisplay(int hour, int minute)
{
hours = new NumberDisplay(24);
minutes = new NumberDisplay(60);
SetTime(hour, minute);
}
public void timetick()
{
minutes.increment();
if(minutes.getValue() == 0) {//it just rolled over!
hours.increment();
}
updateDisplay();
}
public void setTime(int hour, int minute)
{
hours.setValue(hour);
minutes.setValue(minute);
updateDisplay();
}
public String getTime()
{
return displayString;
}
private void updateDisplay()
{
displayString = hours.getDisplayValue() + ":" +
minutes.getDisplayValue();
}
}
the error is: SetTime(hour, minute);
- 03-28-2012, 09:44 AM #7
Re: clock
Which method? which line? What is the error? Detail....Detail...
- 03-28-2012, 09:48 AM #8
Member
- Join Date
- Mar 2012
- Posts
- 6
- Rep Power
- 0
Re: clock
I have an error in the clock display now,
public class ClockDisplay
{
private NumberDisplay hours;
private NumberDisplay minutes;
private String displayString; //simulate the actual display
public ClockDisplay()
{
hours = new NumberDisplay(24);
minutes = new NumberDisplay(60);
updateDisplay();
}
public ClockDisplay(int hour, int minute)
{
hours = new NumberDisplay(24);
minutes = new NumberDisplay(60);
SetTime(hour, minute);
}
public void timetick()
{
minutes.increment();
if(minutes.getValue() == 0) {//it just rolled over!
hours.increment();
}
updateDisplay();
}
public void setTime(int hour, int minute)
{
hours.setValue(hour);
minutes.setValue(minute);
updateDisplay();
}
public String getTime()
{
return displayString;
}
private void updateDisplay()
{
displayString = hours.getDisplayValue() + ":" +
minutes.getDisplayValue();
}
}
The error is marked in red
- 03-28-2012, 09:54 AM #9
Re: clock
what compiler say about the error?
- 03-28-2012, 10:54 AM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: clock
You need to give us the error messages in full, otherwise we're just guessing.
Make it easy for us to help you.
And please use [code] tags [/code] when posting code, for the same reason.Please do not ask for code as refusal often offends.
- 03-28-2012, 01:57 PM #11
Member
- Join Date
- Mar 2012
- Posts
- 6
- Rep Power
- 0
Re: clock
cannot find symbol - method SetTime(int,int); maybe you ment getTime or setTime(int,int)
- 03-28-2012, 02:46 PM #12
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Similar Threads
-
24 hour clock to 12 hour clock project.
By bs3ac in forum New To JavaReplies: 4Last Post: 01-08-2013, 10:10 AM -
help with clock
By Bimz in forum New To JavaReplies: 1Last Post: 09-26-2011, 01:50 PM -
System Clock
By sehudson in forum New To JavaReplies: 2Last Post: 04-12-2011, 03:34 PM -
Clock JavaBean
By dns.gonz in forum AWT / SwingReplies: 9Last Post: 10-08-2010, 04:49 AM -
clock
By ws6driver in forum New To JavaReplies: 1Last Post: 07-31-2009, 04:15 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks