I'm developing a program that prompt the user to select time for his/her stay on the hotel, and i'm using a JSpinner to do this. But i don't know how to extract time from JSpinner and insert it to MySQL database on the time format. Please help and give me some example. Sorry for noob question
JSpinner#getValue
) and convert it to a time object. The conversion will depend on what data is stored in your spinner model. The SpinnerDataModel
might be an interesting model to back your spinner, Runnable
and using a new Thread
to execute this. Examples can be found in the JSpinner
tutorial . For example (copy pasted from that tutorial) if you use the SpinnerDateModel
, you can use
SpinnerDateModel dateModel = ...;
...
setSeasonalColor(dateModel.getDate());
which allows you to retrieve a Date
object directly from the model, without a conversion.
Further, the Swing concurrency tutorial explains why you should update your db on a background thread. It also contains code snippets on how to execute something on a background thread from the EDT. But in case you simply need to update the db, and nothing in the UI must be updated, there is not much need to opt for the SwingWorker
class which is used in that sample code. In that case, you can simply start a new Thread
as I stated above. The net is filled with examples on how to achieve that.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.