??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲成a人片在线不卡,国产精品亚洲AV三区,亚洲福利在线播放http://m.tkk7.com/min-water/如果一个h不知道他要驶向哪个码_那么M风都不会是顺风?/description>zh-cnSat, 10 May 2025 19:17:29 GMTSat, 10 May 2025 19:17:29 GMT60- 初学|络~程的两个小E序Q二Q?---TCP/IPhttp://m.tkk7.com/min-water/articles/337958.htmlMineralwasserMineralwasserFri, 12 Nov 2010 15:57:00 GMThttp://m.tkk7.com/min-water/articles/337958.htmlhttp://m.tkk7.com/min-water/comments/337958.htmlhttp://m.tkk7.com/min-water/articles/337958.html#Feedback0http://m.tkk7.com/min-water/comments/commentRss/337958.htmlhttp://m.tkk7.com/min-water/services/trackbacks/337958.htmll过一个多月枯燥的Java~程基础学习Q终于学到net了,呵呵.. .. ..挺好?
上服务器端程序:

TestTCPServer
package socketdemo;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class TestTCPServer {
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(9999);
while(true){
System.out.println("----------服务端已l启?-----------");
Socket s = ss.accept();
// System.out.println(s.getLocalPort()+" "+s.getPort()+" "+s.getLocalAddress().getHostAddress());
// System.out.println(s.getInetAddress().getHostAddress()+":"+s.getPort()+
// "客户端已l?q接上服务器ServerSocket");
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
System.out.println("客户端?/span>"+s.getInetAddress().getHostAddress()+"::"+s.getPort()+"】已l连?/span>");
dos.writeUTF("服务器端写入客户端的数据Q客L?/span>"+s.getInetAddress().getHostAddress()+"::"+s.getPort()+
"】已l连接上服务器端?/span>"+s.getLocalAddress().getHostAddress()+"::"+s.getLocalPort()+"】!");
dos.flush();
dos.close();
s.close();
}
}
}
q行l果Q?/p>
上客LE序Q?

TestTCPClient
package socketdemo;
import java.io.DataInputStream;
import java.io.IOException;
import java.net.Socket;
public class TestTCPClient {
public static void main(String[] args)throws IOException {
for(int i =0;i<5;i++){
Socket s = new Socket("192.168.0.2",9999);
// ------------------------------------------
DataInputStream dis = new DataInputStream(s.getInputStream());
System.out.println("接收Q?/span>"+dis.readUTF());
dis.close();
// ------------------------------------------
s.close();
}
}
}
q行l果Q?/p>
Q客LQ?/p>
Q服务器端)

]]> - 初学|络~程的两个小E序Q一Q?---UDP/IPhttp://m.tkk7.com/min-water/articles/337956.htmlMineralwasserMineralwasserFri, 12 Nov 2010 15:49:00 GMThttp://m.tkk7.com/min-water/articles/337956.htmlhttp://m.tkk7.com/min-water/comments/337956.htmlhttp://m.tkk7.com/min-water/articles/337956.html#Feedback0http://m.tkk7.com/min-water/comments/commentRss/337956.htmlhttp://m.tkk7.com/min-water/services/trackbacks/337956.htmll过一个多月枯燥的Java~程基础学习Q终于学到net了,呵呵.. .. ..挺好?/p>
上服务器端程序:

ServerSocket01
package socket;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
public class ServerSocket01 {
public static void main(String[] args) {
ServerSocket server = null;
try{
// 服务器在9999端口开辟了服务
server = new ServerSocket(9999);
}catch(Exception e){}
// 对于服务器而言Q所有用Lh都是通过ServerSocket实现
Socket client = null;
try{
// 服务器在此等待用L链接
System.out.println("{待客户端连?..");
client = server.accept();//服务端受到的一个client
}catch(Exception e){}
// 要向客户端打C?/span>
PrintStream out = null;
// 得到向客L输出信息的能?/span>
try{
out = new PrintStream(client.getOutputStream());
}catch(Exception e){}
out.println("How are you ?");
try{
client.close();
server.close();
}catch(Exception e){}
System.out.println("客户端回应完?..");
}
}
q行l果Q?/p>
上客LE序Q?/p>

