Hey :D I'm currently writing a software where users pick out seatings from auditoriums.
The tables will contain seating statuses of auditoriums, which could update quickly.

I was thinking of using a thread to repaint the contents, however as the software could be used by many users on the same moment it may take lots of processing power. How can this be done in the most efficient way?

An SQL database will be used. The interface is made through the Java swing paintComponent( ) method.

Thanks for your help! :D

Separate your GUI code from your DB code. "paintComponent" should never have anything directly to do with a DB (nor should any other part of a GUI component class).

Separate your GUI code from your DB code. "paintComponent" should never have anything directly to do with a DB (nor should any other part of a GUI component class).

Before painting, I must fetch the data from the table, right? I want to re-fetch data and then display it efficiently. The paintComponent function would take the seating statuses from the table and display them individually. When are saying it should never have anything direct with the database, what do you mean precisely? How else could I do it?

Thank you. :)

So you fetch the data in one thread, store the information (in a queue, a list, whatever) and have that thread (using SwingUtilities) trigger a repaint of the component that reads the data in the saved structure.

So you fetch the data in one thread, store the information (in a queue, a list, whatever) and have that thread (using SwingUtilities) trigger a repaint of the component that reads the data in the saved structure.

Oh I see, would this yield a significant difference in performance?

I thought of fetching the data by checking the table in segments rather than as a whole. For example, if there is a change on sector one then refresh that sector. But I'm not sure how to approach this method yet. Any ideas?

By the way, I haven't written the code for this area yet.

The performance of the GUI (as in it won't freeze while it is querying the DB) yes. Also, I would suggest you create a BufferedImage that contains the entire data and the part that queries the DB simply changes only the parts of the BufferedImage that needs to be changed, and then paintComponent need simply copy the Graphics from the BufferdImage to the Graphics to be drawn in the painting.

This article has been dead for over six months. Start a new discussion instead.