I am working on a project that involves GUI. On the JFrame I have several JButtons that perform specific actions when clicked. Now the problem is, with the code I wrote, every time the buttons are clicked, they generate a new thread. I do this because I learned that JFrame would freeze if everything happens on the same thread, but I feel that creating that many threads isn't very efficient. Although the program functions pretty well for now, I still hope to cut off redundant pieces from the program. Should put all the GUI things in an "InvokeLater"? But aren't jButtons also in the GUI? Some actions the these Button perform required an existing GUI, so it's hard to separate them... Any ideas? Here is an example of the button.
JButton buttonA4= new JButton("Deact Crew");
buttonA4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Thread hilo = new Thread(new Runnable()
{
public void run() {
DinnerList.deactivateGroup(tempJobCrew.getCrews());
studentTable.repaint();
}
});
hilo.start();
}
});