ClientSocket01
package socket;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.Socket;
public class ClientSocket01 {
public static void main(String[] args) {
Socket client=null;
try {
// 实际上表C链接到服务器上去?/span>
client=new Socket("192.168.0.2",9999);
//192.168.0.2是本人的局域网IP地址
} catch (Exception e) {}
// {待服务器的回应
String str = null;
// 如果直接使用InputStream接收会比较麻?/span>
BufferedReader buf = null;
try{
buf = new BufferedReader(new InputStreamReader(client.getInputStream()));
str = buf.readLine();
}catch(Exception e){}
System.out.println(str);
}
}
q行l果Q?/p>
Q客LQ?/p>
Q服务器端)

]]> - 生?消费者(producer-consumerQ问?/title>http://m.tkk7.com/min-water/articles/337955.htmlMineralwasserMineralwasserFri, 12 Nov 2010 15:30:00 GMThttp://m.tkk7.com/min-water/articles/337955.htmlhttp://m.tkk7.com/min-water/comments/337955.htmlhttp://m.tkk7.com/min-water/articles/337955.html#Feedback0http://m.tkk7.com/min-water/comments/commentRss/337955.htmlhttp://m.tkk7.com/min-water/services/trackbacks/337955.html 生?消费者(producer-consumerQ问题,两个q程׃n一个公q固定大小的缓冲区。其中一个是生者,用于消息放入缓冲区Q另外一个是消费者,用于从缓冲区中取出消息?/p>
q样应该是生产者生产一个品,然后消费者取C个品,然后再生产、再消费Q这个看似很理所当然的逻辑在现实中是必然的Q但是在E序里却出现了问题。aQ生产者生产了很多消费者却没有取,bQ生产这q没有生产完一个完整的产品消费者却已经取走了好几次了,q样取走的品当然是不合格的?/p>
下面q生和消贚w子ؓ例,看看E序是怎么q行的吧.. .. ..

Demo01
package demo;
class Shoes{
// 鞋子c,两个属性:使用者(?奻IQ大(?)
String user=null;
String size=null;
}
class Pro implements Runnable{
// 生者,生
Shoes shoe = null;
public Pro(Shoes s){
this.shoe=s;
}
public void run(){
int i=0;
while(true){
if(i==0){
// 男hI的鞋子是大L
shoe.user="男式";
shoe.size="大号";
i=1;
}else{
// 女hI的鞋子是小L
shoe.user="奛_";
shoe.size="号";
i=0;
}
}
}
}
class Cus implements Runnable{
Shoes shoe=null;
public Cus(Shoes s){
this.shoe=s;
}
public void run(){
while(true){
System.out.println(shoe.user+"-->"+shoe.size);
}
}
}
public class Demo01 {
/**生?消费者问? producer-consumer
* @param args
*/
public static void main(String[] args) {
// 讄鞋子的一个生产者和一个消费者,q启动两个线E,分别q行生和消?/span>
Shoes shoe = new Shoes();
Pro p = new Pro(shoe);
Cus c = new Cus(shoe);
new Thread(p).start();
new Thread(c).start();
}
}
l果Q?/p>
从结果中可以看到Q第一ơ取时已l生产完一双男鞋,女鞋q没有生产完取C女鞋Q第二次到第四次消费都是男鞋Q看来是要么生的太多了Q没有取赎ͼ要么是取的太快Q只生了一双男鞋却取了四次?/p>
q样的程序显然是不符合实际的Q所以就要加以改q?/p>
应该是生产时Q生产者进入R间ƈ把R间的门上锁,生一双后生者出来,消费者进入到车间q把车间门上锁,取到鞋子后出来,q样车间里只有一个hQ要么生产者要么消费者,q样可以保证生产合格的产品?/p>
改进的程序:

Demo02
package demo2;
class Shoes{
// 鞋子c,两个属性:使用者(?奻IQ大(?)
String user=null;
String size=null;
private boolean flag = true;
public synchronized void set(String user,String size){
//如果flag的g是true则要{待
if (!flag){
//{待
try{
wait();
}catch(Exception e){}
}
try{
Thread.sleep(100);
}catch (Exception e){}
// 如果向下l箋执行了,则表C可以设|?flag = true
this.user = user;
this.size = size;
// 修改讄的标?
flag = false;
//唤醒其他U程
notify();
}
//讄一个输出方?
public synchronized void get(){
// 如果flag的gؓtrue的时候,表示要等?
if(flag){
try{
wait();
}catch(Exception e){}
}
try{
Thread.sleep(100);
}catch (Exception e){}
//如果向下执行了,则表C允许取?
System.out.println(this.user+" --> "+this.size);
//改变标志Q表C可以生产了
flag = true;
notify();
}
}
class Pro implements Runnable{
// 生者,生
Shoes shoe = null;
public Pro(Shoes s){
this.shoe=s;
}
public void run(){
int i=0;
while(true){
if(i==0){
// 男hI的鞋子是大L
shoe.set("男式", "大号");
i=1;
}else{
// 女hI的鞋子是小L
shoe.set("奛_", "号");
i=0;
}
}
}
}
class Cus implements Runnable{
Shoes shoe=null;
public Cus(Shoes s){
this.shoe = s;
}
public void run(){
while(true){
shoe.get();
}
}
}
public class Demo02 {
/**生?消费者问? producer-consumer
* @param args
*/
public static void main(String[] args) {
// 讄鞋子的一个生产者和一个消费者,q启动两个线E,分别q行生和消?/span>
Shoes shoe = new Shoes();
Pro p = new Pro(shoe);
Cus c = new Cus(shoe);
new Thread(p).start();
new Thread(c).start();
}
}
q行l果Q?/p>


]]> - 多线E及实现多线E的Ҏ(gu)http://m.tkk7.com/min-water/articles/337543.htmlMineralwasserMineralwasserMon, 08 Nov 2010 08:33:00 GMThttp://m.tkk7.com/min-water/articles/337543.htmlhttp://m.tkk7.com/min-water/comments/337543.htmlhttp://m.tkk7.com/min-water/articles/337543.html#Feedback0http://m.tkk7.com/min-water/comments/commentRss/337543.htmlhttp://m.tkk7.com/min-water/services/trackbacks/337543.html多线E:减轻~写交互频繁、涉及面多的E序的难度;充分利用计算源?/p>
一个操作系l,可以有多个进E,每个q程上边会有多个U程。一个程序的q行臛_启动两个U程QmainU程和gcQ守护)U程?/p>
U程分ؓ前台U程和后台线E(守护U程Q:
对JavaE序来说Q只要有一个前台线E在q行Q这个进E就不会l束Q?/p>
如果一个进E只有后台线E在q行Q这个进E就会结束;
如果某个U程对象在启动(调用start()Ҏ(gu)Q之前调用setDaemon(true);Ҏ(gu)Q这个线E就变成了后台线E?/p>
U程的状态{换:
* 多线E的Ҏ(gu)有两U:
1、承Threadc,q写run()Ҏ(gu)Q?/p>
2、实现Runnable接口?/p>
虽然有两U不同的Ҏ(gu)Q但是它们的多线E启动方法是相同的,都是同归ThreadcL启动多线E的[p.start();]?/p>
start使盖县程开始执行是指Java虚拟用该U程的run()Ҏ(gu)Q?/p>
start只是使线E就l,什么时候开始执行由CPU军_?/p>
U程只能启动一ơ;如果启动多次Q程序在~译时不会出现错误,但是执行时会出现错误?/p>
两种Ҏ(gu)的不同在于:
Ҏ(gu)1的缺点:Java为单l承Q当一个想实现多线E的cȝ承了Threadcd׃可以再承其他类Q这样就不灵z,没有扩展性了Q?/p>
Ҏ(gu)2的优点:实现Runnable接口不仅可以再承其他类Q还可以实现资源׃n?/p>
M实现Runnable接口比承Threadc要更好一些,所以尽量要使用Runnable而不用Thread?/p>
下面p两种Ҏ(gu)举例说明Q?/p>
Ҏ(gu)1Q承Threadc,重写run()Ҏ(gu)?/p>

class MyThread11 extends Thread
{
private int time;

public MyThread11 (String name,int time)
{
super(name);
this.time=time;
}

public void run()
{

try
{
Thread.sleep(this.time);

} catch (InterruptedException e)
{
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName()+"-->q行Qgq?nbsp;"+this.time+"毫秒?/span>");
}
}

public class MyDemo01
{

public static void main(String[] args)
{
MyThread11 mt1 = new MyThread11("T--A",1000);
MyThread11 mt2 = new MyThread11("T--B",2000);
MyThread11 mt3 = new MyThread11("T--C",3000);
mt1.start();
mt2.start();
mt3.start();
}
}

E序q行l果Q(每隔一U打C行,打印完后E序l束Q?br />
Ҏ(gu)2Q实现Runnable接口?br />

class MyThread22 implements Runnable
{
private int time;
private String name;

public MyThread22 (String name,int time)
{
this.name=name;
this.time=time;
}

public void run()
{

try
{
Thread.sleep(this.time);

} catch (InterruptedException e)
{
e.printStackTrace();
}
System.out.println(this.name+"-->q行Qgq?nbsp;"+this.time+"毫秒?/span>");
}
}

public class MyDemo02
{

public static void main(String[] args)
{
MyThread22 mt1 = new MyThread22("T--A",1000);
MyThread22 mt2 = new MyThread22("T--B",2000);
MyThread22 mt3 = new MyThread22("T--C",3000);
new Thread(mt1).start();
new Thread(mt2).start();
new Thread(mt3).start();
}
}

E序q行l果Q?
Q每隔一U打C行,打印完后E序l束Q?/p>

]]> - 阶段ȝhttp://m.tkk7.com/min-water/articles/337427.htmlMineralwasserMineralwasserSat, 06 Nov 2010 14:12:00 GMThttp://m.tkk7.com/min-water/articles/337427.htmlhttp://m.tkk7.com/min-water/comments/337427.htmlhttp://m.tkk7.com/min-water/articles/337427.html#Feedback0http://m.tkk7.com/min-water/comments/commentRss/337427.htmlhttp://m.tkk7.com/min-water/services/trackbacks/337427.html
下面写一个小E序Q把已经学过的知识都捎带着复习一?. .. ..
先说E序的要求:小的简单的学生信息理pȝ。在控制C昄四个选项Q分别ؓ增加、浏览、修攏V退出系l;然后选择相应的功能进行操?
阅读全文
]]> - JAVA技术(IO~程Q?/title>http://m.tkk7.com/min-water/articles/337371.htmlMineralwasserMineralwasserFri, 05 Nov 2010 10:02:00 GMThttp://m.tkk7.com/min-water/articles/337371.htmlhttp://m.tkk7.com/min-water/comments/337371.htmlhttp://m.tkk7.com/min-water/articles/337371.html#Feedback1http://m.tkk7.com/min-water/comments/commentRss/337371.htmlhttp://m.tkk7.com/min-water/services/trackbacks/337371.html字节序列的源和目的地可以是文件、网l连接、内存块{,存储在文件中的信息和从网l连接中接收的信息,从本质上处理Ҏ(gu)是相同的?
数据最l都保存Z个字节序列,但是在程序设计中应当用更高的数据结构来处理Q如字符或对象序列等?nbsp; 阅读全文
]]> - 银行排队叫号pȝhttp://m.tkk7.com/min-water/articles/336710.htmlMineralwasserMineralwasserMon, 01 Nov 2010 09:16:00 GMThttp://m.tkk7.com/min-water/articles/336710.htmlhttp://m.tkk7.com/min-water/comments/336710.htmlhttp://m.tkk7.com/min-water/articles/336710.html#Feedback0http://m.tkk7.com/min-water/comments/commentRss/336710.htmlhttp://m.tkk7.com/min-water/services/trackbacks/336710.html现在银行遍地开花,在城市了差不多每?00c_可以看到一安行。在银行叫号排队也就成了很^常的事情。但是很让h生气的是在咱们这个世界上最大的C会M国家里,在银行排队却很不公^Q咱们这些没q人(在银行里存钱不多Q持普通卡Q每ơ排队都要等很长一D|间才能办理业务,而且没有工作人员来招|而那些有׃hQ在银行里存了很多钱Q持“金卡”Q却不用{,随时可以办理业务Q还其名曰“金卡”Ҏ(gu)。难道有钱就有特权吗Q气愤中……...
q是说这个系l吧Q?/p>
银行大厅里有一个叫hQ顾客客LQ,如果持普通卡点一下办理业务按钮就会打C张小条,昄你的L和排在你前面的h敎ͼ如果持金卡,点一下办理业务就会提CZ一位要办理的客户就是你?/p>
每个业务办理H口都有一个工作h员客LQ点M一位就会从{待的客户队列中取出W一位到该窗口办理?/p>
客户Q也是{待的hQ要有号码、排在前面的人数{属性,然后实现q些属性的set、getҎ(gu)?/p>
Waiter

Waiter
package queuebanknew;
public class Waiter {
private int num;
private int frontNum;
private int flag;
public int getFlag() {
return flag;
}
public void setFlag(int flag) {
this.flag = flag;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public int getFrontNum() {
return frontNum;
}
public void setFrontNum(int frontNum) {
this.frontNum = frontNum;
}
}
工作人员Q也是H口的处理业务的人员Q她们有自己的编P姓名Q顾客,实现q些属性的set、getҎ(gu)Q还加入了一D工作过E的代码?/p>
Counter

Counter
package queuebanknew;
public class Counter {
private int id;
private String name;
private Waiter w;
public Counter(Waiter waiter) {
this.w=waiter;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Waiter getW() {
return w;
}
public void setW(Waiter w) {
this.w = w;
}
public void handBussines(){
System.out.println("正在处理Q?/span>"+this.w.getNum()+"?/span>");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("处理完毕Q?/span>"+this.getW().getNum());
}
}
试一下:

TestBankQueue
package queuebanknew;
import java.util.Queue;
public class TestBankQueue {
/**
* @param args
*/
public static void main(String[] args) {
QueueServer qs = new QueueServer();
Queue<Waiter> waiterList = qs.init();//初始?0个等待?/span>
Waiter waiter= null;
while(true){//模拟工作人员处理业务
waiter = waiterList.poll();
if(waiter != null){
Counter counter = new Counter(waiter);
counter.handBussines();
}else{
break;
}
}
}
}
l果Q?/p>
服务器端Q?/p>

QueueServer
package queuebanknew;
import java.util.LinkedList;
public class QueueServer {
LinkedList<Waiter> waiterList = new LinkedList<Waiter>();
public LinkedList<Waiter> init(){
for(int i=1;i<=10;i++){
Waiter w = new Waiter();
w.setNum(i);
w.setFrontNum(i-1);
waiterList.offer(w);
}
return waiterList;
}
}
BankWorkerUI
工作人员客户端:

BankWorkerUI
package queuebanknew;
import java.util.Queue;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class BankWorkerUI {
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(327, 253);
shell.setText("银行排队---工作人员客户?/span>");
// 新插入的界面核心代码
QueueServer qs = new QueueServer();
final Queue<Waiter> waiterList = qs.init();
final Text txt = new Text(shell,SWT.MULTI);
txt.setBounds(65,30,180,70);
// 事g代码里要讉Kbutton
final Button button = new Button(shell,SWT.Activate);
button.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
Waiter waiter = waiterList.poll();
if(waiter!=null){
txt.setText(waiter.getNum()+"号顾客到1L口办?/span>");
}else{
txt.setText("没h办理业务");
}
}
});
button.setBounds(90, 141, 100, 25);
button.setText("下一?/span>");
shell.layout();
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}
}
}
WaiterQueueUI
客户的客LQ?/p>

