import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Chatclient extends JFrame {
//-----------------------------------------------
Socket client = new Socket();
Socket server;
private String ip; //hier wird die Variable ip deklariert
JFrame window = new JFrame("Login");
JTextField nickField = new JTextField();
JTextField ipField = new JTextField();
JLabel nickLabel = new JLabel("Nickname:");
JLabel ipLabel = new JLabel("Server-IP:");
JButton loginButton = new JButton("Login");
JTextField inputfield = new JTextField();
JTextArea outputarea = new JTextArea();
//-----------------------------------------------
public Chatclient(){
init();
System.out.println(ip); //hier sollte ip testweise mal ausgegeben werden um zu schauen, ob alles klappt
try{
server = new Socket(ip,80); //und hier soll ip letzten endes rein!
}
catch(IOException e){
}
}
//-----------------------------------------------
public void init(){
window.setSize(200, 125);
window.setResizable(false);
window.setLocationRelativeTo(null);
window.getContentPane().setLayout(new BoxLayout(window.getContentPane(), BoxLayout.Y_AXIS));
window.getContentPane().add(nickLabel);
window.getContentPane().add(nickField);
window.getContentPane().add(ipLabel);
window.getContentPane().add(ipField);
window.getContentPane().add(loginButton);
window.setVisible(true);
loginButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
loginEvent(e);
}
});
}
//-----------------------------------------------
void loginEvent(ActionEvent e){
window.remove(loginButton);
window.remove(nickLabel);
window.remove(ipLabel);
window.remove(nickField);
window.remove(ipField);
window.setTitle("LAN-Chat");
window.setSize(600, 400);
window.setLocationRelativeTo(null);
window.getContentPane().setLayout(new BorderLayout());
window.getContentPane().add("South", inputfield);
window.getContentPane().add("Center", outputarea);
outputarea.setEditable(false);
window.setVisible(true);
ip = ipField.getText(); //hier wird der Variable erst der Wert zugewiesen
}
//-----------------------------------------------
public boolean handleEvent(Event evt){
if(evt.id==Event.WINDOW_DESTROY)
System.exit(0);
return false;
}
//-----------------------------------------------
public static void main(String[] args){
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e){
}
new Chatclient();
}
}