• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Status Bar Updating

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get the status bar for this program to update with the tickets that are being purchased. However, it only changes the to updated color once all the tickets are sold and I need it to gradually increase the color as the tickets are sold not change the whole bar to that color.

Heres my status bar class:


And then my TicketCounter class:

 
Rancher
Posts: 3094
24
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't make the "status" variable public.

Standard class design is to make a method like:


So now in your application code you invoke the setStatus(...) method with your status.

It is now the repsonsibility of the StatusBar class to repaint() itself when a property of the class is changed (not the class that invokes the method).

Using this approach you can now add a System.out.println(status) statement to your setStatus(...) method to verify 1) the method is invoked and 2) you pass the value you are expecting to pass.

If the problem isn't solved then you add debug code to the paintComponent(...) method to display the value of the "filled" variable.

This is how debugging work. Don't assume your code is correct. Display the value of all your variables to make sure they are correct.
 
Rancher
Posts: 3623
34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One issue might be integer division.  status/100 will be 0 until status = 100.  Make status a double  or divide by 100.0 to do floating division.

Display the value of all your variables to make sure they are correct.


That is also true for expressions.  Printlng status/100 would show what is happening.
 
Nathan Montgomery
Ranch Hand
Posts: 48
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:One issue might be integer division.  status/100 will be 0 until status = 100.  Make status a double  or divide by 100.0 to do floating division.

Display the value of all your variables to make sure they are correct.


That is also true for expressions.  Printlng status/100 would show what is happening.


Made status a double and works perfectly, thanks!
 
Rob Camick
Rancher
Posts: 3094
24
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Made status a double and works perfectly, thanks!


Sigh. That's what you took out of all this?

Give somebody a fish they eat for a day. Teach somebody to fish and they eat for life.
 
Norm Radder
Rancher
Posts: 3623
34
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Give somebody a fish they eat for a day. Teach somebody to fish and they eat for life.

I agree.
Sorry to have given away the answer.  It has happened to me many times on this site.  A lot of helpers here are not into helping OPs learn how to debug their code.  They seem more interested in providing a solution.
 
Ranch Hand
Posts: 71
4
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Norm Radder wrote:

Give somebody a fish they eat for a day. Teach somebody to fish and they eat for life.

I agree.
Sorry to have given away the answer.  It has happened to me many times on this site.  Most helpers here are not into helping OPs learn how to debug their code.  They seem more interested in providing a solution.


The other issue is that neither mods nor most new users like to hear the reality: There're some basics one have to learn about how to use a computer before starting to tell it what to do - already got banned with a few accounts cause some mod took it personal as I directly confronted someone to better learn some basics upfront before take another approach at the current topic. Yes, I'm sorry for doing it and to be the harsh one directly say what first comes to my mind - but some just don't get otherwise.
How often we encounter topic a student needs "urgent" help for some topic s/he had two weeks of time already and all knowledge thaught in class - and most of them start with "teacher didnt taught us". Sorry, but blame others cause one self likes to party rather taking learning serious - it's exactly them who need this told directly ibto thier face:
1) teachers will always teach the needed basics - it's up to the student to keep asking until s/he fully got them - you will never get some homework about some topic not already had in class - pay attention!
2) students aren't kids - most are around 20 or even older - everyone of them chose the courses themselfs - and it's expected by someone old enough to have children to have the will and is able to get some information by yourself - if you prefer to party instead of learn you only deserve to fail
3) today most new users only looking for fast answers instead of search for help to learn why it's still an integer if you only devide integers - so, if someone seeks for a short solution I provide it - I just don't care if s/he fails the next test cause s/he didn't understood the reason - same as your own health: if I have a cold I don't care about the cause (mostly a viral infection) and get rid of it but rather only I want to get rid of the symptoms like caughing or sneezing
4) the above combined: the unwillingness to try to find an explanation yourself: most beginners topics are so often discussed each and every day - why not try to search for how to setup your environment before askin the same question again for the 100th time? well, cause some even lack the ability to use google to find an answer - these poeple should already stop right there - they can't even use thier computer - but now want to tell it what to do? - kthxbai - that's how chernobyl happend: someone not knowing the reactor forced it to do something against every rule made up by some who knew it better and already 3 failed tests for the other reactors

I won't even start with politics - but whoever voted for this man wearing a guine pig as hair top - feel free to be my guest when kim hits the button ...
 
Marshal
Posts: 66637
251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Kristina Hansen wrote:. . . whoever voted for this man wearing a guine pig as hair top . . .

Which one? I am in UK.
 
I am going down to the lab. Do NOT let anyone in. Not even this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!