WaiterQueueUI
package queuebanknew;
import java.util.LinkedList;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class WaiterQueueUI {
public static void main(String[] args){
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setBounds(100, 100, 570, 380);
// shell.setMaximized(true);
shell.setText("银行排队----֮客户?/span>");
// 界面核心代码
QueueServer qs = new QueueServer();
final LinkedList<Waiter> waiterList = qs.init();
final Text txt = new Text(shell,SWT.MULTI);
txt.setBounds(50,50,200,150);
// 事g代码里要讉KbuttonQ所以要dfinal
final Button button = new Button(shell,SWT.Activate);
button.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
Waiter waiter = new Waiter();
waiter.setNum(waiterList.size()+1);
waiter.setFrontNum(waiterList.size());
waiterList.offer(waiter);
if(waiterList.size()<=20){
txt.setText("(zhn)现在排?/span>"+waiter.getNum()+"位置上\n(zhn)前面有"+waiter.getFrontNum()+"个hQ请耐心{待Q!");
}else{
txt.setText("(zhn)前面已l排20多hQ请考虑Q\n"+"(zhn)现在排?/span>"+waiter.getNum()+"位置上,\n(zhn)前面有"+waiter.getFrontNum()+"个hQ请耐心{待Q!");
}
}
});
button.setBounds(75, 250, 150, 50); // 讄按钮位置
button.setFont(new Font(display,"宋体",12,SWT.BOLD));
button.setText("个h业务");// 讄按钮上的文字
// ------------------------------------------------------------------------
final Text goldTxt = new Text(shell,SWT.NULL);
goldTxt.setBounds(300,50,200,150);
// 事g代码里要讉KbuttonQ所以要dfinal
final Button goldButton = new Button(shell,SWT.Activate);
goldButton.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
Waiter w = new Waiter();
w.setFlag(1);
waiterList.addFirst(w);
goldTxt.setText("金卡用户Q下一位就是?zhn)Q?/span>");
}
});
goldButton.setBounds(325, 250, 150, 50); // 讄按钮位置
goldButton.setFont(new Font(display,"宋体",12,SWT.BOLD));
goldButton.setText("金卡通道");// 讄按钮上的文字
// ------------------END---------------------------------------------
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
看一下运行结果:


]]>- 一个简单的医院自助挂号pȝhttp://m.tkk7.com/min-water/articles/336700.htmlMineralwasserMineralwasserMon, 01 Nov 2010 08:33:00 GMThttp://m.tkk7.com/min-water/articles/336700.htmlhttp://m.tkk7.com/min-water/comments/336700.htmlhttp://m.tkk7.com/min-water/articles/336700.html#Feedback3http://m.tkk7.com/min-water/comments/commentRss/336700.htmlhttp://m.tkk7.com/min-water/services/trackbacks/336700.html先说一下在医院挂号的情况:(zhn)者到医院后要先交钱挂P然后在等候大厅等待叫P叫到你,你才能去看病。怎么挂号呢?医院有好多坐诊的ȝ或者专Ӟ挂号的时候?zhn)者可以选择让哪个医生或者专家ؓ自己看病Q选好以后Q等着你选的ȝ或者专家叫你就好了。这个挂Ll怎么做的呢,我们写一个JAVAE序模拟一下?/p>
首先Q这个系l会有?zhn)者类PatientQ医生类DoctorQ还有服务器cServerQ当然还有用L面UI?/p>
Patient
病hc,要有名字、号码,q要有挂Lȝ的标记号Q这些都要作为病人的属性,然后实现set、getҎ(gu)?/p>

