求Java大神,帮忙做一个点餐系统,求java多隆大神源代码下载

android_dianchangxitong
org.eclipse.jdt.core.prefs
android_dianchangxitong
android-support-v4.jar
btn_add1.png
btn_add2.png
btn_arrows_left_1.png
btn_arrows_left_2.png
btn_arrows_right_1.png
btn_arrows_right_2.png
btn_back1.png
btn_back2.png
btn_browse_order1.png
btn_browse_order2.png
btn_change_table1.png
btn_change_table2.png
btn_checkout1.png
btn_checkout2.png
btn_choosedish1.png
btn_choosedish2.png
btn_delete1.png
btn_delete2.png
btn_login1.png
btn_login2.png
btn_merge_table1.png
btn_merge_table2.png
btn_more1.png
btn_more2.png
btn_net_test1.png
btn_net_test2.png
btn_ok1.png
btn_ok2.png
btn_option1.png
btn_option2.png
btn_order_schedule1.png
btn_order_schedule2.png
btn_remark1.png
btn_remark2.png
btn_update_menu1.png
btn_update_menu2.png
btn_update_table1.png
btn_update_table2.png
dish_no_image.png
gallery1.jpg
gallery2.jpg
gallery3.jpg
gallery4.jpg
gallery5.jpg
gallery6.jpg
ic_launcher.png
img_bg1.png
img_bg2.png
img_net.png
img_order.png
img_table.png
input_bg.9.png
layout_menu_bottom.png
logininput1.png
logininput2.png
login_bg.png
login_input.9.png
menu_background.9.png
spinner_click_press.png
spinner_click_unpress.png
title_bg.9.png
title_bg1.9.png
title_bg2.9.png
title_bg3.9.png
drawable-hdpi
ic_launcher.png
drawable-mdpi
backbutton.png
backbuttonselect.png
button_back.png
button_back_press.png
button_menuintroduction.png
button_menuintroduction_press.png
button_next.png
button_next_press.png
button_ok.png
button_ok_press.png
button_order.png
button_order_press.png
cancel.png
cancelorders.png
cancelordersselect.png
cancelselect.png
choosetablebeijing.png
delete.png
deleteselect.png
determine.png
determinelist.png
determinelistselect.png
determineselect.png
erguotou.png
explist_click.9.png
explist_click_press.9.png
forgetpasswordselect.png
forgotpassword.png
gallery1.jpg
gallery2.jpg
gallery3.jpg
gallery4.jpg
gallery5.jpg
gallery6.jpg
ic_launcher.png
imagebutton_zoomin.9.png
imageview_background.9.png
kekoukele.png
layout_menu_bottom.png
leisure.png
leisureselect.png
loginbackground.9.png
loginbiankuang.png
loginbutton.png
loginbutton1.png
loginbutton1select.png
menupredetermine.png
menupredetermineselect.png
menuquery.png
menuqueryselect.png
menu_background.9.png
menu_explist_item_arrow.png
messagequery.png
messagequeryselect.png
mymoney_bg.png
noteselect.png
radio_selcet.png
radio_selceted.png
register.png
registerselect.png
spinner_click.png
spinner_click_press.png
text_background.9.png
wankuai.png
xialajiantou.png
yudingbeijing.png
zicaitang.png
drawable-xhdpi
ic_launcher.png
drawable-xxhdpi
ic_launcher.png
activity_bookingseats.xml
activity_main.xml
activity_register.xml
alter_password.xml
browse_order.xml
chakan.xml
chakan_item.xml
checkout.xml
checkout_item.xml
customeractivity_main.xml
detail_checkout.xml
detail_item.xml
dishes_erji.xml
dishes_menu.xml
options.xml
order_schedule.xml
order_schedule_item.xml
preview_order_item.xml
table_change.xml
dimens.xml
strings.xml
styles.xml
values-sw600dp
dimens.xml
values-sw720dp-land
dimens.xml
android_dianchangxitong
httpclient
shujugongxiang
.classpath
AndroidManifest.xml
ic_launcher-web.png
proguard-project.txt
project.properties
GourmetOrderServer
GourmetOrderServer
.jsdtscope
org.eclipse.jdt.core.prefs
org.eclipse.wst.jsdt.ui.superType.container
org.eclipse.wst.jsdt.ui.superType.name
DBConfig.properties
colddishes1.png
colddishes2.png
colddishes3.png
colddishes4.png
drink1.png
drink2.png
drink3.png
drink4.png
hotdishes1.png
hotdishes2.png
hotdishes3.png
hotdishes4.png
staplefood1.png
staplefood2.png
staplefood3.png
staplefood4.png
tableware1.png
MANIFEST.MF
CheckTableDaoImpl.class
CustomerDaoImpl.class
MenuDaoImpl.class
OrderDaoImpl.class
UserDaoImpl.class
UtilDaoImpl.class
CheckTableDao.class
CustomerDao.class
MenuDao.class
OrderDao.class
UserDao.class
UtilDao.class
CheckTable.class
Customer.class
Menu.class
Order.class
OrderDetail.class
User.class
EncodingFilter.class
AddOrderServlet.class
ChangetableServlet.class
LoginServlet.class
OrderServlet.class
PayMoneyServlet.class
QueryOreder.class
RegisterServlet.class
UpdateServlet.class
DBConfig.properties
DBUtil.class
JSONUtil.class
gson-1.7.1.jar
mysql-connector-java-5.0.3-bin.jar
org.json.jar
.classpath
.mymetadata
gourmet_db
customer.MYD
customer.MYI
menutbl.MYD
menutbl.MYI
ordertbl.MYD
ordertbl.MYI
orederdetailtbl.MYD
orederdetailtbl.MYI
tabletbl.MYD
tabletbl.MYI
usertbl.MYD
usertbl.MYI
package com.
import java.io.IOE
import java.io.InputS
import java.net.HttpURLC
import java.net.URL;
import java.util.ArrayL
import java.util.L
import org.apache.http.HttpE
import org.apache.http.HttpR
import org.apache.http.NameValueP
import org.apache.http.client.ClientProtocolE
import org.apache.http.client.HttpC
import org.apache.http.client.entity.UrlEncodedFormE
import org.apache.http.client.methods.HttpG
import org.apache.http.client.methods.HttpP
import org.apache.http.impl.client.DefaultHttpC
import org.apache.http.message.BasicNameValueP
import org.apache.http.util.EntityU
import android.graphics.B
import android.graphics.BitmapF
public class MyHttpClient {
static String http = &http://192.168.1.100&;
public static String getHttpClient(String name, String paw, String category)
throws IOException {
String xiaoxi =
// 打开浏览器 创建Httpclient对象
HttpClient httpClient = new DefaultHttpClient();
// 访问网址
String url = http + &:8080/GourmetOrderServer/loginServlet?name=&
+ name + &&paw=& + paw + &&category=& +
// 创建请求方式,创建HttpGet对象
HttpGet httpGet = new HttpGet(url);
// 浏览器执行请求,获取HttpResponse对象。通过Httpclient对象调用execute
HttpResponse httpResponse = httpClient.execute(httpGet);
// 通过获取响应码,判断是否执行成功
if (httpResponse.getStatusLine().getStatusCode() == 200) {
// 获得响应内容
System.out.println(&响应成功&);
HttpEntity httpEntity = httpResponse.getEntity();
// 通过EntityUtils调用tostring解码成字符串
xiaoxi = EntityUtils.toString(httpEntity);
System.out.println(&响应失败&);
xiaoxi = &网络连接失败&;
* 创建HttpClient对象
* 创建URL字符串对象
* 创建HttpPost对象
* 创建HttpEntity 对象:通过UrlEncodedFormEntity
* 通过HttpPost对象调用setEntity方法传入HttpEntity 对象
* 获取HttpResponse对象,通过HttpClient对象调用execute
* 通过获取响应码,判断执行是否成功
* 如果响应成功,获取HttpEntity对象:通过HttpResponse对象调用getEntity方法
* 通过EntityUtil调用toString方法把HttpEntity对象转化成字符串
* @throws IOException
* @throws ClientProtocolException
// 修改密码
public static String postHttpClient(String name, String opaw, String npaw)
throws ClientProtocolException, IOException {
String value =
// 创建HttpClient对象
HttpClient httpClient = new DefaultHttpClient();
// 设置访问网络地址:创建URL字符串对象
String url = http + &:8080/GourmetOrderServer/loginServlet&;
// 创建HttpPost对象
HttpPost httpPost = new HttpPost(url);
List&NameValuePair& parameters = new ArrayList&NameValuePair&();
NameValuePair np1 = new BasicNameValuePair(&name&, name);
parameters.add(np1);
NameValuePair np2 = new BasicNameValuePair(&opaw&, opaw);
parameters.add(np2);
NameValuePair np3 = new BasicNameValuePair(&npaw&, npaw);
parameters.add(np3);
// 创建HttpEntity 对象:通过UrlEncodedFormEntity
HttpEntity httpEntity = new UrlEncodedFormEntity(parameters);
// 设置请求参数:通过HttpPost对象调用setEntity方法传入HttpEntity 对象
httpPost.setEntity(httpEntity);
// 获取HttpResponse对象,通过HttpClient对象调用execute
HttpResponse httpResponse = httpClient.execute(httpPost);
// 判断响应是否成功
if (httpResponse.getStatusLine().getStatusCode() == 200) {
httpEntity = httpResponse.getEntity();
value = EntityUtils.toString(httpEntity);
value = &网络错误&;
// 获取菜单信息
public static String postHttpClient1() throws ClientProtocolException,
IOException {
String value =
// 创建HttpClient对象
HttpClient httpClient = new DefaultHttpClient();
// 设置访问网络地址:创建URL字符串对象
String url = http + &:8080/GourmetOrderServer/updateServlet&;
// 创建HttpPost对象
HttpPost httpPost = new HttpPost(url);
List&NameValuePair& parameters = new ArrayList&NameValuePair&();
NameValuePair np1 = new BasicNameValuePair(&num&, &1&);
parameters.add(np1);
NameValuePair np2 = new BasicNameValuePair(&update&, &menu&);
parameters.add(np2);
// 创建HttpEntity 对象:通过UrlEncodedFormEntity
HttpEntity httpEntity = new UrlEncodedFormEntity(parameters);
// 设置请求参数:通过HttpPost对象调用setEntity方法传入HttpEntity 对象
httpPost.setEntity(httpEntity);
// 获取HttpResponse对象,通过HttpClient对象调用execute
HttpResponse httpResponse = httpClient.execute(httpPost);
// 判断响应是否成功
if (httpResponse.getStatusLine().getStatusCode() == 200) {
httpEntity = httpResponse.getEntity();
value = EntityUtils.toString(httpEntity);
value = &网络错误&;
// 加载菜单图片
public static Bitmap getHttpUrlConnection(String imageString)
throws IOException {
Bitmap bitmap =
// 1\创建一个字符串网址,然后封装至Url对象中
String str = http + &:8080/GourmetOrderServer/& + imageS
URL url = new URL(str);
// 2\通过Url获取UrlConnection对象:调用openConnection
HttpURLConnection httpUrlConnection = (HttpURLConnection) url
.openConnection();
// 3\设置连接参数:超时时间、请求方式
httpUrlConnection.setRequestMethod(&GET&);
httpUrlConnection.setConnectTimeout(5000);
// 4\判断响应是否成功
if (httpUrlConnection.getResponseCode() == 200) {
// 5\获取输入流,通过getInputStream
InputStream input = httpUrlConnection.getInputStream();
bitmap = BitmapFactory.decodeStream(input);
/* 获取桌号信息 */
public static String postHttpClient2() throws ClientProtocolException,
IOException {
String value =
// 创建HttpClient对象
HttpClient httpClient = new DefaultHttpClient();
// 设置访问网络地址:创建URL字符串对象
String url = http + &:8080/GourmetOrderServer/updateServlet&;
// 创建HttpPost对象
HttpPost httpPost = new HttpPost(url);
List&NameValuePair& parameters = new ArrayList&NameValuePair&();
NameValuePair np1 = new BasicNameValuePair(&num&, &1&);
parameters.add(np1);
NameValuePair np2 = new BasicNameValuePair(&update&, &table&);
parameters.add(np2);
// 创建HttpEntity 对象:通过UrlEncodedFormEntity
HttpEntity httpEntity = new UrlEncodedFormEntity(parameters);
// 设置请求参数:通过HttpPost对象调用setEntity方法传入HttpEntity 对象
httpPost.setEntity(httpEntity);
// 获取HttpResponse对象,通过HttpClient对象调用execute
HttpResponse httpResponse = httpClient.execute(httpPost);
// 判断响应是否成功
if (httpResponse.getStatusLine().getStatusCode() == 200) {
httpEntity = httpResponse.getEntity();
value = EntityUtils.toString(httpEntity);
value = &网络错误&;
// 上传订单
public static String postHttpClient3(String object)
throws ClientProtocolException, IOException {
String value =
// 创建HttpClient对象
HttpClient httpClient = new DefaultHttpClient();
// 设置访问网络地址:创建URL字符串对象
String url = http + &:8080/GourmetOrderServer/orderServlet&;
// 创建HttpPost对象
HttpPost httpPost = new HttpPost(url);
List&NameValuePair& parameters = new ArrayList&NameValuePair&();
NameValuePair np1 = new BasicNameValuePair(&list&, object);
parameters.add(np1);
// 创建HttpEntity 对象:通过UrlEncodedFormEntity
HttpEntity httpEntity = new UrlEncodedFormEntity(parameters);
// 设置请求参数:通过HttpPost对象调用setEntity方法传入HttpEntity 对象
httpPost.setEntity(httpEntity);
// 获取HttpResponse对象,通过HttpClient对象调用execute
HttpResponse httpResponse = httpClient.execute(httpPost);
// 判断响应是否成功
if (httpResponse.getStatusLine().getStatusCode() == 200) {
httpEntity = httpResponse.getEntity();
value = EntityUtils.toString(httpEntity);
System.out.println(value);
value = &网络错误&;
// 查询全部订单
public static String getHttpClient4() throws IOException {
String xiaoxi =
// 打开浏览器 创建Httpclient对象
HttpClient httpClient = new DefaultHttpClient();
// 访问网址
String url = http + &:8080/GourmetOrderServer/queryAllOreder&;
// 创建请求方式,创建HttpGet对象
HttpGet httpGet = new HttpGet(url);
// 浏览器执行请求,获取HttpResponse对象。通过Httpclient对象调用execute
HttpResponse httpResponse = httpClient.execute(httpGet);
// 通过获取响应码,判断是否执行成功
if (httpResponse.getStatusLine().getStatusCode() == 200) {
// 获得响应内容
System.out.println(&响应成功&);
HttpEntity httpEntity = httpResponse.getEntity();
// 通过EntityUtils调用tostring解码成字符串
xiaoxi = EntityUtils.toString(httpEntity);
System.out.println(&响应失败&);
xiaoxi = &网络连接失败&;
// 查询订单菜单
public static String postHttpClient5(String orders, String waiter)
throws ClientProtocolException, IOException {
String value =
// 创建HttpClient对象
HttpClient httpClient = new DefaultHttpClient();
// 设置访问网络地址:创建URL字符串对象
String url = http + &:8080/GourmetOrderServer/queryOreder&;
// 创建HttpPost对象
HttpPost httpPost = new HttpPost(url);
List&NameValuePair& parameters = new ArrayList&NameValuePair&();
NameValuePair np1 = new BasicNameValuePair(&orders&, orders);
parameters.add(np1);
NameValuePair np2 = new BasicNameValuePair(&waiter&, waiter);
parameters.add(np2);
// 创建HttpEntity 对象:通过UrlEncodedFormEntity
HttpEntity httpEntity = new UrlEncodedFormEntity(parameters);
// 设置请求参数:通过HttpPost对象调用setEntity方法传入HttpEntity 对象
httpPost.setEntity(httpEntity);
// 获取HttpResponse对象,通过HttpClient对象调用execute
HttpResponse httpResponse = httpClient.execute(httpPost);
// 判断响应是否成功
if (httpResponse.getStatusLine().getStatusCode() == 200) {
httpEntity = httpResponse.getEntity();
value = EntityUtils.toString(httpEntity);
value = &网络错误&;
public static String postHttpClient6(String orders, String waiter,
String cus, String sum) throws ClientProtocolException, IOException {
String value =
// 创建HttpClient对象
HttpClient httpClient = new DefaultHttpClient();
// 设置访问网络地址:创建URL字符串对象
String url = http + &:8080/GourmetOrderServer/payMoneyServlet&;
// 创建HttpPost对象
HttpPost httpPost = new HttpPost(url);
List&NameValuePair& parameters = new ArrayList&NameValuePair&();
NameValuePair np1 = new BasicNameValuePair(&orders&, orders);
parameters.add(np1);
NameValuePair np2 = new BasicNameValuePair(&waiter&, waiter);
parameters.add(np2);
NameValuePair np3 = new BasicNameValuePair(&cus&, cus);
parameters.add(np3);
NameValuePair np4 = new BasicNameValuePair(&sum&, sum);
parameters.add(np4);
// 创建HttpEntity 对象:通过UrlEncodedFormEntity
HttpEntity httpEntity = new UrlEncodedFormEntity(parameters);
// 设置请求参数:通过HttpPost对象调用setEntity方法传入HttpEntity 对象
httpPost.setEntity(httpEntity);
// 获取HttpResponse对象,通过HttpClient对象调用execute
HttpResponse httpResponse = httpClient.execute(httpPost);
// 判断响应是否成功
if (httpResponse.getStatusLine().getStatusCode() == 200) {
httpEntity = httpResponse.getEntity();
value = EntityUtils.toString(httpEntity);
value = &网络错误&;
public static String postHttpClient7(String object)
throws ClientProtocolException, IOException {
String value =
// 创建HttpClient对象
HttpClient httpClient = new DefaultHttpClient();
// 设置访问网络地址:创建URL字符串对象
String url = http + &:8080/GourmetOrderServer/addOrderServlet&;
// 创建HttpPost对象
HttpPost httpPost = new HttpPost(url);
List&NameValuePair& parameters = new ArrayList&NameValuePair&();
NameValuePair np1 = new BasicNameValuePair(&list&, object);
parameters.add(np1);
// 创建HttpEntity 对象:通过UrlEncodedFormEntity
HttpEntity httpEntity = new UrlEncodedFormEntity(parameters);
// 设置请求参数:通过HttpPost对象调用setEntity方法传入HttpEntity 对象
httpPost.setEntity(httpEntity);
// 获取HttpResponse对象,通过HttpClient对象调用execute
HttpResponse httpResponse = httpClient.execute(httpPost);
// 判断响应是否成功
if (httpResponse.getStatusLine().getStatusCode() == 200) {
httpEntity = httpResponse.getEntity();
value = EntityUtils.toString(httpEntity);
System.out.println(value);
value = &网络错误&;
public static String postHttpClient8(String orders, String waiter)
throws ClientProtocolException, IOException {
String value =
// 创建HttpClient对象
HttpClient httpClient = new DefaultHttpClient();
// 设置访问网络地址:创建URL字符串对象
String url = http + &:8080/GourmetOrderServer/changetableServlet&;
// 创建HttpPost对象
HttpPost httpPost = new HttpPost(url);
List&NameValuePair& parameters = new ArrayList&NameValuePair&();
NameValuePair np1 = new BasicNameValuePair(&orders&, orders);
parameters.add(np1);
NameValuePair np2 = new BasicNameValuePair(&waiter&, waiter);
parameters.add(np2);
// 创建HttpEntity 对象:通过UrlEncodedFormEntity
HttpEntity httpEntity = new UrlEncodedFormEntity(parameters);
// 设置请求参数:通过HttpPost对象调用setEntity方法传入HttpEntity 对象
httpPost.setEntity(httpEntity);
// 获取HttpResponse对象,通过HttpClient对象调用execute
HttpResponse httpResponse = httpClient.execute(httpPost);
// 判断响应是否成功
if (httpResponse.getStatusLine().getStatusCode() == 200) {
httpEntity = httpResponse.getEntity();
value = EntityUtils.toString(httpEntity);
value = &网络错误&;
public static String postHttpClient9(String object)
throws ClientProtocolException, IOException {
String value =
// 创建HttpClient对象
HttpClient httpClient = new DefaultHttpClient();
// 设置访问网络地址:创建URL字符串对象
String url = http + &:8080/GourmetOrderServer/registerServlet&;
// 创建HttpPost对象
HttpPost httpPost = new HttpPost(url);
List&NameValuePair& parameters = new ArrayList&NameValuePair&();
NameValuePair np1 = new BasicNameValuePair(&list&, object);
parameters.add(np1);
// 创建HttpEntity 对象:通过UrlEncodedFormEntity
HttpEntity httpEntity = new UrlEncodedFormEntity(parameters);
// 设置请求参数:通过HttpPost对象调用setEntity方法传入HttpEntity 对象
httpPost.setEntity(httpEntity);
// 获取HttpResponse对象,通过HttpClient对象调用execute
HttpResponse httpResponse = httpClient.execute(httpPost);
// 判断响应是否成功
if (httpResponse.getStatusLine().getStatusCode() == 200) {
httpEntity = httpResponse.getEntity();
value = EntityUtils.toString(httpEntity);
System.out.println(value);
value = &网络错误&;
Copyright(C)
OKBASE.NET All Rights Reserved 好库网 版权所有&快餐点餐系统--java制作
秒后自动跳转到登录页
(奖励10下载豆)
快捷登录:
举报类型:
不规范:上传重复资源
不规范:标题与实际内容不符
不规范:资源无法下载或使用
其他不规范行为
违规:资源涉及侵权
违规:含有危害国家安全等内容
违规:含有反动/色情等内容
违规:广告内容
详细原因:
任何违反下载中心规定的资源,欢迎Down友监督举报,第一举报人可获5-10下载豆奖励。
C#摄像头源码分享
用C++实现2048游戏的
198个经典C#WinForm
Java 7并发编程实战
Java经典问题答案(
算法与数据结构-实用
百度面试题总结
快餐点餐系统--java制作
上传时间:
技术分类:
资源评价:
(1位用户参与评价)
已被下载&105&次
基于叫java制作的一个点餐系统小程序
本资料共包含以下附件:
51CTO下载中心常见问题:
1.如何获得下载豆?
1)上传资料
2)评论资料
3)每天在首页签到领取
4)购买VIP会员服务,无需下载豆下载资源
5)更多途径:点击此处
2.如何删除自己的资料?
下载资料意味着您已同意遵守以下协议:
1.资料的所有权益归上传用户所有
2.未经权益所有人同意,不得将资料中的内容挪作商业或盈利用途
3.51CTO下载中心仅提供资料交流平台,并不对任何资料负责
4.本站资料中如有侵权或不适当内容,请邮件与我们联系()
5.本站不保证资源的准确性、安全性和完整性, 同时也不承担用户因使用这些资料对自己和他人造成任何形式的伤害或损失
下载1302次
下载1394次
下载1289次
下载2102次
相关专题推荐
本专题收录Java经典编程的实例源码,
在国内的开发语言中,java凭借这简单
本套视频教程是韩顺平老师,循序渐进
北京圣思园张龙(风中叶)老师的Java
讲述Arm嵌入式Linux系统下的C语言编程
这段视频是从尚学堂科技的教学课堂上
本套视频共78集,是由郝斌老师根据多
本视频专题共180集涵盖了C语言概述中
本视频专题共107集涵盖了Java概述、数
由传智播客毕向东老师讲解的Java基础
本专题为spring视频教程,共31集。教
本专题为C语言黑客编程系列视频教程,
本专题为韩顺平讲解的Java从入门到精
本专题为Java Web项目开发案例精粹视
SSH为struts+spring+hibernate的一个
本专题为疯狂Java李刚老师讲解的Stru
本周下载热点
意见或建议:
联系方式:
您已提交成功!感谢您的宝贵意见,我们会尽快处理Java小项目点餐系统(二)之服务端
服务端详解:
服务端的主要功能就是无限监听一个端口号,对客户端发来的连接请求给予回应,然后开辟新线程处理客户端。界面做的比较简单就是显示在线的用户,分为商家和学生。
一.监听客户端的socket连接请求
import java.awt.D
import java.awt.GridL
import java.awt.T
import java.awt.event.WindowA
import java.awt.event.WindowE
import java.io.IOE
import java.net.ServerS
import java.net.S
import java.util.LinkedL
import javax.swing.JF
import javax.swing.JScrollP
import javax.swing.JT
import javax.swing.table.DefaultTableM
public class MainWindow extends JFrame{
JTable user_
JTable seller_
JScrollPane user_jscrollP
JScrollPane seller_jscrollP
DefaultTableModel user_
DefaultTableModel seller_
String []user_headers = {"序号","在线学生"};
String []seller_headers = {"序号","在线商家"};
Object [][]cellData=
LinkedList student,
LinkedList
public static void main(String args[])
new MainWindow("服务端");
public MainWindow(String s)
student = new LinkedList();
seller = new LinkedList();
mysocket = new LinkedList();
addWindowListener(new WindowAdapter()
public void windowClosing(WindowEvent e)
dispose();
System.exit(0);
//获取屏幕大小
Dimension screenSize =Toolkit.getDefaultToolkit().getScreenSize();
//设置窗体的位置和大小
setBounds((screenSize.width-320)/2,(screenSize.height-240)/2,320,240);
setLayout(new GridLayout());
user_model = new DefaultTableModel(cellData,user_headers);
user_table = new JTable(user_model);
seller_model = new DefaultTableModel(cellData,seller_headers);
seller_table = new JTable(seller_model);
user_jscrollPane = new JScrollPane(user_table);
user_jscrollPane.setPreferredSize(new Dimension(160, 240));
seller_jscrollPane = new JScrollPane(seller_table);
seller_jscrollPane.setPreferredSize(new Dimension(160, 240));
add(user_jscrollPane);
add(seller_jscrollPane);
setVisible(true);
validate();
startServer();
void update()
user_model.setRowCount(0);
seller_model.setRowCount(0);
for(int i=0;i<student.size();i++)
user_model.addRow(new Object[]{i+1,student.get(i).account});
for(int i=0;i<seller.size();i++)
seller_model.addRow(new Object[]{i+1,seller.get(i).account});
void startServer() {
int i = 0;
//设置监听端口号和最大接入数
server = new ServerSocket(8889, 3);
System.out.println("==========start===========快点来啊");
new Thread(new ListenThread(this)).start();
while (true) {
Socket socket = server.accept();
mysocket.add(socket);
System.out.println("第" + i + "个用户连接成功!");
System.out.println("该用户端的地址信息为:"+socket.getInetAddress());
new Thread(new ServerThread(socket,this)).start();
} catch (IOException e) {
e.printStackTrace();
class ListenThread implements Runnable
private MainWindow mainW
public ListenThread(MainWindow mainWindow)
this.mainWindow = mainW
public void run()
while(true)
for(int i=0;i<mainWindow.mysocket.size();i++)
if(mainWindow.mysocket.get(i).isClosed())
for(int j=0;j<mainWindow.student.size();j++)
if(mainWindow.student.get(i).address == mainWindow.mysocket.get(i).getInetAddress())
mainWindow.student.remove(mainWindow.student.get(i));
for(int j=0;j<mainWindow.seller.size();j++)
if(mainWindow.seller.get(i).address == mainWindow.mysocket.get(i).getInetAddress())
mainWindow.seller.remove(mainWindow.seller.get(i));
mainWindow.update();
mainWindow.mysocket.remove(mainWindow.mysocket.get(i));
System.out.println("客户端已经断开");
Thread.sleep(500);
catch(Exception e)
在进程中使用while循环不断监听客户端发过来的请求,一旦请求建立成功就新建一个ServerThread子线程来处理客户端的请求,而主线程继续等待。同时开辟一个ListenThread线程不断判断哪一个线程已经断开连接。
二.在ServerThread中对客户端的请求进行处理
import java.io.DataInputS
import java.io.DataOutputS
import java.io.IOE
import java.net.S
public class ServerThread implements Runnable {
String account,
DataInputStream in =
DataOutputStream out =
LinkMySql linkMyS
private MainWindow mainW
// 创建静态全局变量
public ServerThread(Socket socket,MainWindow mainWindow)
this.mainWindow = mainW
this.socket =
linkMySql = new LinkMySql(this);
// 任务是为一个用户提供服务
public void run()
// 读取客户端传过来信息的DataInputStream
in = new DataInputStream(socket.getInputStream());
// 向客户端发送信息的DataOutputStream
out = new DataOutputStream(socket.getOutputStream());
System.out.println("放马过来吧!!!!");
// 读取来自客户端的信息
accept = in.readUTF();
System.out.println(accept);
catch (IOException e)
e.printStackTrace();
if(accept.equals("LOGIN"))
account = in.readUTF();
passwd = in.readUTF();
System.out.println("用户名:"+account+"\n密码:"+passwd);
for(int i=0;i<mainWindow.student.size();i++)
if(account.equals(mainWindow.student.get(i).account))
socket.close();
for(int i=0;i<mainWindow.seller.size();i++)
if(account.equals(mainWindow.seller.get(i).account))
socket.close();
dept = linkMySql.query(account,passwd);
out.writeUTF(dept);
if(dept.equals("student"))
User temp = new User();
temp.account =
temp.passwd =
temp.type = "student";
temp.address = socket.getInetAddress();
mainWindow.student.add(temp);
mainWindow.update();
linkMySql.initStudent(in,out);
linkMySql.handleOrder();
else if(dept.equals("seller"))
User temp = new User();
temp.account =
temp.passwd =
temp.type = "seller";
temp.address = socket.getInetAddress();
mainWindow.seller.add(temp);
mainWindow.update();
linkMySql.initseller(in,out);
catch(IOException e)
else if(accept.equals("REGISTER"))
先读取客户端发来的请求,然后进入对应的功能模块,如果是用户登录,则进行sql语句操作并对结果做出反应,如果查询错误则关闭该线程,判断为学生则加入学生链表并初始化学生端的商品信息和店铺信息,判断为商家则把改商家的商品信息发过去并查找相应的订单表,把属于该商家的订单发给商家。
服务端的主要功能就是利用socket和多线程把学生端和商家端连接起来,并把所有对数据的操作集中在服务端来做,全部由服务端与进行交互,保证数据的安全。
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'}

我要回帖

更多关于 求大神帮忙啊 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信