CACLient

Client:

import java.net.*;

import javax.swing.*;

import java.io.*;

class ChatClient{

publicstaticvoid main(String arhs[]){

try{

Socket s =new Socket("10.2.10.170", 55555);

new Client(s).start();

new Client1(s).start();

}

catch(Exception e){}

}

}

class Clientextends Thread{

Socket soc;

public Client(Socket s){

soc = s;

}

publicvoid run(){

JFrame get =new JFrame("Get tet");

JTextArea txt =new JTextArea();

get.getContentPane().add(txt);

get.pack();

try{

while(true){

BufferedReader in =new BufferedReader(new InputStreamReader(soc.getInputStream()));

txt.append(in.readLine());

}

}

catch(Exception e){}

}

}

class Client1extends Thread{

Socket soc;

public Client1(Socket s){

soc = s;

}

publicvoid run(){

//erics code

Talker t =new Talker(this);

}

publicvoid send(String s){

try{

PrintWriter out =new PrintWriter(soc.getOutputStream(),true);

out.println(s);

}

catch(Exception e){}

}

}

Gui

[code]

public class Talker extends JFrame implements WindowListener,ActionListener {

JButton send = new JButton("Send");

JTextPane myPane = new JTextPane();

Client1 b;

public Talker(Client1 a) {

super("Send");

b =a;

send.addActionListener(this);

myPane.setSize(new Dimension(300,200));

JScrollPane myBar = new JScrollPane(myPane);

this.getContentPane().add(myBar, BorderLayout.CENTER);

this.getContentPane().add(send,BorderLayout.SOUTH);

addWindowListener(this);

this.pack();

this.setVisible(true);

}

public void actionPerformed(ActionEvent e) {

Object source = e.getSource();

if (source==send){

b.send(myPane.getText());

//Send info

}

}

public void windowClosing(WindowEvent e) {

setVisible(false);

dispose();

System.exit(0);

}

public void windowClosed(WindowEvent e) {}

public void windowDeactivated(WindowEvent e) {}

public void windowActivated(WindowEvent e) {}

public void windowDeiconified(WindowEvent e) {}

public void windowIconified(WindowEvent e) {}

public void windowOpened(WindowEvent e) {}

}