Patient
package hospital;
public class Patient {
private String name;
private int flag;
private int num;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getFlag() {
return flag;
}
public void setFlag(int flag) {
this.flag = flag;
}
public void setNum(int num) {
this.num = num;
}
public int getNum() {
return num;
}
}
Doctor
ȝc,要有姓名和编P~号用来供给病h来挂自己的号Q姓名就不用再说了。然后给q些属性实现set、getҎ(gu)?/p>

Doctor
package hospital;
public class Doctor {
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
QueueServer
挂号排队pȝ的服务器Q由q个服务器来实现对病人、医生的兌Q实现病人挂号和ȝ叫号的功能?/p>
具体Ҏ(gu)为:为每个医生创Z个?zhn)者队列,装蝲对应的挂h者。这些队列listQ要先进先出即firstinQfirstoutQ所以要用Queue。然后把q些队列初始化,׃是模拟的E序Q所以初始化时先分别加入几个病h?/p>

QueueServer
package hospital;
import java.util.LinkedList;
import java.util.Queue;
public class QueueServer {
Queue<Patient> patientList1 = new LinkedList<Patient>();
Queue<Patient> patientList2 = new LinkedList<Patient>();
Queue<Patient> patientList3 = new LinkedList<Patient>();
public Queue<Patient> init1(){
for(int i=1;i<=10;i++){
Patient p = new Patient();
p.setNum(i);
patientList1.offer(p);
}
return patientList1;
}
public Queue<Patient> init2(){
for(int i=1;i<=15;i++){
Patient p = new Patient();
p.setNum(i);
patientList2.offer(p);
}
return patientList2;
}
public Queue<Patient> init3(){
for(int i=1;i<=20;i++){
Patient p = new Patient();
p.setNum(i);
patientList3.offer(p);
}
return patientList3;
}
}
PatientUI
q是病h挂号pȝ的病人客L。要有一个TextQ几个ButtonQ对应相应的ȝQ,当然要有一个容器装载这些东ѝ?/p>
当?zhn)者点d生按钮挂号后Q?zhn)者会加入到医生对应的(zhn)者队列,Text内会昄所选择的医生或者专家、自qL和所排在位置Q如果前面排队的人太多还会有小的温馨提C呵Q?/p>

