J
Jan Danielsson
Hello all,
In OS/2 whenever I use an SQL database in a GUI program I use a separate
thread to collect data. This thread also preprares all the data
structures for a GUI widget that is about to display the data. Then,
when all preparations has been done, I would use WinSendMsg()
(synchronous) or WinPostMsg() (asynchronous) to let the main application
thread (where the GUI runs) know about the widget data. This means that
the GUI is "never" (never noticably) locked.
How would I do that in Java? AFAIK, it doesn't use message queues, at
least not visible, and in the same form that OS/2 and Windows uses.
This is what I know:
I can implement a thread using "Runnable"..
---------------------------
class GetMonthlyTable implements Runnable {
private Connection con;
Vector tableRows = new Vector();
GetMonthlyTable(Connection con) {
this.con = con;
}
public void run() {
Q = "SELECT ID,DATE,AMOUNT,DESCRIPTION FROM TRANSACTIONS";
...
ResultSet rs = stmt.executeQuery(Q);
while(rs.next())
{
// Add table row to Vector tableRows
}
}
}
---------------------------
That would ensure that I won't be holding up the GUI with my database
operations, now I need to get the tableRows reference to the GUI's main
thread (where I store a Vector referece which is used for all the JTable
data).
If I pass along a reference to JTable, I can easily set the rableRows
instance variable using a "set*()"-method. However, once this is done,
how do I "signal" (analogous to passing a message) to the main GUI
thread that it has new data, and the widget should be updated? AFAIK,
the GUI API:s aren't thread safe -- all GUI operations should be
performed on the GUI thread. ...or should that be: All GUI APIs are
executed on the main thread? (if so, how are asyncronous calls to the
GUI thread made?)
Also, could someone please explain what Swing is, or more specifically,
what it is not? As far as I can understand, Swing is "new" in the sense
that there is another GUI toolkit which was in Java 1.0, and that is
still a part of Java. How do I know which I am using? Are they entirely
separate (as in they can't be mixed?). I am using JTable, GridBagLayout,
JComboBox, et al. -- does that mean that automatically I'm using Swing?
In OS/2 whenever I use an SQL database in a GUI program I use a separate
thread to collect data. This thread also preprares all the data
structures for a GUI widget that is about to display the data. Then,
when all preparations has been done, I would use WinSendMsg()
(synchronous) or WinPostMsg() (asynchronous) to let the main application
thread (where the GUI runs) know about the widget data. This means that
the GUI is "never" (never noticably) locked.
How would I do that in Java? AFAIK, it doesn't use message queues, at
least not visible, and in the same form that OS/2 and Windows uses.
This is what I know:
I can implement a thread using "Runnable"..
---------------------------
class GetMonthlyTable implements Runnable {
private Connection con;
Vector tableRows = new Vector();
GetMonthlyTable(Connection con) {
this.con = con;
}
public void run() {
Q = "SELECT ID,DATE,AMOUNT,DESCRIPTION FROM TRANSACTIONS";
...
ResultSet rs = stmt.executeQuery(Q);
while(rs.next())
{
// Add table row to Vector tableRows
}
}
}
---------------------------
That would ensure that I won't be holding up the GUI with my database
operations, now I need to get the tableRows reference to the GUI's main
thread (where I store a Vector referece which is used for all the JTable
data).
If I pass along a reference to JTable, I can easily set the rableRows
instance variable using a "set*()"-method. However, once this is done,
how do I "signal" (analogous to passing a message) to the main GUI
thread that it has new data, and the widget should be updated? AFAIK,
the GUI API:s aren't thread safe -- all GUI operations should be
performed on the GUI thread. ...or should that be: All GUI APIs are
executed on the main thread? (if so, how are asyncronous calls to the
GUI thread made?)
Also, could someone please explain what Swing is, or more specifically,
what it is not? As far as I can understand, Swing is "new" in the sense
that there is another GUI toolkit which was in Java 1.0, and that is
still a part of Java. How do I know which I am using? Are they entirely
separate (as in they can't be mixed?). I am using JTable, GridBagLayout,
JComboBox, et al. -- does that mean that automatically I'm using Swing?