I have the following code in my constructor for my GUI
search.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//do stuff
}});
The problem was that when I the "//do stuff" runs, it takes a while, and it doesn't let me do anything else. So I made "//do stuff" into a thread, and i开发者_如何学Pythont runs, and I can do other stuff in the GUI at the same time. I wasn't sure if this was threadsafe or not, and if not, how to fix the problem.
The problem is that you were probably blocking the main Swing event thread (the thread that handles things like button clicks). You can read up about it (and one possible solution) on Swing Worker Threads
精彩评论