Select Git revision
http-server.c
StartScreen.java 2.06 KiB
package GUI;
import client.Client;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class StartScreen {
private JPanel panel1;
private JTextArea information;
private JTextField textField1;
private JButton joinButton;
private JTextField textField2;
JFrame frame;
private Client client;
public StartScreen(Client client)
{
this.client = client;
}
// public static void main(String[] args) {
// new StartScreen().go();
// }
ActionListener actionListener = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == joinButton)
{
String serverAddress = textField2.getText();
String userName = textField1.getText();
int connectionStatus = client.connect(userName, serverAddress);
if( connectionStatus == 1 )
{
frame.setVisible(false);
frame.dispose();
client.startApplication();
}
else if( connectionStatus == 2 )
{
showErrorMessage("Duplicate username: Please enter a new username");
}
else if( connectionStatus == 3 )
{
showErrorMessage("Cannot connect to server: Please check the server address");
}
else
{
showErrorMessage("Unknown Connection Status");
}
}
}
};
public static void showErrorMessage(String message)
{
JOptionPane.showMessageDialog(null,
message, "Error", JOptionPane.ERROR_MESSAGE);
}
public void go()
{
joinButton.addActionListener(actionListener);
frame = new JFrame("StartScreen");
frame.setContentPane(panel1);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}