searching working, Timer in GUI to refresh status
git-svn-id: svn://anubis/gvsu@45 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
932386c8ee
commit
5c0071a232
@ -10,6 +10,7 @@ public class KaZaGUI extends JFrame
|
||||
private KaZaClient m_client;
|
||||
private KaZaServer m_server;
|
||||
private Thread m_serverThread;
|
||||
private javax.swing.Timer m_timer;
|
||||
|
||||
/* client tab components */
|
||||
private JButton m_browseButton;
|
||||
@ -24,6 +25,7 @@ public class KaZaGUI extends JFrame
|
||||
private JComboBox m_speedCombo;
|
||||
|
||||
/* server tab components */
|
||||
private JLabel m_serverClientsLabel;
|
||||
private JLabel m_serverStatusLabel;
|
||||
private JButton m_serverStartButton;
|
||||
|
||||
@ -49,6 +51,9 @@ public class KaZaGUI extends JFrame
|
||||
|
||||
JPanel serverPanel = getServerPanel();
|
||||
pane.add("Server", serverPanel);
|
||||
|
||||
m_timer = new javax.swing.Timer(1000, m_handler);
|
||||
m_timer.start();
|
||||
}
|
||||
|
||||
private class ActionEventHandler implements ActionListener
|
||||
@ -106,7 +111,8 @@ public class KaZaGUI extends JFrame
|
||||
}
|
||||
else if (e.getSource() == m_searchButton)
|
||||
{
|
||||
if (m_client != null && m_client.connected())
|
||||
if ( m_client != null && m_client.connected() &&
|
||||
(!m_queryField.getText().trim().equals("")) )
|
||||
{
|
||||
Vector<KaZaClient.SearchResult> results =
|
||||
m_client.performSearch(m_queryField.getText());
|
||||
@ -120,6 +126,24 @@ public class KaZaGUI extends JFrame
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (e.getSource() == m_timer)
|
||||
{
|
||||
if (m_server != null)
|
||||
{
|
||||
Object[] clients = m_server.getClientList();
|
||||
String caption = "Clients (" + clients.length + "): ";
|
||||
boolean first = true;
|
||||
for (Object o : clients)
|
||||
{
|
||||
String s = (String) o;
|
||||
if (!first)
|
||||
caption += ", ";
|
||||
caption += s;
|
||||
first = false;
|
||||
}
|
||||
m_serverClientsLabel.setText(caption);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,12 +257,13 @@ public class KaZaGUI extends JFrame
|
||||
m_serverStatusLabel = new JLabel();
|
||||
m_serverStartButton = new JButton("Start MNH Server");
|
||||
m_serverStartButton.addActionListener(m_handler);
|
||||
m_serverClientsLabel = new JLabel("No Clients");
|
||||
|
||||
JPanel serverPanel = new JPanel();
|
||||
serverPanel.setLayout(new BoxLayout(serverPanel, BoxLayout.Y_AXIS));
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
|
||||
p.add(new JLabel("Clients:"));
|
||||
p.add(m_serverClientsLabel);
|
||||
p.add(new Box.Filler(new Dimension(0, 0), new Dimension(Short.MAX_VALUE, 0),
|
||||
new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)));
|
||||
serverPanel.add(p);
|
||||
|
@ -59,14 +59,14 @@ public class KaZaServer implements Runnable
|
||||
{
|
||||
}
|
||||
|
||||
public String[] getClientList()
|
||||
public Object[] getClientList()
|
||||
{
|
||||
Set<String> s;
|
||||
synchronized (m_clientData)
|
||||
{
|
||||
s = m_clientData.keySet();
|
||||
}
|
||||
return (String[]) s.toArray();
|
||||
return s.toArray();
|
||||
}
|
||||
|
||||
private class ClientInfo
|
||||
|
Loading…
x
Reference in New Issue
Block a user