PatientUI
package hospital;
import java.util.Queue;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class PatientUI {
public static void main(String[] args){
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setBounds(100, 100, 620, 450);
// shell.setMaximized(true);
shell.setText("医院专家挂号pȝ");
// 界面核心代码
QueueServer qs1 = new QueueServer();
final Queue<Patient> patientList1 = qs1.init1();
final Text txt = new Text(shell,SWT.MULTI);
txt.setFont(new Font(display,"宋体",20,SWT.BOLD));
txt.setBounds(100,50,400,200);
// 事g代码里要讉KbuttonQ所以要dfinal
final Button button = new Button(shell,SWT.Activate);
button.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
Patient patient = new Patient();
patient.setNum(patientList1.size()+1);
patientList1.offer(patient);
if(patientList1.size()<=20){
txt.setText("\n(zhn)选择? 张医生\n\n(zhn)现在排?/span>"+patient.getNum()+"号位|上");
}else{
txt.setText("\n(zhn)选择? 张医生\n\n(zhn)现在排?/span>"+patient.getNum()+"号位|上\n\n前面已经?0多hQ请考虑Q?/span>");
}
}
});
button.setBounds(50, 300, 150, 55); // 讄按钮位置
button.setFont(new Font(display,"宋体",12,SWT.BOLD));
button.setText("专家 张医?/span>");// 讄按钮上的文字
// -----------------2号专家||||--------------------------------------------
QueueServer qs2 = new QueueServer();
final Queue<Patient> patientList2 = qs2.init2();
final Button button2 = new Button(shell,SWT.Activate);
button2.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
Patient patient = new Patient();
patient.setNum(patientList2.size()+1);
patientList2.offer(patient);
if(patientList2.size()<=20){
txt.setText("\n(zhn)选择? 王医生\n\n(zhn)现在排?/span>"+patient.getNum()+"号位|上");
}else{
txt.setText("\n(zhn)选择? 王医生\n\n(zhn)现在排?/span>"+patient.getNum()+"号位|上\n\n前面已经?0多hQ请考虑Q?/span>");
}
}
});
button2.setBounds(225, 300, 150, 55); // 讄按钮位置
button2.setFont(new Font(display,"宋体",12,SWT.BOLD));
button2.setText("专家 王医?/span>");// 讄按钮上的文字
// --------------------3号专家||||------------------------------------
QueueServer qs3 = new QueueServer();
final Queue<Patient> patientList3 = qs3.init3();
final Button button3 = new Button(shell,SWT.Activate);
button3.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
Patient patient = new Patient();
patient.setNum(patientList3.size()+1);
patientList3.offer(patient);
if(patientList3.size()<=20){
txt.setText("\n(zhn)选择? 李医生\n(zhn)现在排?/span>"+patient.getNum()+"号位|上");
}else{
txt.setText("\n(zhn)选择? 李医生\n\n(zhn)现在排?/span>"+patient.getNum()+"号位|上\n\n前面已经?0多hQ请考虑Q?/span>");
}
}
});
button3.setBounds(400, 300, 150, 55); // 讄按钮位置
button3.setFont(new Font(display,"宋体",12,SWT.BOLD));
button3.setText("专家 李医?/span>");// 讄按钮上的文字
// -----------------------END---------------------------------------
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
DoctorUI
q是ȝ的客LQ同栯有一个容器装载一个Text和一个Button。点击ButtonQ下一?.Q,׃在他的病人队列里取出排在最前面的那个?zhn)者,在Text内显C位前来就诊的(zhn)者的信息Q如果所有病人都看完了,׃昄没有病h了)?/p>
Q这只是一个医生的客户端,其他ȝ的客L的编写方法与之相同,q里׃一一写出来了..Q?/p>

