Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Swing and mutlithreading  RSS feed

 
Dave Robbins
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

Not sure where this goes
It's got Swing, sockets and threads

I'm building a client/server pair
The server needs to be multithreaded to talk to mutiple clients
I've got it (the server) up and running as a console app, no problem
Now I'd like to move it into a Swing GUI application so I can monitor what's going on
The server is built along the lines of Sun's using sockets tutorial
I have a server class which extends Thread with a run method like this





It sits and waits for incoming connections from a client, and when one comes in it spawns a new thread to handle it
If I create an instance of this class in my GUI application I get no GUI
The server seems to be working fine, a client can connect to it, but no GUI
In playing with it I've just now realized I can comment out the lines that wait for an incoming connection and it still doesn't work. It seem to be the while loop that's making things break. Do I need to set the priority of the thread or something?
Ideas?
Pointers to info on mixing Swing and threads?

TIA
Dave
 
Dave Robbins
Ranch Hand
Posts: 131
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent catch, Dave! It took me a long time to find that sucker. Since then I've learned that a Google for "java anytopic tutorial" almost always gets a winner from Sun or some university course. I have a little program that runs any number of worker threads. As it starts each one it creates a new subpanel for status display and hooks up a pub-sub connection so updates notify an object that uses the Swing invoke later thing.
 
Dave Robbins
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea, google rules
I've already re-written my code using SwingWorker
It's SWEET!!
Why in the world isn't that part of the jdk?
I woulda never figured it out on my own

Dave
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!