96 lines
3.1 KiB
Java
96 lines
3.1 KiB
Java
|
|
import java.awt.*;
|
|
import java.awt.event.*;
|
|
import javax.swing.*;
|
|
|
|
public class KaZaGUI extends JFrame
|
|
{
|
|
private JButton m_browseButton;
|
|
private JButton m_connectButton;
|
|
private JButton m_closeButton;
|
|
private JTextField m_shareFolderField;
|
|
|
|
public KaZaGUI()
|
|
{
|
|
super("Josh's KaZa application for CS654!");
|
|
|
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
|
setSize(600, 400);
|
|
setVisible(true);
|
|
|
|
ActionEventHandler handler = new ActionEventHandler(this);
|
|
|
|
Container c = getContentPane();
|
|
JTabbedPane pane = new JTabbedPane();
|
|
c.add(pane);
|
|
|
|
JPanel clientPanel = new JPanel();
|
|
clientPanel.setLayout(new BoxLayout(clientPanel, BoxLayout.Y_AXIS));
|
|
JPanel p = new JPanel();
|
|
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
|
|
p.add(new JLabel("User name: "));
|
|
p.add(new JTextField());
|
|
clientPanel.add(p);
|
|
p = new JPanel();
|
|
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
|
|
p.add(new JLabel("Connection speed: "));
|
|
p.add(new JTextField());
|
|
clientPanel.add(p);
|
|
p = new JPanel();
|
|
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
|
|
p.add(new JLabel("Shared folder: "));
|
|
m_shareFolderField = new JTextField();
|
|
p.add(m_shareFolderField);
|
|
m_browseButton = new JButton("...");
|
|
m_browseButton.addActionListener(handler);
|
|
p.add(m_browseButton);
|
|
clientPanel.add(p);
|
|
clientPanel.add(Box.createVerticalGlue());
|
|
clientPanel.add(new Box.Filler(new Dimension(0, 0),
|
|
new Dimension(0, Short.MAX_VALUE),
|
|
new Dimension(Short.MAX_VALUE,
|
|
Short.MAX_VALUE)));
|
|
p = new JPanel();
|
|
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
|
|
m_connectButton = new JButton("Connect");
|
|
m_connectButton.addActionListener(handler);
|
|
p.add(m_connectButton);
|
|
m_closeButton = new JButton("Close");
|
|
m_closeButton.addActionListener(handler);
|
|
p.add(m_closeButton);
|
|
clientPanel.add(p);
|
|
pane.add("Client", clientPanel);
|
|
|
|
JPanel transferPanel = new JPanel(new BorderLayout());
|
|
pane.add("Transfers", transferPanel);
|
|
|
|
JPanel serverPanel = new JPanel(new BorderLayout());
|
|
pane.add("Server", serverPanel);
|
|
}
|
|
|
|
private class ActionEventHandler implements ActionListener
|
|
{
|
|
private KaZaGUI m_kg;
|
|
|
|
public ActionEventHandler(KaZaGUI kg)
|
|
{
|
|
m_kg = kg;
|
|
}
|
|
|
|
public void actionPerformed(ActionEvent e)
|
|
{
|
|
if (e.getSource() == m_browseButton)
|
|
{
|
|
JFileChooser fc = new JFileChooser();
|
|
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
|
fc.showOpenDialog(m_kg);
|
|
m_shareFolderField.setText(fc.getSelectedFile().getAbsolutePath());
|
|
}
|
|
else if (e.getSource() == m_closeButton)
|
|
{
|
|
System.exit(0);
|
|
}
|
|
}
|
|
}
|
|
}
|