DoctorUI
package hospital;
import java.util.Queue;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class DoctorUI {
public static void main(String[] args) {
// TODO Auto-generated method stub
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setBounds(200, 100, 420, 350);
shell.setText("医院专家挂号pȝ--张医生客L");
// 界面核心代码
QueueServer qs1 = new QueueServer();
final Queue<Patient> patientListz = qs1.init1();
final Text txt = new Text(shell,SWT.MULTI);
txt.setFont(new Font(display,"微Y雅黑",13,SWT.BOLD));
txt.setBounds(50,50,300,100);
// 事g代码里要讉KbuttonQ所以要dfinal
final Button button = new Button(shell,SWT.Activate);
button.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
Patient p = patientListz.poll();
if(p!=null){
txt.setText("\n\t\tW? "+p.getNum()+" L?/span>" +
"\n\t 请到张医生医务室医");
}
else{
txt.setText("\n\t现在没有病h看病?/span>");
}
}
});
button.setBounds(100, 200, 200, 75); // 讄按钮位置
button.setFont(new Font(display,"微Y雅黑",14,SWT.BOLD));
button.setText("下一?.");// 讄按钮上的文字
// ---------------------END----------------------------
shell.layout();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
PatientUI
病h客户端的q行效果Q?/p>
DoctorUI
ȝ客户端的q行效果Q?/p>


]]> - 选课http://m.tkk7.com/min-water/articles/336539.htmlMineralwasserMineralwasserFri, 29 Oct 2010 16:40:00 GMThttp://m.tkk7.com/min-water/articles/336539.htmlhttp://m.tkk7.com/min-water/comments/336539.htmlhttp://m.tkk7.com/min-water/articles/336539.html#Feedback0http://m.tkk7.com/min-water/comments/commentRss/336539.htmlhttp://m.tkk7.com/min-water/services/trackbacks/336539.html选课pȝ很有意思,学生选择一门课E以后,q门评׃d到这个学生的选课列表里面Q同时这名学生也dC选择q门评的学生列表里面,也就是学生和评是双向选择的?/p>
创徏评cCourseQ设|三个属性分别ؓ名称、学分、学生名单?/p>

Course
import java.util.ArrayList;
import java.util.List;
public class Course {
private String name;
private float grade;
private List<Student> allStudents;
public Course(String name,float grade){
this.setAllStudents(new ArrayList<Student>());
this.setGrade(grade);
this.setName(name);
}
public void addStu(Student student){
this.allStudents.add(student);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getGrade() {
return grade;
}
public void setGrade(float grade) {
this.grade = grade;
}
public List<Student> getAllStudents() {
return allStudents;
}
public void setAllStudents(List<Student> allStudents) {
this.allStudents = allStudents;
}
}
创徏学生cStudentQ设|三个属性姓名、年龄、选课列表?/div>

Student
import java.util.ArrayList;
import java.util.List;
public class Student {
private String name;
private int age;
private List<Course> allCourse;//一个学生可以选多门课
public Student(String name,int age){
this.setAge(age);
this.setAllCourse(new ArrayList<Course>());
this.setName(name);
}
public void addCourse(Course course){
this.allCourse.add(course);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public List<Course> getAllCourse() {
return allCourse;
}
public void setAllCourse(List<Course> allCourse) {
this.allCourse = allCourse;
}
}
创徏试cTestCourseQ在里面创徏五个学生三门评Qƈ对他们互盔R择Qƈ把每个学生选得评d到各自的选课列表Q把选择每门评的学生添加到各科的学生列表,然后q行遍历Q学生的评列表和课E的学生列表?/p>

TestCourse
import java.util.Iterator;
public class TestCourse {
public static void main(String[] args) {
Student stu1 = new Student("张三",20);
Student stu2 = new Student("李四",21);
Student stu3 = new Student("王五",22);
Student stu4 = new Student("赉|",23);
Student stu5 = new Student("孙琦",24);
Course c1 = new Course("Java se 基础",2.0f);
Course c2 = new Course("Java se web",3.0f);
Course c3 = new Course("分布式开?/span>",5.0f);
// 讄关系
stu1.addCourse(c1);
c1.addStu(stu1);
stu1.addCourse(c2);
c2.addStu(stu1);
stu2.addCourse(c2);
c2.addStu(stu2);
stu3.addCourse(c1);
c1.addStu(stu3);
stu3.addCourse(c2);
c2.addStu(stu3);
stu3.addCourse(c3);
c3.addStu(stu3);
stu4.addCourse(c3);
c3.addStu(stu4);
stu5.addCourse(c3);
c3.addStu(stu5);
System.out.println("学生姓名Q?/span>"+stu1.getName());
Iterator<Course> it1 = stu1.getAllCourse().iterator();
while(it1.hasNext()){
Course c = it1.next();
System.out.println("\t|-评名称Q?/span>"+c.getName()+",学分Q?/span>"+c.getGrade());
}
System.out.println("评名称Q?/span>"+c3.getName());
Iterator<Student> it2 = c3.getAllStudents().iterator();
while(it2.hasNext()){
Student s = it2.next();
System.out.println("\t|-学生姓名Q?/span>"+s.getName()+",q龄Q?/span>"+s.getAge());
}
}
}
l果昄Q只打印stu1和c1的列表)


]]>
- 消息队列http://m.tkk7.com/min-water/articles/336537.htmlMineralwasserMineralwasserFri, 29 Oct 2010 16:23:00 GMThttp://m.tkk7.com/min-water/articles/336537.htmlhttp://m.tkk7.com/min-water/comments/336537.htmlhttp://m.tkk7.com/min-water/articles/336537.html#Feedback0http://m.tkk7.com/min-water/comments/commentRss/336537.htmlhttp://m.tkk7.com/min-water/services/trackbacks/336537.html先创Z个messagec,属性ؓ发送方、接收方、内宏V?/p>

