I have a TCP Server with multithreading and can handle it from the cli.
Now I want to write a GUI for it so that I can easily start, watch, manage and quit specific instances of that multithreaded server. First I thought on JTable and thats also my first question:
Is it a good way (or even possible) to handle multiple serverthreads on multiple sockets (not threads) inside a JTable and am I be able to send data to it to update individual rows depending on socketactivities? I mean when every row stands for a running serverthread, the user should be able to click on it, start a new one (that will be added to the list) see the socketstatus (whatever that will be) in a field, see how many clients are connected and even be able to stop a specific thread throu that table?
My second question is:
When I start implementing it the way I described above, what happens to the jtable and the running threads when I update the active JPanel with another interface and switch back again? For example, I have one interface for an overview about all instances and another one for details on a single instance of it. Will all threads be interrupted or can they communicate to the Table after that again? Or is it better to use a cardLayout?
When I change the card on a cardlayout and on this card is something running (for ex. A JTable with running socketthreads) will they be interrupted or stopped or can i update statusdata in the JTable anymore? So the sockets should be able to write and update data to the table over all.
And now my last question, thanks for reading so long. while trying to discover answers for all of my questions above, I tried a simple JPanel switching Frame with a JTextarea on each Panel that writes 100 lines with a 1000ms break between. Then I wanted to switch the panels and see if that task was interrupted. Unfortunately, I can't even bring this to work.
In an external class MyPanel I am initiating a JPanel with individual configuration and add it to the main frame.
The for loop is just for testing:
class MyPanel extends JPanel {
public static JTextArea tArea;
public MyPanel(String config) {
JButton testButton = new JButton(config);
add(testButton);
tArea = new JTextArea();
JScrollPane scroll = new JScrollPane(tArea);
add(scroll, BorderLayout.CENTER);
for (int i = 0 ; i < 50 ; i ++ ) {
tArea.append("test \n") ;
try { Thread.sleep(2000); } catch(InterruptedException ie) {}
}
setVisible(true);
revalidate();
repaint();
}
}
But I think, that is completely wrong because I call it before revalidate and repaint :( And inside the mainframe I want to initiating it that way:
JMenuItem menuItem = new JMenuItem("Test");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
MyPanel dynamicPanel = new MyPanel("Test");
contentContainer.removeAll();
contentContainer.add(dynamicPanel);
contentContainer.revalidate();
contentContainer.repaint();
}
});