Java C/S mode --Client

王朝java/jsp·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

作者:ludejun98

import Java.applet.*;

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import java.net.*;

//public String str;

class javaclient extends Panel implements ActionListener

{

TextField tf;

LudCanvas cv;

Button b;

LudPanel(LudCanvas cv)

{

this.cv = cv;

tf = new TextField("ludejun",30);

add(tf);

b = new Button("退出");

b.addActionListener(this);

add(b);

b = new Button("发送");

b.addActionListener(this);

add(b);

}

public str actionPerformed(ActionEvent ev)

{

String str = ev.getActionCommand();

if( str.equals("退出") )

{

//tf.setText("This is my first button");

System.exit(0);

}

else

{

str = tf.getText();

tf.setText("开始检测发送......");

return str;

}

}

public static void main(String args[])

{

String data;

Socket Client;

DataInputStream InputS;

DataInputStream KeyS;

PrintStream OutputS;

Basic h = new Basic();

int i = 0;

try

{

Client = new Socket(args[0],600);

InputS = new

DataInputStream(Client.getInputStream());

OutputS = new PrintStream(Client.getOutputStream());

KeyS = new DataInputStream(System.in);

}

catch(IOException e)

{

System.out.println("Cannot Connect with Server");

return;

}

try

{

while (i

{

data = KeyS.readLine();

OutputS.println(data);

System.out.println("ECHO From Server:"+ InputS.readLine());

i++;

}

}

catch(IOException e)

{

System.out.println("IOException Happened");

}

try

{

System.out.println("Now will end this program");

Client.close();

}

catch(IOException e)

{

System.out.println("system cannot close socket");

}

}

}

//@@@@@@@@@@@@@@@@@@@@@@@222

class LudCanvas extends Canvas

{

public void paint(Graphics g)

{

Rectangle r = getBounds();

g.setColor(Color.red);

int panelHeight = 15;

int b = 3;

g.drawRect(b , b , r.width-b-b , r.height-b-b-panelHeight);

int t = 10;

g.drawRect(t , t , r.width-t-t , r.height-t-t-panelHeight);

g.drawString("The first applet of mine", 120, 30);

Image img = Toolkit.getDefaultToolkit().getImage("ie.gif");

g.drawImage(img, 50, 50, this);

}

}

class LudPanel extends Panel implements ActionListener

{

TextField tf;

LudCanvas cv;

Button b;

LudPanel(LudCanvas cv)

{

this.cv = cv;

tf = new TextField("ludejun",30);

add(tf);

b = new Button("退出");

b.addActionListener(this);

add(b);

b = new Button("发送");

b.addActionListener(this);

add(b);

}

public void actionPerformed(ActionEvent ev)

{

String str = ev.getActionCommand();

if( str.equals("退出") )

{

//tf.setText("This is my first button");

System.exit(0);

}

else

{

tf.setText("开始检测发送......");

}

}

}

:em51: :em51: :em51:

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航