[/code

[4643 byte] By [EagleEye101] at [2007-9-22]
# 1

import java.net.*;

import javax.swing.*;

import java.io.*;

import java.awt.*;

import java.awt.event.*;

class ChatClient {

public static void main(String arhs[]) {

try {

Socket s = new Socket("10.2.10.170", 55555);

new Client(s).start();

new Client1(s).start();

}

catch(Exception e) {}

}

}

class Client extends Thread{

Socket soc;

public Client(Socket s) {

soc = s;

}

public void run() {

JFrame get = new JFrame("Get text");

JTextArea txt = new JTextArea();

JScrollPane mySp = new JScrollPane(txt);

mySp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

mySp.setPreferredSize(new Dimension(250, 145));

mySp.setMinimumSize(new Dimension(10, 10));

get.getContentPane().add(mySp);

get.pack();

get.setVisible(true);

try {

while(true) {

BufferedReader in = new BufferedReader(new InputStreamReader(soc.getInputStream()));

txt.append(in.readLine());

}

}

catch(Exception e) {}

}

}

class Client1 extends Thread {

Socket soc;

public Client1(Socket s) {

soc = s;

}

public void run() {

Talker t = new Talker(this);

}

public void send(String s) {

try {

PrintWriter out = new PrintWriter(soc.getOutputStream(), true);

out.println(s);

}

catch(Exception e) {}

}

}

class Talker extends JFrame implements WindowListener,ActionListener {

JButton send = new JButton("Send");

JTextPane myPane = new JTextPane();

Client1 b;

public Talker(Client1 a) {

super("Send");

b =a;

send.addActionListener(this);

myPane.setSize(new Dimension(300,200));

JScrollPane textScrollPane = new JScrollPane(myPane);

textScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

textScrollPane.setPreferredSize(new Dimension(250, 145));

textScrollPane.setMinimumSize(new Dimension(10, 10));

this.getContentPane().add(textScrollPane, BorderLayout.CENTER);

this.getContentPane().add(send,BorderLayout.SOUTH);

addWindowListener(this);

this.pack();

this.setVisible(true);

}

public void actionPerformed(ActionEvent e) {

Object source = e.getSource();

if (source==send){

b.send(myPane.getText());

}

}

public void windowClosing(WindowEvent e) {

setVisible(false);

dispose();

System.exit(0);

}

public void windowClosed(WindowEvent e) {}

public void windowDeactivated(WindowEvent e) {}

public void windowActivated(WindowEvent e) {}

public void windowDeiconified(WindowEvent e) {}

public void windowIconified(WindowEvent e) {}

public void windowOpened(WindowEvent e) {}

}

chhasx at 2007-7-7 > top of java,Developer Tools,Debugging and Profiling Tool APIs...
# 2
System.out.println(System.getProperty("user.name"));
chhasx at 2007-7-7 > top of java,Developer Tools,Debugging and Profiling Tool APIs...
# 3

import java.net.*;

import java.io.*;

import javax.swing.*;

class CSRClient {

public static void main(String args[]) {

try {

Socket s = new Socket("10.2.10.157", 6200);

//message box for pwd

//project name

String pwd = JOptionPane.showInputDialog("Enter your password: ");//"eric:blah";

BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));

PrintWriter out = new PrintWriter(s.getOutputStream(), true);

out.println(System.getProperty("user.name") + ":" +pwd);

String answer = in.readLine();

System.out.println(answer);

if(answer.equals("BAD USER")) {

System.out.println("Invalid Password or user");

System.exit(0);

}

String projectname = JOptionPane.showInputDialog("Enter your project name: ");

out.println(projectname);

//do error check with server

answer = in.readLine();

System.out.println(answer);

if (answer.equals("BAD PROJECT")){

System.exit(0);

}

String choice = JOptionPane.showInputDialog("Enter your choice (Upload, Download): ");

choice = choice.toUpperCase();

out.println(choice);

if(choice.equals("DOWNLOAD")){

answer = in.readLine();

int num = Integer.parseInt(answer);

String[] names = new String[num];

String[] filedat = new String[num];

if (num == 1){

System.out.println("Recieving " + num + " file");

}

else{

System.out.println("Recieving " + num + " files");

}

for(int i = 0; i < names.length; ++i) {

names[i] = in.readLine();

}

for(int i = 0; i < filedat.length; ++i) {

String input = "";

one: while (true){

String temp = in.readLine();

if (temp.equals("END OF FILE")){

input = input.substring(0, input.length()-2);

break one;

}

temp += System.getProperty("line.separator") ;

input += temp;

}

filedat[i] = input;

}

File g = new File(projectname);

g.mkdir();

for(int i = 0; i < num; ++i) {

File f = new File(projectname + File.separatorChar + names[i]);

FileOutputStream fout = new FileOutputStream(f);

fout.write(filedat[i].getBytes());

fout.close();

}

}

else if (choice.equals("UPLOAD")){

JFileChooser chooser = new JFileChooser();

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

int returnVal = chooser.showOpenDialog(new JFrame());

File f = null;

if(returnVal == JFileChooser.APPROVE_OPTION) {

f = new File(chooser.getSelectedFile().getAbsolutePath());

}

out.println(f.getName());

byte[] b= new byte[(int)(f.length())];

FileInputStream fin = new FileInputStream(f);

fin.read(b);

String fromFile = new String(b);

out.println(fromFile);

out.println("END OF FILE");

fin.close();

}

answer = in.readLine();

System.out.println(answer);

JOptionPane.showMessageDialog(null, "Successful "+ choice);

in.close();

out.close();

System.exit(0);

}

catch(Exception e) {

System.out.println("Network Connection Error");

System.out.println(e.getMessage());

}

}

}

chhasx at 2007-7-7 > top of java,Developer Tools,Debugging and Profiling Tool APIs...