user2148736
user2148736

Reputation: 1323

How to actualize JProgressBar in Swing application?

In my school project (simple Swing application) I have a class that does some computational stuff (trains neural network) and this computation runs in iterations. I would like to actualize some GUI components (JProgressBar) and show to the user what iteration is actually processed (e.g. 100/10000).

I would like to ask how to accomplish it with respect to application design. I don't want to mix computation code with code for refreshing GUI components. Is it a proper situation to use Observer design pattern? If so, I can set my computation class as an observable object and register observer - class that will actualize JProgressBar.

Is it ok or is there some better way how to achieve it?

Upvotes: 0

Views: 60

Answers (1)

Kieper
Kieper

Reputation: 315

Depending on how much time your computation takes, you should also consider SwingWorker. Also having observer or some kind of handler which will update gui is good idea.

Upvotes: 2

Related Questions