Message
public class Message {
private String from;
private String to;
private String content;
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getTo() {
return to;
}
public void setTo(String to) {
this.to = to;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
创徏QQInterface接口Q内部创建发送和接收消息的方法?/p>

QQInterface
public interface QQInterface {
void sendMsg(Message msg);
Message receiveMsg(String name);
}
创徏QQServer服务器,作ؓ消息的{q站?/p>

QQServer
import java.util.HashMap;
import java.util.Map;
public class QQServer {
static Map<String,Message> serverMap = new HashMap<String,Message>();
public static void serverReceiveMsg(Message msg){
serverMap.put(msg.getTo(),msg);
System.out.println(msg.getFrom()+" "+" "+msg.getContent());
}
public static Message asked(String name){
Message msg = serverMap.get(name);
return msg;
}
}
QQ1Q实现QQInterface接口及方法,作ؓ发送方?/p>

QQ1
public class QQ1 implements QQInterface{
public static void main(String[] args){
Message msg = new Message();
msg.setFrom("QQ1");
msg.setTo("QQ2");
msg.setContent("I am QQ1 ?/span>");
QQ1 q = new QQ1();
q.sendMsg(msg);
}
public void sendMsg(Message msg){
QQServer.serverReceiveMsg(msg);
}
@Override
public Message receiveMsg(String name) {
Message msg = QQServer.asked(name);
System.out.println("******"+msg.getContent());
return msg;
}
}
QQ2Q实现QQInterface接口及方法,作ؓ接收斏V?/p>

QQ2
public class QQ2 implements QQInterface{
public static void main(String[] args){
Message msg = new Message();
msg.setFrom("QQ2");
msg.setTo("QQ1");
msg.setContent("I am QQ2 ?/span>");
QQ2 q = new QQ2();
q.sendMsg(msg);
}
public void sendMsg(Message msg){
QQServer.serverReceiveMsg(msg);
}
@Override
public Message receiveMsg(String name) {
Message msg = QQServer.asked(name);
System.out.println("******"+msg.getContent());
return msg;
}
}
创徏Test试c?/p>

Test
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Test {
public static void main(String[] args){
Map<String,List<Message>> QQMap = new HashMap<String,List<Message>>();
List<Message> msgList = new ArrayList<Message>();
// W一ơ发送消?/span>
Message msg1 = new Message();
msg1.setFrom("QQ1");
msg1.setTo("QQ2");
msg1.setContent("HI!");
msgList.add(msg1);
QQMap.put(msg1.getTo(), msgList);
// W二ơ发送消?/span>
Message msg2 = new Message();
msg2.setFrom("QQ1");
msg2.setTo("QQ2");
msg2.setContent("Hello World !");
msgList.add(msg2);
QQMap.put(msg2.getTo(), msgList);
List<Message> qq2MsgList = QQMap.get("QQ2");
for(Message m:qq2MsgList){//打印QQ1发给QQ2消息
System.out.println(m.getContent());
}
}
}
l果昄


]]>
վ֩ģ壺
ƷƵ߹ۿ㶮|
1000žžδʮ|
㽶Ƶ
|
Ʒ벻|
߹ۿ|
ۺɫ¶|
һɫëƬ|
Ļ|
þóѲ|
аӰԺ߹ۿ|
114ëƬѹۿ|
һ|
ˬִ̼APP|
|
Ůڵվ|
ۺ|
Ʒһ|
òѸ|
þ˽˹ƷvA|
һƵ|
AVһ
|
97Ƶ|
ƷƵ|
žžžƷƵ|
ۺ͵Ļ|
˳WWW|
պ尡Ƶ߹ۿ
|
ɫվ|
Ʒ߹ۿ|
ҳ߹ۿ|
պ˳վ|
ŷ͵Ʒ |
ѸӰ߹ۿ|
Aɻ߹ۿ
|
͵|
avƬһ
|
С˵רɫУ|
þƷĻ|
߳Ƶ|
һĻ|
רĻ|