Java代码大神QQ,代码Java
用JAVA怎么写QQ
用java是可以写出qq的,只不过用java开发c/s的软件不是java特长的,你要是真的想写,就写着练练手吧,最起码可以巩固java se上的知识。
10年的银川网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。营销型网站建设的优势是能够根据用户设备显示端的尺寸不同,自动调整银川建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“银川网站设计”,“银川网站推广”以来,每个客户项目都认真落实执行。
具体怎么写,给你个大概的思路吧,因为我没办法在这个有限的输入框内把所有的代码写完。
【1】先写出qq的简单界面
【2】给每个按钮添加监听
【3】按钮事件(方法)定义
【4】连接网络(socket)
【5】测试
【5】其他功能添加
【6】测试
求大神解答JAVA编程题(3152439509@qq.com)
简单的,那不需要留邮箱
package proxy;
import java.net.*;
import java.io.*;
public class ProxyServer {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = null;
boolean listening = true;
int port = 10000; //default
try {
port = Integer.parseInt(args[0]);
} catch (Exception e) {
//ignore me
}
try {
serverSocket = new ServerSocket(port);
System.out.println("Started on: " + port);
} catch (IOException e) {
System.err.println("Could not listen on port: " + args[0]);
System.exit(-1);
}
while (listening) {
new ProxyThread(serverSocket.accept()).start();
}
serverSocket.close();
}
}
线程,客户端代码你自己找找,只是发socket过来而已
package proxy;
import java.net.*;
import java.io.*;
import java.util.*;
public class ProxyThread extends Thread {
private Socket socket = null;
private static final int BUFFER_SIZE = 32768;
public ProxyThread(Socket socket) {
super("ProxyThread");
this.socket = socket;
}
public void run() {
//get input from user
//send request to server
//get response from server
//send response to user
try {
DataOutputStream out =
new DataOutputStream(socket.getOutputStream());
BufferedReader in = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
String inputLine, outputLine;
int cnt = 0;
String urlToCall = "";
///////////////////////////////////
//begin get request from client
while ((inputLine = in.readLine()) != null) {
try {
StringTokenizer tok = new StringTokenizer(inputLine);
tok.nextToken();
} catch (Exception e) {
break;
}
//parse the first line of the request to find the url
if (cnt == 0) {
String[] tokens = inputLine.split(" ");
urlToCall = tokens[1];
//can redirect this to output log
System.out.println("Request for : " + urlToCall);
}
cnt++;
}
//end get request from client
///////////////////////////////////
BufferedReader rd = null;
try {
//System.out.println("sending request
//to real server for url: "
// + urlToCall);
///////////////////////////////////
//begin send request to server, get response from server
URL url = new URL(urlToCall);
URLConnection conn = url.openConnection();
conn.setDoInput(true);
//not doing HTTP posts
conn.setDoOutput(false);
//System.out.println("Type is: "
//+ conn.getContentType());
//System.out.println("content length: "
//+ conn.getContentLength());
//System.out.println("allowed user interaction: "
//+ conn.getAllowUserInteraction());
//System.out.println("content encoding: "
//+ conn.getContentEncoding());
//System.out.println("content type: "
//+ conn.getContentType());
// Get the response
InputStream is = null;
HttpURLConnection huc = (HttpURLConnection)conn;
if (conn.getContentLength() 0) {
try {
is = conn.getInputStream();
rd = new BufferedReader(new InputStreamReader(is));
} catch (IOException ioe) {
System.out.println(
"********* IO EXCEPTION **********: " + ioe);
}
}
//end send request to server, get response from server
///////////////////////////////////
///////////////////////////////////
//begin send response to client
byte by[] = new byte[ BUFFER_SIZE ];
int index = is.read( by, 0, BUFFER_SIZE );
while ( index != -1 )
{
out.write( by, 0, index );
index = is.read( by, 0, BUFFER_SIZE );
}
out.flush();
//end send response to client
///////////////////////////////////
} catch (Exception e) {
//can redirect this to error log
System.err.println("Encountered exception: " + e);
//encountered error - just send nothing back, so
//processing can continue
out.writeBytes("");
}
//close out all resources
if (rd != null) {
rd.close();
}
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
if (socket != null) {
socket.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
java网络课一般都会有这种习题,现成的代码网上大把
来个java大神帮写全部代码
public class MainTest {
private static Scanner sc = new Scanner(System.in);
private static Scanner scn = new Scanner(System.in);
public static void main(String[] args) {
show();
}
private static void show() {
String s0 = "\n\t-----------------学生管理系统----------------\n", s1, s2, s3, s4, s5, s6;
s1 = "\t1.添加学生";
s2 = "\n\t2.修改学生";
s3 = "\n\t3.删除学生";
s4 = "\n\t4.查询学生";
s5 = "\n\t5.打印所有学生";
s6 = "\n\t6.退出系统";
sop(s0 + s1 + s2 + s3 + s4 + s5 + s6);
init();
}
private static void init() {
// 管理类!
StuManager sm = new StuManager();
while (true) {
int key = scn.nextInt();
switch (key) {
case 1:
method(1,sm);
break;
case 2:
method(2,sm);
break;
case 3:
method(3,sm);
break;
case 4:
method(4,sm);
break;
case 5:
method(5,sm);
break;
default:
System.exit(0);;
break;
}
}
}
private static void method(int n,StuManager sm) {
if (n == 1) {
sop("添加:学号,Nmae,Phone");
sm.addStudent(new Student(sc.nextLine(),sc.nextLine(),scn.nextLong()));
} else if (n == 2) {
sop("修改:");
sm.updateStudent(sc.nextLine());
} else if (n == 3) {
sop("删除:");
sm.deleteStudent(sc.nextLine());
} else if (n == 4) {
sop("查询:");
sop(sm.getStudent(sc.nextLine()));
} else{
sm.printAllStudent();
}
}
private static void sop(Object obj) {
System.out.println(obj);
}
}
class Student {
private String Number;
private String name;
private long phone;
public Student(String number, String name, long phone) {
super();
Number = number;
this.name = name;
this.phone = phone;
}
public String getNumber() {
return Number;
}
public void setNumber(String number) {
Number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getPhone() {
return phone;
}
public void setPhone(long phone) {
this.phone = phone;
}
public String toString() {
return "学号:" + Number + "\tNmae:" + name + "\tPhone:" + phone;
}
}
class StuManager {
private Student[] Students;
private int porin = 0;
private Scanner sc = new Scanner(System.in);
private Scanner scn = new Scanner(System.in);
StuManager() {
Students = new Student[20];
}
public void addStudent(Student student) {
if (porin Students.length - 1)
return;
Students[porin] = student;
porin++;
}
public void deleteStudent(String number) {
for (int i = 0; i Students.length; i++) {
if (Students[i].getNumber().equals(number)) {
Students[i] = null;
return;
}
}
sop("不存在!");
}
public void updateStudent(String number) {
for (int i = 0; i Students.length; i++) {
if (Students[i].getNumber().equals(number)) {
sop("输入修改name:");
Students[i].setName(sc.nextLine());
;
try {
sop("输入Phone:");
Students[i].setPhone(scn.nextLong());
} catch (Exception e) {
sop("输入有误重新输入:");
updateStudent(number);
}
} else {
sop("不存在!");
return;
}
}
}
public Student getStudent(String stuNo) {
Student tem=null;
for (int i = 0; i Students.length; i++) {
if(Students[i]==null) {
return tem;
}
if (Students[i].getNumber().equals(stuNo)) {
tem=Students[i];
}
}
sop("查无此人!");
return tem;
}
public void printAllStudent() {
for (int i = 0; i Students.length; i++) {
sop(Students[i]);
}
}
private void sop(Object obj) {
System.out.println(obj);
}
}
分享题目:Java代码大神QQ,代码Java
当前URL:http://scjbc.cn/article/phpeeh.html