Dienstag, 30. März 2010

First Source-Code (Client)

Here you can see the first state of the project as source-code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;

public class mnChatClient {

JFrame mainframe;
JPanel mainpanel;
JPanel freespace;

JLabel lblUin;
JLabel lblPwd;
JLabel lblLogo;

JTextField txtUin;
JTextField txtPwd;

JButton btnLogin;
JButton btnRegister;

JList lstContactList;

Socket mnChatSocket;
PrintWriter senden;
BufferedReader emp;

String empfangen;


public mnChatClient() {
// Bilder Laden
Image icon = Toolkit.getDefaultToolkit().getImage("image/icon.png");
ImageIcon logo = new ImageIcon("image/logo.png");

// Deklaration aller Variablen
mainframe = new JFrame();
mainpanel = new JPanel();
freespace = new JPanel();
lblUin = new JLabel();
lblPwd = new JLabel();
lblLogo = new JLabel(logo);
txtUin = new JTextField();
txtPwd = new JTextField();
btnLogin = new JButton();
btnRegister = new JButton();
lstContactList = new JList();

// Ab Hier alles was auskommentiert ist wird zum Verbinden/Empfangen und Senden benötigt

/*try {
mnChatSocket = new Socket("127.0.0.1", 30000);
} catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (IOException e1) {
System.exit(0);
}

try {
senden = new PrintWriter(mnChatSocket.getOutputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

try {
emp = new BufferedReader(new InputStreamReader(mnChatSocket.getInputStream()));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}*/

// mainframe
mainframe.setTitle("mnChatClient");
mainframe.setIconImage(icon);
mainframe.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

// Texte der Labels und Buttons setzen
lblUin.setText("UIN");
lblPwd.setText("Passwort");
btnLogin.setText("Anmelden");
btnRegister.setText("Neuen Account anlegen");

// Größer des mainframes und des mainpanels setzen
mainframe.setPreferredSize(new Dimension(230, 800));
mainpanel.setPreferredSize(new Dimension(220, 400));
freespace.setPreferredSize(new Dimension(220, 250));

// Logo in den Freespace laden
freespace.add("Center", lblLogo);

// Alles auf Visible true setzen
mainframe.setVisible(true);
mainpanel.setVisible(true);
freespace.setVisible(true);
lblUin.setVisible(true);
lblPwd.setVisible(true);
lblLogo.setVisible(true);
txtUin.setVisible(true);
txtPwd.setVisible(true);
btnLogin.setVisible(true);
btnRegister.setVisible(true);

// Größe der textfelder einstellen
txtUin.setPreferredSize(new Dimension(210, 24));
txtPwd.setPreferredSize(new Dimension(210, 24));
btnLogin.setPreferredSize(new Dimension(210, 24));
btnRegister.setPreferredSize(new Dimension(210, 24));

// Alle einzelnen Elemente dem mainpanel hinzufügen
mainpanel.add("Center", lblUin);
mainpanel.add("Center", txtUin);
mainpanel.add("Center", lblPwd);
mainpanel.add("Center", txtPwd);
mainpanel.add("Center", btnLogin);
mainpanel.add("Center", btnRegister);

// Alle Panels in den Frame adden
mainframe.add("North", freespace);
mainframe.add("Center", mainpanel);

// OnClose Event
mainframe.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
CloseEverything();
}
});

// Login OnClick Event
btnLogin.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
Login();
}
});

// Größe des Mainframes einstellen
mainframe.pack();
}

public void CloseEverything() {
System.exit(0);
try {
mnChatSocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public void Login() {
senden.println("login|" + txtUin.getText() + "|" + txtPwd.getText());
senden.flush();
try {
empfangen = emp.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(empfangen.equals(new String("1")))
{
HideLogin();
senden.println("get");
senden.flush();
try {
empfangen = emp.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(empfangen);
String [] result = null;
result = empfangen.split("\\|");
for(int i = 0; i < result.length; i++) { } } } public void HideLogin() { txtUin.setVisible(false); txtPwd.setVisible(false); btnLogin.setVisible(false); btnRegister.setVisible(false); lblUin.setVisible(false); lblPwd.setVisible(false); lblLogo.setVisible(false); } public static void main(String[] args) { // TODO Auto-generated method stub @SuppressWarnings("unused") mnChatClient mnChatClient = new mnChatClient(); } }

Freitag, 26. März 2010

Whats the mnChatProject?

Greatings =)

If you ask now: "What the hell is the mnChatProject?" i can answer this question in just a few words.

The mnChatProject is a Project by myself on creating an ICQ-Like Java-based ChatClient and Server.

Why do i want to do this?

It's very simple :)
The normal ICQ-Network is not opensource (that means that you can't edit any files for free).
So i want to create a ICQ-Like Network programm which is opensource and which is written in a language which can be understood by everyone.

Another thing is that ICQ can't encrypt your messages which means that everyone who is listening in your network is able to read your messages.
My client and server are communicating with 64bit encrypted messages which means that you can't read the messages without decrypting them for many days.

Thats the two reasons why i want to programm this project.

On this blog i am going to poste what i have done, what do i want to do and so on ...

Here is a screen of the Client how it looks like at the moment:











So if you are intrested stay tuned =)

ben2k