This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing Calender, ComboBox and timer questions

 
sean beacham
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im trying to code a program at the minute which when you set specific times to switch something on in this case a boiler (theretically)

So i need to have a switch on time and switch off time therefore i have used JComboBoxes then used a string array to hold the value for hours and minutes and then converted them into an interger for to use for if statements.

Now im quite stumped on what to do next i know i have to compare the times together with a realtime clock therefore i guess using the swing calender function???

So far i have come up with this code but even the simple if statement fails me it always reads ON even trying different cominations of >= <= == etc.... im a bit stuck how to compare the times. I would also like it to keep checking to see whether the boiler should still be active therefore i guess putting the whole thing into an infinate for loop?

Any tips or ideas would be greatful i have embedded my code for you to all look at also i am not the best programmer i will admit that and i have limited knowledge but any help would be helpful.

 
Abhilash Etikala
Ranch Hand
Posts: 38
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use GregorianCalendar() to get the current time and compare with the selected time...

Here is the sample code. to get time..


Since,String arrays contains the integer values you can use the below code to initialize the combo box..



hope this helps u...
 
sean beacham
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhilash Etikala wrote:Use GregorianCalendar() to get the current time and compare with the selected time...

Here is the sample code. to get time..


Since,String arrays contains the integer values you can use the below code to initialize the combo box..



hope this helps u...


i dont know what this code does!

i know the first 3 lines get the current hour and minute thats fine.

ive started to write some code so far so good.... a few more tips and i think i should get thre by tomorrow

 
Darryl Burke
Bartender
Posts: 5147
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use parentheses for logical grouping of conditional expressions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic